import assert from "node:assert/strict"; import crypto from "node:crypto"; import fs from "node:fs"; import path from "node:path"; import { execFileSync } from "node:child_process"; import { fileURLToPath } from "node:url"; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); const write = process.argv.includes("--write"); const absolute = (file) => path.join(root, file); const read = (file) => fs.readFileSync(absolute(file), "utf8"); const readJson = (file) => JSON.parse(read(file)); const sha256 = (file) => crypto.createHash("sha256").update(fs.readFileSync(absolute(file))).digest("hex"); const outputRoot = "tests/golden/WBV2-P9-001"; const chromiumPath = `${outputRoot}/chromium-mesh-production.json`; const chromiumSecondPath = `${outputRoot}/chromium-mesh-production.second.json`; const reportPath = `${outputRoot}/mesh-receipt-report.json`; const statusPath = "docs/status/WBV2-P9-001.md"; const planPath = `${outputRoot}/feature-parity-task-plan.json`; const manifestPath = `${outputRoot}/manifest.json`; const parentManifestPath = "tests/golden/WBV2-P9-000/manifest.json"; const sourceManifestPath = "tests/golden/WBV2-P2-003/manifest.json"; const sourceReportPath = "tests/golden/WBV2-P2-003/mesh-edit-report.json"; const parent = readJson(parentManifestPath); assert.equal(parent.task, "WBV2-P9-000"); assert.equal(parent.status, "done"); assert.equal(parent.nextTask, "WBV2-P9-001"); for (const artifact of Object.values(parent.artifacts ?? {})) assert.equal(sha256(artifact.path), artifact.sha256, artifact.path); const sourceManifest = readJson(sourceManifestPath); const sourceReport = readJson(sourceReportPath); assert.equal(sourceManifest.task, "WBV2-P2-003"); assert.equal(sourceManifest.status, "done"); assert.equal(sourceReport.task, "WBV2-P2-003"); assert.equal(sourceReport.desktop.status, "EXACT"); assert.equal(sourceReport.wasm.status, "EXACT"); assert.equal(sourceReport.desktop.saveReopen, "EXACT"); assert.equal(sourceReport.saveReopen, "EXACT"); const sourceBound = Object.values(sourceManifest.artifacts ?? {}).find((artifact) => artifact.path === sourceReportPath); assert.ok(sourceBound, "P2-003 source report is not manifest-bound"); assert.equal(sourceBound.sha256, sha256(sourceReportPath)); assert.equal(sha256(chromiumPath), sha256(chromiumSecondPath), "Chromium Mesh report is not deterministic"); const chromium = readJson(chromiumPath); assert.equal(chromium.task, "WBV2-P9-001"); assert.equal(chromium.operation, "MESH_PRODUCTION_CHROMIUM"); assert.equal(chromium.browser, "chromium"); assert.equal(chromium.queueMutation, false); assert.equal(chromium.positive.parity, true); for (const surface of ["desktop", "wasm"]) { const result = chromium.positive[surface]; assert.equal(result.status, "FINISHED"); assert.equal(result.code, "OK"); assert.equal(result.mainRevisionBefore, 9); assert.equal(result.mainRevisionAfter, 10); assert.equal(result.mainMutation, "CHANGED"); assert.deepEqual(result.delta, { vertexId: "vertex:0", before: { x: 1, y: 2, z: 3 }, after: { x: 1.5, y: 1, z: 5 } }); } assert.deepEqual(chromium.positive.desktop, chromium.positive.wasm); assert.equal(chromium.persistence.exact, true); assert.deepEqual(chromium.persistence.reopened, chromium.persistence.saved); assert.equal(chromium.negative.malformed.code, "COMMAND_MALFORMED"); assert.equal(chromium.negative.stale.code, "REVISION_CONFLICT"); assert.equal(chromium.negative.unknown.code, "COMMAND_UNSUPPORTED"); assert.equal(chromium.negative.rollbackMain.revision, 9); assert.equal(chromium.negative.rollbackMain.dirty, false); assert.deepEqual(chromium.negative.rollbackMain.value.vertices, [{ id: "vertex:0", x: 1, y: 2, z: 3 }, { id: "vertex:1", x: 0, y: 0, z: 0 }]); const receipt = { schemaVersion: 1, task: "WBV2-P9-001", operation: "MESH_PRODUCTION_CHROMIUM_RECEIPT", status: "PASS", browser: "chromium", queueMutation: false, source: { task: "WBV2-P2-003", manifest: sourceManifestPath, manifestSha256: sha256(sourceManifestPath), report: sourceReportPath, reportSha256: sha256(sourceReportPath), exactDesktop: sourceReport.desktop.status === "EXACT", exactWasm: sourceReport.wasm.status === "EXACT", exactSaveReopen: sourceReport.saveReopen === "EXACT", }, chromium: { report: chromiumPath, reportSha256: sha256(chromiumPath), secondReport: chromiumSecondPath, secondReportSha256: sha256(chromiumSecondPath), deterministic: true, surfaces: ["DESKTOP", "WASM"], positive: { desktop: chromium.positive.desktop, wasm: chromium.positive.wasm, parity: chromium.positive.parity }, negative: { malformed: chromium.negative.malformed, stale: chromium.negative.stale, unknown: chromium.negative.unknown }, persistence: { exact: chromium.persistence.exact, saved: chromium.persistence.saved, reopened: chromium.persistence.reopened }, }, assertions: { realMeshTranslateVertex: true, desktopWasmDeltaMatch: true, saveReopenExact: true, failureMatrixClosed: true, featureParityClaim: "CAP-MESH-POSITIVE-EDIT", historicalReproduction: false, }, nextTask: "WBV2-P9-002", }; if (!write) { process.stdout.write("wbv2-mesh-receipt-ok task=WBV2-P9-001 deterministic=true next=WBV2-P9-002\n"); process.exit(0); } fs.mkdirSync(absolute(outputRoot), { recursive: true }); fs.writeFileSync(absolute(reportPath), `${JSON.stringify(receipt, null, 2)}\n`); const status = `# WBV2-P9-001 status\n\n- task: \`WBV2-P9-001\`; parent: \`WBV2-P9-000\`; status: \`done\`\n- Mesh Chromium receipt: \`DESKTOP + WASM\`\n- delta: \`(0.5, -1, 2)\`; revision: \`9 -> 10\`\n- save/reopen: \`EXACT\`\n- nextTask: \`WBV2-P9-002\`\n\nThe production Chromium receipt executes the existing Mesh Main transaction on both browser surfaces. Malformed, stale-revision, and unknown-vertex commands are rejected without mutating the Main. This is a bounded current implementation claim and does not assert historical byte reproduction.\n`; fs.writeFileSync(absolute(statusPath), status); const previousPlan = readJson("tests/golden/WBV2-P9-000/feature-parity-task-plan.json"); const nextPlan = structuredClone(previousPlan); nextPlan.parentRecoveryPlan = { path: "tests/golden/WBV2-P9-000/feature-parity-task-plan.json", sha256: sha256("tests/golden/WBV2-P9-000/feature-parity-task-plan.json") }; nextPlan.tasks = nextPlan.tasks.map((task) => task.id === "WBV2-P9-001" ? { ...task, status: "done", ready: false } : task.id === "WBV2-P9-002" ? { ...task, status: "in_progress", ready: true } : { ...task, ready: false }); fs.writeFileSync(absolute(planPath), `${JSON.stringify(nextPlan, null, 2)}\n`); const nextCard = `# WBV2-P9-002: Modifier production Chromium receipt\n\n- task: WBV2-P9-002\n- parent: WBV2-P9-001\n- status: in_progress\n- gap: workflow:modifier_production_chromium_receipt\n- ownerFamily: MODIFIER\n- targetImplementationClass: LOCAL_EXACT\n\n## 目标\n\nBind the real Modifier Main transaction to a production Chromium desktop/WASM/save-reopen receipt using the existing source implementation.\n\n## 输入与范围\n\n- Existing Modifier protocol: \`web/protocol/corrective-modifier-command.ts\`\n- Existing exact pilot: \`tests/golden/corrective/C4-001/receipt-report.json\`\n- Chromium test: \`web/tests/e2e/wbv2-modifier-production.spec.ts\`\n\n## 验收\n\n- \`npm --prefix web run test:e2e -- --workers=1 tests/e2e/wbv2-modifier-production.spec.ts\`\n- \`node tools/web/generate-wbv2-modifier-receipt.mjs --write\`\n- \`node tools/web/check-task-context.mjs --task WBV2-P9-002 --write\`\n\nMalformed, stale-revision, unknown-modifier, non-Chromium, or non-exact save/reopen cases must keep in_progress and must not advance nextTask.\n\n## 交付与回滚\n\n- Reports: \`tests/golden/WBV2-P9-002/\`\n- Status: \`docs/status/WBV2-P9-002.md\`\n- Manifest: \`tests/golden/WBV2-P9-002/manifest.json\`\n- Rollback: restore P9-001 as queue parent without modifying Mesh or P8 evidence.\n`; fs.writeFileSync(absolute("docs/tasks/WBV2-P9-002.md"), nextCard); execFileSync(process.execPath, [absolute("tools/web/generate-v2-task-index.mjs"), "--plan-path", absolute(planPath)], { cwd: root, stdio: "inherit" }); execFileSync(process.execPath, [absolute("tools/web/check-task-context.mjs"), "--task", "WBV2-P9-001", "--write"], { cwd: root, stdio: "inherit" }); const artifactPaths = { parentManifest: parentManifestPath, sourceManifest: sourceManifestPath, sourceReport: sourceReportPath, chromiumReport: chromiumPath, chromiumSecondReport: chromiumSecondPath, e2e: "web/tests/e2e/wbv2-mesh-production.spec.ts", protocol: "web/protocol/corrective-mesh-command.ts", bridge: "web/app/src/corrective-pilot-bridge.ts", generator: "tools/web/generate-wbv2-mesh-receipt.mjs", report: reportPath, status: statusPath, featureParityPlan: planPath, taskContext: `${outputRoot}/task-context.json`, }; const artifacts = Object.fromEntries(Object.entries(artifactPaths).map(([name, file]) => [name, { path: file, sha256: sha256(file) }])); const manifest = { schemaVersion: 1, task: "WBV2-P9-001", parentTask: "WBV2-P9-000", operation: "MESH_PRODUCTION_CHROMIUM_RECEIPT", status: "done", enablingTask: false, parityStateChange: true, runtime: "PLAYWRIGHT_CHROMIUM_DESKTOP_AND_WASM", artifacts, assertions: { capabilityId: "CAP-MESH-POSITIVE-EDIT", browser: "chromium", surfaces: 2, deterministic: true, saveReopen: "EXACT", negativeCases: 3, historicalReproduction: false }, nextTask: "WBV2-P9-002", }; fs.writeFileSync(absolute(manifestPath), `${JSON.stringify(manifest, null, 2)}\n`); execFileSync(process.execPath, [absolute("tools/web/check-v2-task-index.mjs")], { cwd: root, stdio: "pipe" }); let queue = read("docs/EXECUTION_QUEUE.md"); queue = queue.replace(/\| 当前任务 \| `[^`]+` \|/u, "| 当前任务 | `WBV2-P9-002` |") .replace(/\| parent manifest \| `[^`]+` \|/u, "| parent manifest | `tests/golden/WBV2-P9-001/manifest.json` |") .replace(/\| 任务卡 \| \[[^\]]+\]\([^\)]+\) \|/u, "| 任务卡 | [`tasks/WBV2-P9-002.md`](tasks/WBV2-P9-002.md) |"); fs.writeFileSync(absolute("docs/EXECUTION_QUEUE.md"), queue); process.stdout.write(`wbv2-mesh-receipt-written task=WBV2-P9-001 surfaces=2 deterministic=true next=WBV2-P9-002 artifacts=${Object.keys(artifacts).length}\n`);