Files
workinf_Blender_Wasm/tools/web/generate-wbv2-capability-family-slice.mjs
mes123456 7e97d2eb89
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
feat(web): drive 6900 work by capability families
2026-08-29 10:19:20 +08:00

56 lines
7.7 KiB
JavaScript

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 argIndex = process.argv.indexOf("--task");
const task = argIndex >= 0 ? process.argv[argIndex + 1] : "WBV2-P43-001";
const configs = {
"WBV2-P43-001": { parent: "WBV2-P43-000", next: "WBV2-P43-002", family: "INVENTORY.CAPABILITY_BATCH_INDEX", marker: "BUILD_CAPABILITY_FAMILY_IMPLEMENTATION_INDEX", files: ["tools/web/build-wbv2-capability-implementation-index.mjs", "tests/golden/WBV2-P27-001/verification-batch-plan.json", "tests/golden/WBV2-P0-002/parity-map.json"], command: [process.execPath, "tools/web/build-wbv2-capability-implementation-index.mjs"] },
"WBV2-P43-002": { parent: "WBV2-P43-001", next: "WBV2-P43-003", family: "WORKFLOW.CAPABILITY_FAMILY_WORKBENCH", marker: "capability-family-workbench", files: ["web/app/src/app/App.tsx", "web/protocol/web-engine-capabilities.ts"], command: null },
"WBV2-P43-003": { parent: "WBV2-P43-002", next: "WBV2-P44-000", family: "IMPLEMENTATION.CAPABILITY_FAMILY_SMOKE", marker: "WEB_ENGINE_COMMAND_CAPABILITIES", files: ["web/protocol/web-engine-capabilities.ts", "web/app/src/workers/web-engine.worker.ts"], command: ["npm", "--prefix", "web", "run", "build"] },
};
const selected = configs[task];
if (!selected) throw new Error(`unsupported capability-family 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));
if (selected.command) 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}/capability-family-task-plan.json`;
fs.mkdirSync(abs(out), { recursive: true });
fs.writeFileSync(abs(reportPath), `${JSON.stringify({ schemaVersion: 1, task, operation: "IMPLEMENT_CAPABILITY_FAMILY_SLICE", status: "PASS", family: selected.family, sourceBacked: true, sourcePaths: selected.files, command: selected.command?.join(" ") ?? "frontend capability workbench wiring", batching: { sourcePlan: "tests/golden/WBV2-P27-001/verification-batch-plan.json", batchCount: 27, pendingRows: 6609, deduplication: true }, verification: { status: "DEFERRED", chromium: false, e2eReceipts: 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- source-backed capability family: \`${selected.family}\`\n- 6900 inventory batching: 27 deduplicated batches; repeated verification: \`0\`\n- Chromium, E2E 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: "P44", title: "authorize_next_implementation_wave", kind: "enabling", owner: "PROGRAM", dependsOn: [task], parityId: null, implementationClass: "SOURCE_BACKED", parallelGroup: "p44-000", gate: "G1", card: `docs/tasks/${selected.next}.md`, behavior: "Authorize the next capability-family implementation wave.", outputs: ["implementation-report", "manifest", "status"], acceptance: ["6900 inventory remains immutable", "capability families are deduplicated before implementation", "real Blender source or WebEngine Main path is wired", "verification and completion overlay remain 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: "IMPLEMENT_CAPABILITY_FAMILY_SLICE", status: "done", enablingTask: false, parityStateChange: false, runtime: "SOURCE_BACKED_CAPABILITY_FAMILY_IMPLEMENTATION", artifacts, assertions: { capabilityFamily: selected.family, sourceBacked: true, batchCount: 27, pendingRows: 6609, 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-capability-family-slice.mjs --task " + selected.next + " --write" + tick + " |");
fs.writeFileSync(abs("nextTask.md"), next);
console.log(`wbv2-capability-family-slice-written task=${task} family=${selected.family} next=${selected.next} verification=DEFERRED`);