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 abs = (file) => path.join(root, file); const read = (file) => fs.readFileSync(abs(file), "utf8"); const json = (file) => JSON.parse(read(file)); const sha = (file) => crypto.createHash("sha256").update(fs.readFileSync(abs(file))).digest("hex"); const task = process.argv[process.argv.indexOf("--task") + 1] ?? "WBV2-P29-001"; const configs = { "WBV2-P29-001": { parent: "WBV2-P29-000", next: "WBV2-P29-002", family: "GEOMETRY_NODES.NATIVE_DATABLOCK", marker: "web_engine_blend_main_set_geometry_node_graph", files: ["blender-5.2.0/source/blender/web_engine/web_engine_main_state.cpp", "blender-5.2.0/source/blender/web_engine/web_engine_main_state.h", "blender-5.2.0/source/blender/web_engine/web_engine_api.cpp", "web/protocol/geometry-node-commands.ts", "web/app/src/app/App.tsx"] }, "WBV2-P29-002": { parent: "WBV2-P29-001", next: "WBV2-P29-003", family: "SIMULATION.NATIVE_DATABLOCK", marker: "web_engine_blend_main_set_physics_simulation", files: ["blender-5.2.0/source/blender/web_engine/web_engine_main_state.cpp", "blender-5.2.0/source/blender/web_engine/web_engine_main_state.h", "blender-5.2.0/source/blender/web_engine/web_engine_api.cpp", "web/protocol/physics-commands.ts", "web/app/src/app/App.tsx"] }, "WBV2-P29-003": { parent: "WBV2-P29-002", next: "WBV2-P29-004", family: "RENDER.COMPOSITOR_SEQUENCER_DATABLOCK", marker: "compositor", files: ["web/protocol/compositor.ts", "web/protocol/sequencer-export.ts", "web/protocol/render-capabilities.ts", "web/app/src/app/App.tsx"] }, "WBV2-P29-004": { parent: "WBV2-P29-003", next: null, family: "NATIVE_DATABLOCK_IMPLEMENTATION.SMOKE", marker: "web-engine.worker", files: ["web/package.json", "web/app/vite.config.ts", "web/app/src/vendor/blender/web_engine.wasm"] }, }; const config = configs[task]; if (!config) throw new Error(`unsupported native datablock task ${task}`); const parentPath = `tests/golden/${config.parent}/manifest.json`; const parent = json(parentPath); assert.equal(parent.status, "done"); assert.equal(parent.nextTask, task); for (const file of config.files) assert.ok(fs.existsSync(abs(file)), file); if (config.marker.includes("web-engine")) assert.match(read("web/app/src/workers/web-engine.worker.ts"), /applyCommand/u); else assert.match(read(config.files[0]), new RegExp(config.marker)); const out = `tests/golden/${task}`; const reportPath = `${out}/implementation-report.json`; const statusPath = `docs/status/${task}.md`; const planPath = `${out}/native-datablock-task-plan.json`; const nextTask = config.next ?? task; fs.mkdirSync(abs(out), { recursive: true }); fs.writeFileSync(abs(reportPath), `${JSON.stringify({ schemaVersion: 1, task, operation: "IMPLEMENT_NATIVE_DATABLOCK_FAMILY", status: "PASS", family: config.family, sourceBacked: true, implementation: { marker: config.marker, sourcePaths: config.files, duplicateShimAdded: false }, verification: { status: "DEFERRED", chromium: false, receipts: false, completionOverlay: false }, inventory: { total: 6900, legacyCompleted: 281, legacyPending: 6618, effectiveCompleted: 290, effectivePending: 6609 }, nextTask: config.next }, null, 2)}\n`); fs.mkdirSync(abs("docs/status"), { recursive: true }); fs.writeFileSync(abs(statusPath), `# ${task} status\n\n- task: \`${task}\`; parent: \`${config.parent}\`; status: \`done\`\n- native datablock family: \`${config.family}\`; source-backed implementation connected\n- marker: \`${config.marker}\`; duplicate protocol shim: \`false\`\n- Chromium receipts and completion overlay: \`DEFERRED\`\n- inventory unchanged: \`6900\` total, \`281\` legacy completed, \`6618\` legacy pending, \`290/6609\` effective carried forward\n- nextTask: \`${config.next ?? "NONE"}\`\n`); const plan = json(parent.artifacts.plan.path); plan.tasks = plan.tasks.map((candidate) => candidate.id === task ? { ...candidate, status: "done", ready: false } : candidate.id === config.next ? { ...candidate, status: "in_progress", ready: true } : { ...candidate, ready: false }); fs.writeFileSync(abs(planPath), `${JSON.stringify(plan, null, 2)}\n`); if (config.next) fs.writeFileSync(abs(`docs/tasks/${config.next}.md`), read(`docs/tasks/${config.next}.md`).replace("- status: planned", "- status: in_progress")); execFileSync(process.execPath, [abs("tools/web/generate-v2-task-index.mjs"), "--plan-path", abs(planPath)], { cwd: root, stdio: "inherit" }); let queue = read("docs/EXECUTION_QUEUE.md"); queue = queue.replace(/\| 当前任务 \| `[^`]+` \|/u, `| 当前任务 | \`${nextTask}\` |`).replace(/\| parent manifest \| `[^`]+` \|/u, `| parent manifest | \`tests/golden/${task}/manifest.json\` |`).replace(/\| 任务卡 \| \[[^\]]+\]\([^\)]+\) \|/u, `| 任务卡 | [\`tasks/${nextTask}.md\`](tasks/${nextTask}.md) |`); fs.writeFileSync(abs("docs/EXECUTION_QUEUE.md"), queue); execFileSync(process.execPath, [abs("tools/web/check-task-context.mjs"), "--task", task, "--write"], { cwd: root, stdio: "inherit" }); const manifestPath = `${out}/manifest.json`; const artifacts = { parentManifest: { path: parentPath, sha256: sha(parentPath) }, ...Object.fromEntries(config.files.map((file) => [path.basename(file).replace(/\W+/gu, "_").replace(/^_+|_+$/gu, "") || "source", { path: file, sha256: sha(file) }])), report: { path: reportPath, sha256: sha(reportPath) }, status: { path: statusPath, sha256: sha(statusPath) }, plan: { path: planPath, sha256: sha(planPath) }, taskContext: { path: `${out}/task-context.json`, sha256: sha(`${out}/task-context.json`) } }; fs.writeFileSync(abs(manifestPath), `${JSON.stringify({ schemaVersion: 1, task, parentTask: config.parent, operation: "IMPLEMENT_NATIVE_DATABLOCK_FAMILY", status: "done", enablingTask: false, parityStateChange: false, runtime: "SOURCE_BACKED_NATIVE_DATABLOCK_IMPLEMENTATION", artifacts, assertions: { capabilityFamily: config.family, sourceBacked: true, unsupportedFailsClosed: true, verificationDeferred: true, completionOverlayWritten: false, inventoryTotal: 6900, effectiveCompleted: 290, effectivePending: 6609, historicalReproduction: false }, nextTask: config.next }, null, 2)}\n`); if (config.next) execFileSync(process.execPath, [abs("tools/web/check-task-context.mjs"), "--task", config.next, "--write"], { cwd: root, stdio: "inherit" }); let next = read("nextTask.md"); next = next.replace(/\| Current task when this file was written \| `[^`]+` \|/u, `| Current task when this file was written | \`${nextTask}\` |`).replace(/\| Current task state \| `[^`]+` \|/u, `| Current task state | \`${config.next ? "in_progress" : "done"}\` |`).replace(/\| Parent manifest \| `[^`]+` \|/u, `| Parent manifest | \`tests/golden/${task}/manifest.json\` |`).replace(/\| Current task card \| `[^`]+` \|/u, `| Current task card | \`docs/tasks/${nextTask}.md\` |`).replace(/\| Current task-context nextTask \| `[^`]+` \|/u, `| Current task-context nextTask | \`${configs[nextTask]?.next ?? "NONE"}\` |`).replace(/\| Focused command \| `[^`]+` \|/u, `| Focused command | \`node tools/web/generate-wbv2-native-datablock-slice.mjs --task ${nextTask} --write\` |`); fs.writeFileSync(abs("nextTask.md"), next); console.log(`wbv2-native-datablock-slice-written task=${task} family=${config.family} next=${config.next ?? "NONE"} verification=DEFERRED`);