import {test} from 'node:test'; import assert from 'node:assert/strict'; import {readFileSync} from 'node:fs'; import {patchAdminReadHelpers,optimizedReadHelpers} from '../admin-read-performance-patch.mjs'; const source=readFileSync(new URL('../deploy-admin-functions.mjs',import.meta.url),'utf8').match(/const operationsGatewayCode = String.raw`([\s\S]*?)\n`;/)[1]+'\n'+readFileSync(new URL('../cloud/payroll-integrity.js',import.meta.url),'utf8'); const strip=code=>{for(const name of optimizedReadHelpers)code=code.replace(new RegExp('async function '+name+'\\([^]*?(?=\\n(?:async )?function |\\nconst [A-Z_])','g'),'READ_HELPER_'+name);return code;}; test('narrow release preserves newer unrelated gateway handlers and authentication',()=>{ const live=source+'\nfunction newerProductionFix(){return "preserve this";}'; const patched=patchAdminReadHelpers(live);assert.equal(strip(patched),strip(live));assert.equal(patchAdminReadHelpers(patched),patched); assert.throws(()=>patchAdminReadHelpers(live.replace('async function queryUsers(','async function removedUsers(')),/Missing read helper/); });