support-requests-release.test.mjs 2.7 KB

12345678910111213141516171819202122232425262728293031
  1. import {test} from 'node:test';
  2. import assert from 'node:assert/strict';
  3. import {patchSupportRequests} from '../deploy-support-requests.mjs';
  4. const before="// online-only fix must remain\nasync function handler(){\n if(operation==='ops/live/versions') return live();\n if(operation==='ops/existing') return existing();\n}";
  5. test('scoped patch preserves every byte of the baseline outside the new dispatch/helper',()=>{
  6. const after=patchSupportRequests(before);
  7. assert.ok(after.includes('// online-only fix must remain'));
  8. assert.ok(after.includes("if(operation==='ops/existing') return existing();"));
  9. assert.equal(after.replace(" if(operation==='ops/support-requests/list') return response.json({success:true,data:await supportRequestsPage(context,input)});\n",'').split('\n// Both mobile roles')[0],before);
  10. assert.equal(patchSupportRequests(after),after);
  11. });
  12. test('refuses missing or ambiguous anchors and conflicting existing implementations',()=>{
  13. assert.throws(()=>patchSupportRequests('async function handler(){}'),/不一致/);
  14. assert.throws(()=>patchSupportRequests(before+before),/不一致/);
  15. assert.throws(()=>patchSupportRequests(before+'\n// ops/support-requests/list'),/不同版本/);
  16. });
  17. import {patchWorkflow} from '../deploy-support-workflow.mjs';
  18. import {readFileSync} from 'node:fs';
  19. test('app patch preserves online changes, is idempotent and refuses competing implementation',()=>{
  20. const before="// production fix\nasync function handler(){\n if (action === 'migration_status') return {implemented: ['existing']};\n if (action === 'guestbook_add') return save();\n}";
  21. const after=patchWorkflow(before,'app');assert.ok(after.includes('// production fix'));assert.ok(after.includes("implemented: ['app_support_requests_list','app_support_request_read','existing']"));assert.ok(after.includes("if (action === 'guestbook_add') return save();"));assert.equal(patchWorkflow(after,'app'),after);
  22. assert.throws(()=>patchWorkflow(before+before,'app'),/不唯一/);
  23. assert.throws(()=>patchWorkflow(before+'async function appSupportRequests(){}','app'),/不同版本/);
  24. });
  25. test('admin patch fails closed for unknown baseline, complete candidate is idempotent',()=>{
  26. assert.throws(()=>patchWorkflow(before,'admin'),/未找到/);
  27. assert.throws(()=>patchWorkflow(before+'\n// Both mobile roles submit category 22\nasync function supportRequestsPage(){\n}', 'admin'),/已变化/);
  28. const candidate=before+"\n if(operation==='ops/support-requests/process') return response.json({success:true,data:await supportRequestProcess(context,input)});\n"+readFileSync(new URL('../cloud/support-requests.js',import.meta.url),'utf8');
  29. assert.equal(patchWorkflow(candidate,'admin'),candidate);
  30. });