import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import {shortLinkFunction, deployAccountShortLinks} from '../../scripts/deploy-account-short-links.mjs'; const prior = fs.readFileSync(new URL('../../deploy/account-binding-short-links-20261112/previous-account-binding.mjs', import.meta.url), 'utf8') .replaceAll('\r\n', '\n').replace(/^import .*;\n/gm, '').replace(/^export /gm, '').trim(); test('短链接部署精确替换账号模块,保留外围生产代码', () => { const prefix = 'const untouchedBefore = "before";\n', suffix = '\nconst untouchedAfter = "after";'; const patched = shortLinkFunction(prefix + prior + suffix); assert.ok(patched.startsWith(prefix)); assert.ok(patched.endsWith(suffix)); assert.ok(patched.includes('confirmationTicket(p.ticket)')); assert.ok(patched.includes("reference = 'ksfl_'")); assert.throws(() => shortLinkFunction(prior + '\n' + prior), /MODULE_MISMATCH/); }); test('线上账号函数存在未知改动时,任何远程写入前停止', async () => { const calls = []; const request = async (method, route) => { calls.push({method, route}); return {objectId: 'bTjPEnHYWF', name: 'ksfWorkshopAccount', path: '/ksfWorkshopAccount', code: prior}; }; await assert.rejects(() => deployAccountShortLinks({request, apply: true}), /UNKNOWN_SHORT_LINK_FUNCTION_VERSION/); assert.deepEqual(calls.map(call => call.method), ['GET']); });