read-pressure-release.test.mjs 1.8 KB

123456789101112
  1. import {test} from 'node:test';import assert from 'node:assert/strict';import {readFileSync,existsSync} from 'node:fs';
  2. const file=new URL('../read-pressure-release.mjs',import.meta.url);
  3. test('release patch preserves unrelated production functions and upgrades only owned read paths',async()=>{
  4. assert.ok(existsSync(file),'surgical release builder exists');const {patchReadPressureGateway}=await import(file);
  5. const before=`const STORE_OPERATIONS=new Set(['ops/lessons/list']);function untouched(){return 'production-hotfix';}\nasync function operationsScopeVersion(scope,companyId){return 'legacy-custom';}\nasync function handler(request,response){const operation='';if(operation==='ops/lessons/list')return response.json({success:true});}`;
  6. const after=patchReadPressureGateway(before,'ops');assert.ok(after.includes("function untouched(){return 'production-hotfix';}"));assert.ok(after.includes("return 'legacy-custom'"));assert.ok(after.includes('ops/lessons/export/create'));assert.ok(after.includes('dispatchReadPressure'));new Function(after);
  7. });
  8. test('late hotfixes after the runtime marker and unrelated lesson transfer writes survive',async()=>{
  9. const {patchReadPressureGateway}=await import(file);const {withXiaoshuRuntime}=await import('../lib/xiaoshu-runtime-compat.mjs');
  10. const source=withXiaoshuRuntime(`const STORE_OPERATIONS=new Set(['ops/lessons/list']);async function lessonTransferCommit(){return 'write-hotfix';}async function handler(request,response){const operation='';if(operation==='ops/lessons/list')return response.json({success:true});}`)+"\nfunction memberCreditStatus(){return 'late-critical-hotfix';}";
  11. const patched=patchReadPressureGateway(source,'ops');assert.ok(patched.includes("function memberCreditStatus(){return 'late-critical-hotfix';}"));assert.ok(patched.includes("async function lessonTransferCommit(){return 'write-hotfix';}"));
  12. });