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-P10-002"; const bindingPath = `${outputRoot}/native-engine-binding-report.json`; const productionPath = `${outputRoot}/native-engine-production.json`; const productionSecondPath = `${outputRoot}/native-engine-production.second.json`; const reportPath = `${outputRoot}/native-engine-receipt-report.json`; const statusPath = "docs/status/WBV2-P10-002.md"; const planPath = `${outputRoot}/native-parity-task-plan.json`; const manifestPath = `${outputRoot}/manifest.json`; const parentManifestPath = "tests/golden/WBV2-P10-001/manifest.json"; const parent = readJson(parentManifestPath); assert.equal(parent.task, "WBV2-P10-001"); assert.equal(parent.status, "done"); assert.equal(parent.nextTask, "WBV2-P10-002"); for (const artifact of Object.values(parent.artifacts ?? {})) assert.equal(sha256(artifact.path), artifact.sha256, artifact.path); const binding = readJson(bindingPath); assert.equal(binding.task, "WBV2-P10-002"); assert.equal(binding.status, "PASS"); assert.equal(binding.runtime.browser, "chromium"); assert.equal(binding.requirements.compiledNativePresent, true); assert.equal(binding.requirements.wasmBinaryPresent, true); assert.equal(binding.requirements.wasmLoaderPresent, true); assert.equal(binding.requirements.fakeBridgeOnly, false); for (const file of [binding.runtime.native.path, binding.runtime.wasm.path, binding.runtime.javascript.path, binding.abi.nativeApi, binding.abi.mainState, binding.abi.worker]) assert.ok(fs.existsSync(absolute(file)), file); assert.equal(sha256(binding.runtime.native.path), binding.runtime.native.sha256); assert.equal(sha256(binding.runtime.wasm.path), binding.runtime.wasm.sha256); assert.equal(sha256(binding.runtime.javascript.path), binding.runtime.javascript.sha256); assert.equal(sha256(productionPath), sha256(productionSecondPath), "native engine Chromium report is not deterministic"); const production = readJson(productionPath); assert.equal(production.task, "WBV2-P10-002"); assert.equal(production.operation, "NATIVE_WASM_ENGINE_PRODUCTION_CHROMIUM"); assert.equal(production.browser, "chromium"); assert.equal(production.queueMutation, false); assert.equal(production.mesh.editedRevision, production.mesh.baseRevision + 1); assert.equal(production.mesh.afterPosition.length, 3); assert.deepEqual(production.mesh.afterPosition.map((value, index) => Number((value - production.mesh.beforePosition[index]).toFixed(6))), [0.25, -0.5, 1]); assert.deepEqual(production.mesh.reopenedPosition, production.mesh.afterPosition); assert.match(production.mesh.savedSha256, /^[a-f0-9]{64}$/u); assert.notEqual(production.mesh.savedSha256, production.mesh.sourceSha256); assert.equal(production.mesh.stale.code, "INVALID_ARGUMENT"); assert.match(production.mesh.stale.message, /REVISION_CONFLICT/u); assert.equal(production.mesh.malformed.code, "INVALID_ARGUMENT"); assert.equal(production.modifier.editedRevision, production.modifier.baseRevision + 1); assert.equal(production.modifier.afterEnabled, !production.modifier.beforeEnabled); assert.equal(production.modifier.reopenedEnabled, production.modifier.afterEnabled); assert.match(production.modifier.savedSha256, /^[a-f0-9]{64}$/u); assert.notEqual(production.modifier.savedSha256, production.modifier.sourceSha256); assert.match(production.modifier.stale.message, /REVISION_CONFLICT/u); assert.equal(production.modifier.malformed.code, "INVALID_ARGUMENT"); assert.equal(production.asset.appendedRevision, production.asset.baseRevision + 1); assert.equal(production.asset.receipt.operation, "APPEND"); assert.equal(production.asset.receipt.transactionCount, 1); assert.equal(production.asset.appendedClosure.object, true); assert.equal(production.asset.appendedClosure.mesh, true); assert.equal(production.asset.appendedClosure.material, true); assert.equal(production.asset.appendedClosure.image.libraryLinked, false); assert.equal(production.asset.appendedClosure.image.packed, true); assert.deepEqual(production.asset.reopenedClosure, production.asset.appendedClosure); assert.match(production.asset.stale.message, /REVISION_CONFLICT/u); assert.equal(production.asset.collision.code, "ASSET_MANIFEST_INVALID"); assert.equal(production.asset.collisionRevision, production.asset.appendedRevision); const sourceBindings = binding.sourceBindings.map((source) => { const manifest = readJson(source.manifest); const report = readJson(source.report); assert.equal(manifest.status, "done", `${source.task} source manifest is not done`); assert.equal(report.desktop?.status, "EXACT", `${source.task} desktop source is not exact`); assert.equal(report.wasm?.status, "EXACT", `${source.task} WASM source is not exact`); const bound = Object.values(manifest.artifacts ?? {}).find((artifact) => artifact.path === source.report); assert.ok(bound, `${source.task} report is not manifest-bound`); assert.equal(bound.sha256, sha256(source.report)); return { task: source.task, manifest: source.manifest, manifestSha256: sha256(source.manifest), report: source.report, reportSha256: sha256(source.report) }; }); const receipt = { schemaVersion: 1, task: "WBV2-P10-002", operation: "NATIVE_WASM_ENGINE_PRODUCTION_RECEIPT", status: "PASS", browser: "chromium", queueMutation: false, runtime: { binding: bindingPath, bindingSha256: sha256(bindingPath), native: binding.runtime.native, wasm: binding.runtime.wasm, javascript: binding.runtime.javascript, abi: binding.abi }, sourceBindings, production: { report: productionPath, reportSha256: sha256(productionPath), secondReport: productionSecondPath, secondReportSha256: sha256(productionSecondPath), deterministic: true, mesh: { mutation: "translateMeshVertices", revisionDelta: 1, saveReopen: "EXACT", stale: "REVISION_CONFLICT", malformed: "REJECTED" }, modifier: { mutation: "setModifierEnabled", revisionDelta: 1, saveReopen: "EXACT", stale: "REVISION_CONFLICT", malformed: "REJECTED" }, asset: { mutation: "appendLibraryObject", revisionDelta: 1, resourceClosure: "LOCAL_MAIN", saveReopen: "EXACT", stale: "REVISION_CONFLICT", collision: "REJECTED" } }, assertions: { compiledNativeBound: true, compiledWasmBound: true, realEngineMainMutation: true, saveReopenExact: 3, deterministicRuns: 2, failureMatrixClosed: true, fakeBridgeOnly: false, historicalReproduction: false }, nextTask: "WBV2-P10-003", }; if (!write) { process.stdout.write("wbv2-native-engine-receipt-ok task=WBV2-P10-002 native=true wasm=true chromium=true deterministic=true next=WBV2-P10-003\n"); process.exit(0); } fs.mkdirSync(absolute(outputRoot), { recursive: true }); fs.writeFileSync(absolute(reportPath), `${JSON.stringify(receipt, null, 2)}\n`); fs.writeFileSync(absolute(statusPath), `# WBV2-P10-002 status\n\n- task: \`WBV2-P10-002\`; parent: \`WBV2-P10-001\`; status: \`done\`\n- compiled native: \`Blender 5.2.0 LTS\`; compiled WASM: \`web_engine.wasm\`\n- real Main mutations: \`Mesh + Modifier + Asset Catalog\`\n- deterministic Chromium runs: \`2\`; save/reopen: \`3/3 EXACT\`\n- nextTask: \`WBV2-P10-003\`\n\nThe Chromium Worker loaded the checked-in WebEngine WASM and executed the native ABI through WebEngineClient. Mesh translation, modifier state, and library append all changed the real WASM Main, persisted through save/reopen, and rejected stale or malformed inputs without a late mutation. This evidence is engine-bound and still does not claim full historical reproduction.\n`); const previousPlan = readJson("tests/golden/WBV2-P10-001/native-parity-task-plan.json"); const nextPlan = structuredClone(previousPlan); nextPlan.parentRecoveryPlan = { path: "tests/golden/WBV2-P10-001/native-parity-task-plan.json", sha256: sha256("tests/golden/WBV2-P10-001/native-parity-task-plan.json") }; nextPlan.tasks = nextPlan.tasks.map((task) => task.id === "WBV2-P10-002" ? { ...task, status: "done", ready: false } : task.id === "WBV2-P10-003" ? { ...task, status: "in_progress", ready: true } : { ...task, ready: false }); fs.writeFileSync(absolute(planPath), `${JSON.stringify(nextPlan, null, 2)}\n`); const nextCardPath = "docs/tasks/WBV2-P10-003.md"; fs.writeFileSync(absolute(nextCardPath), read(nextCardPath).replace("- status: planned", "- status: in_progress")); 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-P10-002", "--write"], { cwd: root, stdio: "inherit" }); const artifactPaths = { parentManifest: parentManifestPath, binding: bindingPath, production: productionPath, productionSecond: productionSecondPath, e2e: "web/tests/e2e/wbv2-native-engine-production.spec.ts", webEngineClient: "web/app/src/engine-client/WebEngineClient.ts", webEngineWorker: "web/app/src/workers/web-engine.worker.ts", nativeApi: "blender-5.2.0/source/blender/web_engine/web_engine_api.cpp", mainState: "blender-5.2.0/source/blender/web_engine/web_engine_main_state.cpp", nativeBinary: "build_blender_native/bin/blender", wasmBinary: "web/app/src/vendor/blender/web_engine.wasm", wasmJavaScript: "web/app/src/vendor/blender/web_engine.js", generator: "tools/web/generate-wbv2-native-engine-receipt.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-P10-002", parentTask: "WBV2-P10-001", operation: "NATIVE_WASM_ENGINE_PRODUCTION_RECEIPT", status: "done", enablingTask: false, parityStateChange: true, runtime: "PLAYWRIGHT_CHROMIUM_WEBENGINE_WASM", artifacts, assertions: { compiledNativeBound: true, compiledWasmBound: true, realEngineMainMutation: true, deterministic: true, saveReopen: "EXACT", surfaces: 3, historicalReproduction: false }, nextTask: "WBV2-P10-003" }; fs.writeFileSync(absolute(manifestPath), `${JSON.stringify(manifest, null, 2)}\n`); let queue = read("docs/EXECUTION_QUEUE.md"); queue = queue.replace(/\| 当前任务 \| `[^`]+` \|/u, "| 当前任务 | `WBV2-P10-003` |") .replace(/\| parent manifest \| `[^`]+` \|/u, "| parent manifest | `tests/golden/WBV2-P10-002/manifest.json` |") .replace(/\| 任务卡 \| \[[^\]]+\]\([^\)]+\) \|/u, "| 任务卡 | [`tasks/WBV2-P10-003.md`](tasks/WBV2-P10-003.md) |"); fs.writeFileSync(absolute("docs/EXECUTION_QUEUE.md"), queue); process.stdout.write(`wbv2-native-engine-receipt-written task=WBV2-P10-002 native=true wasm=true chromium=true deterministic=true next=WBV2-P10-003 artifacts=${Object.keys(artifacts).length}\n`);