import assert from "node:assert/strict"; import crypto from "node:crypto"; import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); const read = (file) => fs.readFileSync(path.join(root, file), "utf8"); const sha256 = (file) => crypto.createHash("sha256").update(fs.readFileSync(path.join(root, file))).digest("hex"); const queue = read("docs/EXECUTION_QUEUE.md"); const requested = process.argv.indexOf("--task"); const current = requested >= 0 ? process.argv[requested + 1] : queue.match(/\|\s*当前任务\s*\|\s*`([^`]+)`/u)?.[1]; assert.match(current ?? "", /^WBV2-P\d-\d{3}$/u); const currentCard = `docs/tasks/${current}.md`; assert.ok(fs.existsSync(path.join(root, currentCard)), `${currentCard} must exist`); const parentPath = requested >= 0 ? `tests/golden/${JSON.parse(read(`tests/golden/${current}/manifest.json`)).parentTask}/manifest.json` : queue.match(/\|\s*parent manifest\s*\|\s*`([^`]+)`/iu)?.[1]; const currentManifestPath = `tests/golden/${current}/manifest.json`; const currentManifest = fs.existsSync(path.join(root, currentManifestPath)) ? JSON.parse(read(currentManifestPath)) : null; if (currentManifest) { assert.equal(currentManifest.task, current); assert.ok(["done", "in_progress", "blocked"].includes(currentManifest.status)); } const expectedParent = currentManifest?.parentTask ?? path.basename(path.dirname(parentPath ?? "")); assert.equal(parentPath, `tests/golden/${expectedParent}/manifest.json`); const parent = JSON.parse(read(parentPath)); assert.equal(parent.nextTask, current); for (const [name, artifact] of Object.entries(currentManifest?.artifacts ?? {})) { assert.equal(sha256(artifact.path), artifact.sha256, `${name} hash drift: ${artifact.path}`); } process.stdout.write(`v2-handoff-ok task=${current} parent=${expectedParent} status=${currentManifest?.status ?? "awaiting_handoff"} artifacts=${Object.keys(currentManifest?.artifacts ?? {}).length}\n`);