Setting the file. One moment. Migration Completion · Wix Replatform · wix/skills · Skills Docs(opens in a new tab)
scripts/migration-completion.js
JavaScript·76 lines·4 KB
11
}
=
require
(
'../lib/migration-completion.js'
);
12const { validateEntityQaAttestation } = require('../lib/entity-qa-attestation.js');
13const { loadArtifacts, writeJsonAtomic } = require('../lib/orchestration-state.js');
14const { getEffectiveDeliveryMode } = require('../lib/orchestration-decisions.js');
15
16async function main() {
17 const projectDirArg = process.argv[2];
18 if (!projectDirArg) throw new Error('Usage: node scripts/migration-completion.js <projectDir>');
19 const projectDir = path.resolve(projectDirArg);
20 const artifacts = await loadArtifacts(projectDir);
21 const deliveryMode = getEffectiveDeliveryMode(artifacts.decisions || {});
22 const inputs = await loadMigrationCompletionInputs(projectDir);
23 // Surface the completion-artifact refusals as typed reasons the caller can route on, rather than as a
24 // bare stack trace. The run is not finished until all four artifacts exist; saying which one
25 // is missing is the difference between a fixable stop and a mystery.
26 const artifactCheck = validateCompletionArtifacts(inputs);
27 if (!artifactCheck.ok) {
28 console.error(JSON.stringify({ ok: false, reason: artifactCheck.reason, projectDir }, null, 2));
29 process.exit(1);
30 }
31 // Same treatment for a missing, stale or failed entity-QA attestation -- a typed
32 // refusal carrying `entityQa` (the same object the router's refusal carries), not a bare
33 // "migration cannot complete" thrown out of createMigrationCompletion.
34 const entityQa = validateEntityQaAttestation({
35 attestation: inputs.entityQaAttestation,
36 report: inputs.backendCompletion,
37 reportDigest: inputs.reportDigest,
38 mappedEntities: inputs.mappedEntities,
39 });
40 if (!entityQa.ok) {
41 console.error(JSON.stringify({
42 ok: false,
43 reason: entityQa.reasons[0],
44 entityQa: { qaStatus: entityQa.qaStatus, entities: entityQa.entities, recheck: entityQa.recheck },
45 projectDir,
46 }, null, 2));
47 // The CLI refusal prints the Import Operator prompt with the project path
48 // and affected entities filled in. A missing or stale attestation (recheck: 'full') has no
49 // per-entity list yet -- the whole mapped-entity set needs a fresh pass.
50 const entityList = entityQa.entities.length
51 ? entityQa.entities.map((entry) => `${entry.entity}/${entry.subtype}`).join(', ')
52 : '(all mapped entities -- the attestation is missing or stale)';
53 console.error(
54 `\nImport Operator action required: in project \`${projectDir}\`, run the entity-by-entity QA pass `
55 + 'from `rp-execute-import` against the current completion report, fix the listed entities '
56 + 'through a fresh Developer dispatch, then run `scripts/entity-qa-attestation.js` and re-route.\n'
57 + `qaStatus: ${entityQa.qaStatus}\n`
58 + `Entities to recheck: ${entityList}`,
59 );
60 process.exit(1);
61 }
62 const completion = createMigrationCompletion({ deliveryMode, ...inputs });
63 const outputPath = path.join(projectDir, COMPLETION_FILE);
64 if (inputs.completion?.schemaVersion === 1) {
65 const archive = path.join(projectDir, 'completion/migration-completion.v1.json');
66 // Preserve the original receipt once; never overwrite its historical bytes.
67 await fs.copyFile(outputPath, archive, require('node:fs').constants.COPYFILE_EXCL).catch(error => { if (error.code !== 'EEXIST') throw error; });
68 }
69 await writeJsonAtomic(outputPath, completion);
70 console.log(JSON.stringify({ ok: true, outputPath, completion }, null, 2));
71}
72
73main().catch((error) => {
74 console.error(JSON.stringify({ ok: false, reason: error.code || error.message, staleInputs: error.staleInputs }));
75 process.exit(1);
76});