import {test} from 'node:test'; import assert from 'node:assert/strict'; import {patchSupportRequests} from '../deploy-support-requests.mjs'; 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}"; test('scoped patch preserves every byte of the baseline outside the new dispatch/helper',()=>{ const after=patchSupportRequests(before); assert.ok(after.includes('// online-only fix must remain')); assert.ok(after.includes("if(operation==='ops/existing') return existing();")); 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); assert.equal(patchSupportRequests(after),after); }); test('refuses missing or ambiguous anchors and conflicting existing implementations',()=>{ assert.throws(()=>patchSupportRequests('async function handler(){}'),/不一致/); assert.throws(()=>patchSupportRequests(before+before),/不一致/); assert.throws(()=>patchSupportRequests(before+'\n// ops/support-requests/list'),/不同版本/); }); import {patchWorkflow} from '../deploy-support-workflow.mjs'; import {readFileSync} from 'node:fs'; test('app patch preserves online changes, is idempotent and refuses competing implementation',()=>{ const before="// production fix\nasync function handler(){\n if (action === 'migration_status') return {implemented: ['existing']};\n if (action === 'guestbook_add') return save();\n}"; 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); assert.throws(()=>patchWorkflow(before+before,'app'),/不唯一/); assert.throws(()=>patchWorkflow(before+'async function appSupportRequests(){}','app'),/不同版本/); }); test('admin patch fails closed for unknown baseline, complete candidate is idempotent',()=>{ assert.throws(()=>patchWorkflow(before,'admin'),/未找到/); assert.throws(()=>patchWorkflow(before+'\n// Both mobile roles submit category 22\nasync function supportRequestsPage(){\n}', 'admin'),/已变化/); 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'); assert.equal(patchWorkflow(candidate,'admin'),candidate); });