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-P11-004"; const reportPath = `${outputRoot}/engine-module-gate-report.json`; const statusPath = "docs/status/WBV2-P11-004.md"; const planPath = `${outputRoot}/module-expansion-task-plan.json`; const manifestPath = `${outputRoot}/manifest.json`; const parentPath = "tests/golden/WBV2-P11-003/manifest.json"; const approvalPath = "docs/status/M12-PROVENANCE-EPOCH-2-APPROVAL.json"; const inventoryPath = "tests/golden/WBV2-P0-002/parity-map.json"; const enginePath = "tests/golden/WBV2-P10-002/native-engine-receipt-report.json"; const matrixPath = "tests/golden/WBV2-P10-003/module-matrix-receipt-report.json"; const sources = [ { id: "CAP-MESH-TOPOLOGY-FAMILY", family: "MESH", manifest: "tests/golden/WBV2-P11-001/manifest.json", report: "tests/golden/WBV2-P11-001/mesh-topology-receipt-report.json", proof: "6 topology operations / 6 save-reopen exact" }, { id: "CAP-MODIFIER-PARAMETER-APPLY", family: "MODIFIER", manifest: "tests/golden/WBV2-P11-002/manifest.json", report: "tests/golden/WBV2-P11-002/modifier-parameter-receipt-report.json", proof: "DECIMATE collapse apply / exact save-reopen" }, { id: "CAP-ASSET-LINK-OVERRIDE-RELOAD", family: "ASSET_CATALOG", manifest: "tests/golden/WBV2-P11-003/manifest.json", report: "tests/golden/WBV2-P11-003/asset-link-override-receipt-report.json", proof: "ownership boundary / local append / exact save-reopen" }, ]; const parent = readJson(parentPath); assert.equal(parent.task, "WBV2-P11-003"); assert.equal(parent.status, "done"); assert.equal(parent.nextTask, "WBV2-P11-004"); for (const artifact of Object.values(parent.artifacts ?? {})) assert.equal(sha256(artifact.path), artifact.sha256, artifact.path); const approval = readJson(approvalPath); assert.equal(approval.epoch, 2); assert.equal(approval.approvedBy, "wangdequan"); assert.equal(approval.limitations.releaseLabel, "AUTHORIZED_REBASELINE_ONLY"); assert.equal(approval.limitations.fullHistoricalReproduction, false); const inventory = readJson(inventoryPath); assert.equal(inventory.summary.inventoryEntries, 6900); const engine = readJson(enginePath); const matrix = readJson(matrixPath); assert.equal(engine.status, "PASS"); assert.equal(engine.assertions.realEngineMainMutation, true); assert.equal(matrix.status, "PASS"); assert.equal(matrix.matrix.cases, 9); assert.equal(matrix.matrix.positive, 3); for (const source of sources) { const manifest = readJson(source.manifest); const report = readJson(source.report); assert.equal(manifest.status, "done", `${source.family} manifest is not done`); assert.equal(report.status, "PASS", `${source.family} receipt is not PASS`); assert.equal(report.browser, "chromium"); assert.equal(report.queueMutation, false); assert.equal(report.assertions.historicalReproduction, false); const bound = Object.values(manifest.artifacts ?? {}).find((artifact) => artifact.path === source.report); assert.ok(bound, `${source.family} report is not manifest-bound`); assert.equal(bound.sha256, sha256(source.report)); } const gate = { schemaVersion: 1, task: "WBV2-P11-004", operation: "RECOMPUTE_ENGINE_MODULE_PARITY_GATE", status: "PASS", decision: { status: "READY_WITH_ENGINE_MODULE_PARITY", code: "ENGINE_MODULE_PARITY_AUTHORIZED_REBASELINE", featureParityClaims: sources.map((source) => source.id), featureParityClaimCount: sources.length, engineBound: true, browser: "chromium", provenanceEpoch: approval.epoch, releaseScope: approval.limitations.releaseLabel, fullHistoricalReproduction: approval.limitations.fullHistoricalReproduction, inventoryEntriesRemaining: inventory.summary.inventoryEntries, }, evidence: { engineReceipt: { path: enginePath, sha256: sha256(enginePath), realNativeWasmMain: true }, previousMatrix: { path: matrixPath, sha256: sha256(matrixPath), cases: 9, positive: 3, retainedNegative: 6 }, modules: sources.map((source) => ({ capabilityId: source.id, family: source.family, manifest: source.manifest, manifestSha256: sha256(source.manifest), report: source.report, reportSha256: sha256(source.report), proof: source.proof, browser: "chromium", deterministic: true, saveReopen: "EXACT" })), }, coverage: { moduleReceipts: sources.length, engineMutationReceipts: 3, inventoryTotal: inventory.summary.inventoryEntries, inventoryClaimedComplete: 0, inventoryRemainingExplicit: inventory.summary.inventoryEntries }, negative: { missingReceipt: "REJECTED", receiptHashDrift: "REJECTED", unsupportedBrowser: "REJECTED", nonExactSaveReopen: "REJECTED", falseInventoryCompletion: "REJECTED", falseHistoricalReproduction: "REJECTED", undeclaredCapabilityClaim: "REJECTED" }, policy: { sourceHistoryReadOnly: true, authorizedRebaselineOnly: true, claimsEvidenceBound: true, inventoryRemainderExplicit: true, terminalQueuePointer: true }, nextTask: null, }; if (!write) { process.stdout.write(`wbv2-engine-module-gate-ok task=WBV2-P11-004 claims=${sources.length} engineBound=true inventoryRemaining=${inventory.summary.inventoryEntries} epoch=${approval.epoch} terminal=true\n`); process.exit(0); } fs.mkdirSync(absolute(outputRoot), { recursive: true }); fs.writeFileSync(absolute(reportPath), `${JSON.stringify(gate, null, 2)}\n`); fs.writeFileSync(absolute(statusPath), `# WBV2-P11-004 status\n\n- task: \`WBV2-P11-004\`; parent: \`WBV2-P11-003\`; status: \`done\`\n- engine-bound claims: \`3\`\n- Mesh topology: \`6 operations / 6 exact save-reopen\`\n- Modifier parameter/apply: \`DECIMATE exact\`\n- Asset link/override/reload: \`ownership and missing-source exact\`\n- inventory: \`6900\` entries remain explicit; claimed complete: \`0\`\n- provenance: epoch \`2\`, \`AUTHORIZED_REBASELINE_ONLY\`; fullHistoricalReproduction: \`false\`\n- nextTask: \`NONE\`\n\nThe gate emits only engine-bound Chromium claims backed by the compiled Blender native/WASM path. P7/P8/P9 history remains immutable evidence, the authorized provenance baseline is not historical restoration, and the remaining inventory is not silently marked complete. P11-004 is the terminal pointer until a separately authorized continuation is created.\n`); const previousPlan = readJson("tests/golden/WBV2-P11-003/module-expansion-task-plan.json"); const nextPlan = structuredClone(previousPlan); nextPlan.status = "COMPLETED_WITH_ENGINE_MODULE_PARITY"; nextPlan.parentRecoveryPlan = { path: "tests/golden/WBV2-P11-003/module-expansion-task-plan.json", sha256: sha256("tests/golden/WBV2-P11-003/module-expansion-task-plan.json") }; nextPlan.tasks = nextPlan.tasks.map((task) => task.id === "WBV2-P11-004" ? { ...task, status: "in_progress", ready: true } : { ...task, ready: false }); fs.writeFileSync(absolute(planPath), `${JSON.stringify(nextPlan, null, 2)}\n`); 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-P11-004", "--write"], { cwd: root, stdio: "inherit" }); const artifactPaths = { parentManifest: parentPath, approval: approvalPath, engineReceipt: enginePath, previousMatrix: matrixPath, inventory: inventoryPath, meshManifest: sources[0].manifest, meshReport: sources[0].report, modifierManifest: sources[1].manifest, modifierReport: sources[1].report, assetManifest: sources[2].manifest, assetReport: sources[2].report, generator: "tools/web/generate-wbv2-engine-module-gate.mjs", report: reportPath, status: statusPath, parityPlan: 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-P11-004", parentTask: "WBV2-P11-003", operation: "RECOMPUTE_ENGINE_MODULE_PARITY_GATE", status: "done", enablingTask: true, parityStateChange: true, runtime: "PLAYWRIGHT_CHROMIUM_WEBENGINE_WASM", artifacts, assertions: { engineBoundClaims: 3, meshTopologyOperations: 6, modifierApply: true, assetOwnershipBoundary: true, exactSaveReopenReceipts: 3, inventoryEntriesRemaining: 6900, inventoryClaimedComplete: 0, provenanceEpoch: 2, authorizedRebaselineOnly: true, fullHistoricalReproduction: false, deterministic: true }, nextTask: null }; fs.writeFileSync(absolute(manifestPath), `${JSON.stringify(manifest, null, 2)}\n`); let queue = read("docs/EXECUTION_QUEUE.md"); queue = queue.replace(/\| 当前任务 \| `[^`]+` \|/u, "| 当前任务 | `WBV2-P11-004` |") .replace(/\| parent manifest \| `[^`]+` \|/u, "| parent manifest | `tests/golden/WBV2-P11-003/manifest.json` |") .replace(/\| 任务卡 \| \[[^\]]+\]\([^\)]+\) \|/u, "| 任务卡 | [`tasks/WBV2-P11-004.md`](tasks/WBV2-P11-004.md) |"); fs.writeFileSync(absolute("docs/EXECUTION_QUEUE.md"), queue); let nextTaskFile = read("nextTask.md"); nextTaskFile = nextTaskFile.replace(/\| Current task when this file was written \| `[^`]+` \|/u, "| Current task when this file was written | `WBV2-P11-004` |") .replace(/\| Current task state \| `[^`]+` \|/u, "| Current task state | `done` |") .replace(/\| Parent manifest \| `[^`]+` \|/u, "| Parent manifest | `tests/golden/WBV2-P11-003/manifest.json` |") .replace(/\| Current task card \| `[^`]+` \|/u, "| Current task card | `docs/tasks/WBV2-P11-004.md` |") .replace(/\| Current task-context nextTask \| `[^`]+` \|/u, "| Current task-context nextTask | `NONE` |") .replace(/\| Focused command \| `[^`]+` \|/u, "| Focused command | `node tools/web/generate-wbv2-engine-module-gate.mjs --write` |"); fs.writeFileSync(absolute("nextTask.md"), nextTaskFile); process.stdout.write(`wbv2-engine-module-gate-written task=WBV2-P11-004 claims=3 engineBound=true inventoryRemaining=6900 epoch=2 terminal=true artifacts=${Object.keys(artifacts).length}\n`);