| 123456789101112131415161718192021222324252627282930 |
- /** Read-only byte audit of the tagged single-function candidate; no remote requests. */
- import fs from 'node:fs';
- import assert from 'node:assert/strict';
- import { createHash } from 'node:crypto';
- import { BEGIN, END } from './onboarding-cloud-patch.mjs';
- const tag = process.argv.find(x => x.startsWith('--tag='))?.slice(6);
- assert.match(tag || '', /^[A-Za-z0-9-]+$/);
- const suffix = '-' + tag;
- const out = 'test-results/new-account-20261128';
- const privateDir = '.local-backup/new-account-20261128';
- const old = JSON.parse(fs.readFileSync(privateDir + '/provision-cloud-preview-before' + suffix + '.json')).code;
- const candidate = fs.readFileSync(privateDir + '/provision-cloud-candidate' + suffix + '.js', 'utf8');
- const preview = JSON.parse(fs.readFileSync(out + '/cloud-prompt-preview' + suffix + '.json'));
- const hash = value => createHash('sha256').update(value).digest('hex');
- assert.equal(hash(old), preview.oldSha256); assert.equal(hash(candidate), preview.newSha256);
- const newline = old.includes('\r\n') ? '\r\n' : '\n';
- const start = old.indexOf(' var mxPass = derivedPass ||');
- const terminator = "].join('\\n');";
- const end = old.indexOf(terminator, start);
- assert.ok(start >= 0 && end > start);
- const oldSpan = old.slice(start, end + terminator.length);
- const call = ' var instruction = _buildSelfHostedInstruction(oa.id, containerName, prov0, derivedPass, token0, ownerMx, CONTAINER_ONBOARDING_BUNDLE);';
- let restored = candidate.slice(0, candidate.indexOf(BEGIN)) + candidate.slice(candidate.indexOf(END) + END.length + 2 * newline.length);
- restored = restored.replace(call, oldSpan).replace(' onboardingBundle: CONTAINER_ONBOARDING_BUNDLE,' + newline, '');
- assert.equal(restored, old, '允许的提示词区域之外存在变更');
- const result = { target: preview.target, outsideOwnedByteIdentical: true, oldSha256: hash(old), newSha256: hash(candidate),
- allowedRegions: ['owned onboarding helper and bundle metadata', 'trial instruction expression', 'additive onboardingBundle response field'] };
- fs.writeFileSync(out + '/cloud-prompt-byte-preservation' + suffix + '.json', JSON.stringify(result, null, 2), { flag: 'wx' });
- console.log(JSON.stringify(result));
|