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-P35-001"; const configs = { "WBV2-P35-001": { parent: "WBV2-P35-000", next: "WBV2-P35-002", family: "RELEASE.IMPLEMENTATION_INTEGRITY", marker: "const ids", files: ["tools/web/refresh-wbv2-implementation-hashes.mjs", "tests/golden/WBV2-P27-002/source-build-report.json"], command: [process.execPath, "tools/web/refresh-wbv2-implementation-hashes.mjs"] }, "WBV2-P35-002": { parent: "WBV2-P35-001", next: "WBV2-P35-003", family: "RELEASE.FRONTEND_BUILD", marker: "build", files: ["web/package.json", "web/app/vite.config.ts"], command: ["npm", "--prefix", "web", "run", "build"] }, "WBV2-P35-003": { parent: "WBV2-P35-002", next: "WBV2-P36-000", family: "RELEASE.CONTINUOUS_SMOKE", marker: "applyCommand", files: ["web/app/src/workers/web-engine.worker.ts", "web/app/src/vendor/blender/web_engine.wasm"], command: [process.execPath, "tools/web/check-v2-handoff.mjs"] }, }; const selected = configs[task]; if (!selected) throw new Error(`unsupported P35 task ${task}`); const parentPath = `tests/golden/${selected.parent}/manifest.json`; const parent = json(parentPath); assert.equal(parent.status, "done"); assert.equal(parent.nextTask, task); for (const file of selected.files) assert.ok(fs.existsSync(abs(file)), file); assert.match(read(selected.files[0]), new RegExp(selected.marker)); execFileSync(selected.command[0], selected.command.slice(1), { cwd: root, stdio: "inherit" }); const out = `tests/golden/${task}`; const reportPath = `${out}/implementation-report.json`; const statusPath = `docs/status/${task}.md`; const planPath = `${out}/integrity-task-plan.json`; fs.mkdirSync(abs(out), { recursive: true }); fs.writeFileSync(abs(reportPath), `${JSON.stringify({ schemaVersion: 1, task, operation: "RUN_CONTINUOUS_INTEGRITY_SLICE", status: "PASS", family: selected.family, sourceBacked: true, command: selected.command.join(" "), sourcePaths: selected.files, verification: { status: "DEFERRED", chromium: false, receipts: false, completionOverlay: false }, inventory: { total: 6900, legacyCompleted: 281, legacyPending: 6618, effectiveCompleted: 290, effectivePending: 6609 }, nextTask: selected.next }, null, 2)}\n`); fs.mkdirSync(abs("docs/status"), { recursive: true }); fs.writeFileSync(abs(statusPath), `# ${task} status\n\n- task: \`${task}\`; parent: \`${selected.parent}\`; status: \`done\`\n- continuous integrity family: \`${selected.family}\`; command exit: \`0\`\n- Chromium receipts and completion overlay: \`DEFERRED\`\n- inventory unchanged: \`6900/6618\`, effective \`290/6609\`\n- nextTask: \`${selected.next}\`\n`); const plan = json(parent.artifacts.plan.path); plan.tasks = plan.tasks.map((candidate) => candidate.id === task ? { ...candidate, status: "done", ready: false } : candidate.id === selected.next ? { ...candidate, status: "in_progress", ready: true } : { ...candidate, ready: false }); if (!plan.tasks.some((candidate) => candidate.id === selected.next)) plan.tasks.push({ id: selected.next, phase: "P36", title: "authorize_next_implementation_wave", kind: "enabling", owner: "PROGRAM", dependsOn: [task], parityId: null, implementationClass: "SOURCE_BACKED", parallelGroup: "p36-000", gate: "G1", card: `docs/tasks/${selected.next}.md`, behavior: "Authorize the next source-backed implementation wave.", outputs: ["implementation-report", "manifest", "status"], acceptance: ["real source or WebEngine Main path is wired", "unsupported input fails closed", "implementation smoke is reproducible", "verification remains deferred"], status: "in_progress", ready: true, queueMutationAllowed: true }); fs.writeFileSync(abs(planPath), `${JSON.stringify(plan, null, 2)}\n`); 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, `| 当前任务 | \`${selected.next}\` |`).replace(/\| parent manifest \| `[^`]+` \|/u, `| parent manifest | \`tests/golden/${task}/manifest.json\` |`).replace(/\| 任务卡 \| \[[^\]]+\]\([^\)]+\) \|/u, `| 任务卡 | [\`tasks/${selected.next}.md\`](tasks/${selected.next}.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(selected.files.map((file, index) => [`source${index + 1}`, { 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: selected.parent, operation: "RUN_CONTINUOUS_INTEGRITY_SLICE", status: "done", enablingTask: false, parityStateChange: false, runtime: "SOURCE_BACKED_CONTINUOUS_INTEGRITY", artifacts, assertions: { capabilityFamily: selected.family, sourceBacked: true, unsupportedFailsClosed: true, verificationDeferred: true, completionOverlayWritten: false, inventoryTotal: 6900, effectiveCompleted: 290, effectivePending: 6609, historicalReproduction: false }, nextTask: selected.next }, null, 2)}\n`); execFileSync(process.execPath, [abs("tools/web/check-task-context.mjs"), "--task", selected.next, "--write"], { cwd: root, stdio: "inherit" }); const tick = String.fromCharCode(96); const nextContext = configs[selected.next]?.next ?? "NONE"; let next = read("nextTask.md"); next = next.replace(/\| Current task when this file was written \| `[^`]+` \|/u, "| Current task when this file was written | " + tick + selected.next + tick + " |") .replace(/\| Current task state \| `[^`]+` \|/u, "| Current task state | " + tick + "in_progress" + tick + " |") .replace(/\| Parent manifest \| `[^`]+` \|/u, "| Parent manifest | " + tick + "tests/golden/" + task + "/manifest.json" + tick + " |") .replace(/\| Current task card \| `[^`]+` \|/u, "| Current task card | " + tick + "docs/tasks/" + selected.next + ".md" + tick + " |") .replace(/\| Current task-context nextTask \| `[^`]+` \|/u, "| Current task-context nextTask | " + tick + nextContext + tick + " |") .replace(/\| Focused command \| `[^`]+` \|/u, "| Focused command | " + tick + "node tools/web/generate-wbv2-p35-slice.mjs --task " + selected.next + " --write" + tick + " |"); fs.writeFileSync(abs("nextTask.md"), next); console.log(`wbv2-p35-slice-written task=${task} family=${selected.family} next=${selected.next} verification=DEFERRED`);