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 writeJson = (file, value) => { fs.mkdirSync(path.dirname(abs(file)), { recursive: true }); fs.writeFileSync(abs(file), `${JSON.stringify(value, null, 2)}\n`); }; const task = "WBV2-P27-001"; const parentTask = "WBV2-P27-000"; const nextTask = "WBV2-P27-002"; const parentManifestPath = `tests/golden/${parentTask}/manifest.json`; const inventoryPath = "tests/golden/WBV2-P0-002/parity-map.json"; const registryPath = "web/protocol/web-engine-capabilities.ts"; const parent = json(parentManifestPath); const inventory = json(inventoryPath); assert.equal(parent.status, "done"); assert.equal(parent.nextTask, task); assert.equal(inventory.summary.inventoryEntries, 6900); assert.equal(inventory.summary.pendingLegacyEntries, 6618); const evidenceIds = new Set(); const behaviorHashes = new Set(); const dedupeKeys = new Set(); const collect = (value) => { if (!value || typeof value !== "object") return; if (Array.isArray(value)) { for (const item of value) collect(item); return; } for (const [key, item] of Object.entries(value)) { if (key === "id" && typeof item === "string" && /^(operator|rna|node|modifier|area|space|keymap|workspace|constraint|datablock|physics|strip|region):/u.test(item)) evidenceIds.add(item); if (key === "behaviorHash" && typeof item === "string") behaviorHashes.add(item); if (key === "dedupeKey" && typeof item === "string") dedupeKeys.add(item); collect(item); } }; const scan = (directory) => { if (!fs.existsSync(abs(directory))) return; for (const entry of fs.readdirSync(abs(directory), { withFileTypes: true })) { if (entry.name === "node_modules" || entry.name.endsWith(".blend") || entry.name.endsWith(".blend1")) continue; const relative = `${directory}/${entry.name}`; if (entry.isDirectory()) scan(relative); else if (entry.isFile() && entry.name.endsWith(".json")) { try { collect(json(relative)); } catch { /* non-JSON artifacts are ignored */ } } } }; scan("tests/golden/WBV2"); const overlayIds = new Set(); for (const entry of inventory.entries) if (entry.legacyState === "completed") overlayIds.add(entry.id); for (const relative of ["tests/golden/WBV2-P23-003/inventory-completion-overlay.json"]) { const overlay = json(relative); for (const entry of overlay.entries ?? []) overlayIds.add(entry.id); } const pending = inventory.entries.filter((entry) => entry.legacyState === "pending" && !overlayIds.has(entry.id)); const groups = new Map(); for (const entry of pending) { const key = `${entry.capabilityId ?? "UNMAPPED"}|${entry.kind}|${entry.targetImplementationClass ?? "UNKNOWN"}`; const group = groups.get(key) ?? { key, capabilityId: entry.capabilityId ?? "UNMAPPED", kind: entry.kind, implementationClass: entry.targetImplementationClass ?? "UNKNOWN", count: 0, representativeIds: [], sourceTasks: new Set() }; group.count += 1; if (group.representativeIds.length < 5) group.representativeIds.push(entry.id); group.sourceTasks.add(entry.sourceTask); groups.set(key, group); } const batches = [...groups.values()].sort((left, right) => left.key.localeCompare(right.key)).map((group, index) => ({ batchId: `P27-BATCH-${String(index + 1).padStart(3, "0")}`, ...group, sourceTasks: [...group.sourceTasks].sort(), dedupe: { behaviorKey: group.key, existingBehaviorEvidence: behaviorHashes.size > 0, existingDedupeEvidence: dedupeKeys.size > 0, repeatedRunsRequired: 0 } })); const out = `tests/golden/${task}`; const planPath = `${out}/verification-batch-plan.json`; const reportPath = `${out}/verification-batch-report.json`; const statusPath = `docs/status/${task}.md`; writeJson(planPath, { schemaVersion: 1, task, operation: "BUILD_DEDUPLICATED_CAPABILITY_FAMILY_BATCHES", status: "READY_FOR_CHROMIUM_WAVE", inventory: { total: 6900, legacyCompleted: 281, legacyPending: 6618, overlayBound: overlayIds.size, effectiveCompleted: 290, effectivePending: 6609 }, evidenceIndex: { scannedRoot: "tests/golden/WBV2", knownEvidenceIds: evidenceIds.size, knownBehaviorHashes: behaviorHashes.size, knownDedupeKeys: dedupeKeys.size }, batching: { strategy: "CAPABILITY_ID_KIND_IMPLEMENTATION_CLASS", batchCount: batches.length, pendingRows: pending.length, rowsPerBatchAverage: Number((pending.length / Math.max(1, batches.length)).toFixed(2)), repeatedRunsRequired: 0, batches } }); writeJson(reportPath, { schemaVersion: 1, task, operation: "BUILD_DEDUPLICATED_CAPABILITY_FAMILY_BATCHES", status: "PASS", inventory: { total: 6900, legacyCompleted: 281, legacyPending: 6618, overlayBound: overlayIds.size, effectiveCompleted: 290, effectivePending: 6609, pendingRows: pending.length }, evidenceReuse: { knownEvidenceIds: evidenceIds.size, knownBehaviorHashes: behaviorHashes.size, knownDedupeKeys: dedupeKeys.size, repeatedBlenderRuns: 0, repeatedWasmRuns: 0, repeatedChromiumRuns: 0, duplicateValidationAvoided: true }, batches: { count: batches.length, strategy: "capability-family-unique-behavior", readyFor: "Chromium-only production wave" }, verification: { executed: false, completionOverlayWritten: false, fullHistoricalReproduction: false }, nextTask }); fs.mkdirSync(abs("docs/status"), { recursive: true }); fs.writeFileSync(abs(statusPath), `# ${task} status\n\n- task: \`${task}\`; parent: \`${parentTask}\`; status: \`done\`\n- deduplicated pending rows: \`${pending.length}\`; capability/kind/implementation batches: \`${batches.length}\`\n- reused evidence index: \`${evidenceIds.size}\` ids, \`${behaviorHashes.size}\` behavior hashes, \`${dedupeKeys.size}\` dedupe keys\n- repeated Blender/WASM/Chromium runs scheduled: \`0\`; Chromium production verification: \`NOT_EXECUTED\`\n- inventory unchanged: \`6900\` total, \`281\` legacy completed, \`6618\` legacy pending, \`290/6609\` effective carried forward\n- nextTask: \`${nextTask}\`\n`); const parentPlanPath = parent.artifacts.plan.path; const nextPlanPath = `${out}/implementation-task-plan.json`; const parentPlan = json(parentPlanPath); parentPlan.tasks = parentPlan.tasks.map((candidate) => candidate.id === task ? { ...candidate, status: "done", ready: false } : candidate.id === nextTask ? { ...candidate, status: "in_progress", ready: true } : { ...candidate, ready: false }); writeJson(nextPlanPath, parentPlan); fs.writeFileSync(abs(`docs/tasks/${nextTask}.md`), read(`docs/tasks/${nextTask}.md`).replace("- status: planned", "- status: in_progress")); execFileSync(process.execPath, [abs("tools/web/generate-v2-task-index.mjs"), "--plan-path", abs(nextPlanPath)], { 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`; writeJson(manifestPath, { schemaVersion: 1, task, parentTask, operation: "BUILD_DEDUPLICATED_CAPABILITY_FAMILY_BATCHES", status: "done", enablingTask: true, parityStateChange: false, runtime: "READ_ONLY_VERIFICATION_BATCH_PLANNER", artifacts: { parentManifest: { path: parentManifestPath, sha256: sha(parentManifestPath) }, inventory: { path: inventoryPath, sha256: sha(inventoryPath) }, registry: { path: registryPath, sha256: sha(registryPath) }, plan: { path: planPath, sha256: sha(planPath) }, report: { path: reportPath, sha256: sha(reportPath) }, status: { path: statusPath, sha256: sha(statusPath) }, taskContext: { path: `${out}/task-context.json`, sha256: sha(`${out}/task-context.json`) } }, assertions: { batchCount: batches.length, pendingRows: pending.length, knownEvidenceIds: evidenceIds.size, knownBehaviorHashes: behaviorHashes.size, knownDedupeKeys: dedupeKeys.size, repeatedBlenderRuns: 0, repeatedWasmRuns: 0, repeatedChromiumRuns: 0, duplicateValidationAvoided: true, verificationExecuted: false, completionOverlayWritten: false, inventoryTotal: 6900, effectiveCompleted: 290, effectivePending: 6609, historicalReproduction: false }, nextTask }); execFileSync(process.execPath, [abs("tools/web/check-task-context.mjs"), "--task", nextTask, "--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 | `in_progress` |").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 | `WBV2-P27-003` |").replace(/\| Focused command \| `[^`]+` \|/u, `| Focused command | \`node tools/web/generate-wbv2-chromium-batch.mjs --task ${nextTask} --write\` |`); fs.writeFileSync(abs("nextTask.md"), next); console.log(`wbv2-verification-batch-written task=${task} batches=${batches.length} pendingRows=${pending.length} next=${nextTask} chromium=DEFERRED`);