admin-read-release.test.mjs 1.1 KB

1234567891011
  1. import {test} from 'node:test';
  2. import assert from 'node:assert/strict';
  3. import {readFileSync} from 'node:fs';
  4. import {patchAdminReadHelpers,optimizedReadHelpers} from '../admin-read-performance-patch.mjs';
  5. 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');
  6. 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;};
  7. test('narrow release preserves newer unrelated gateway handlers and authentication',()=>{
  8. const live=source+'\nfunction newerProductionFix(){return "preserve this";}';
  9. const patched=patchAdminReadHelpers(live);assert.equal(strip(patched),strip(live));assert.equal(patchAdminReadHelpers(patched),patched);
  10. assert.throws(()=>patchAdminReadHelpers(live.replace('async function queryUsers(','async function removedUsers(')),/Missing read helper/);
  11. });