Files
workinf_Blender_Wasm/tools/web/generate-wbv2-coverage-ledger.mjs
mes123456 dc55bacce6
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
Add deduplicated WBV2 inventory coverage workflow
2026-08-28 10:12:29 +08:00

92 lines
12 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 write = process.argv.includes("--write");
const absolute = (file) => path.join(root, file);
const read = (file) => fs.readFileSync(absolute(file), "utf8");
const json = (file) => JSON.parse(read(file));
const sha256 = (file) => crypto.createHash("sha256").update(fs.readFileSync(absolute(file))).digest("hex");
const outputRoot = "tests/golden/WBV2-P14-001";
const ledgerPath = `${outputRoot}/inventory-coverage-ledger.json`;
const reportPath = `${outputRoot}/coverage-ledger-report.json`;
const matrixPath = `${outputRoot}/capability-batch-summary.json`;
const statusPath = "docs/status/WBV2-P14-001.md";
const planPath = `${outputRoot}/coverage-task-plan.json`;
const manifestPath = `${outputRoot}/manifest.json`;
const parentPath = "tests/golden/WBV2-P14-000/manifest.json";
const inventoryPath = "tests/golden/WBV2-P0-002/parity-map.json";
const p13Path = "tests/golden/WBV2-P13-005/high-value-domain-gate-report.json";
const parent = json(parentPath);
assert.equal(parent.task, "WBV2-P14-000");
assert.equal(parent.status, "done");
assert.equal(parent.nextTask, "WBV2-P14-001");
for (const artifact of Object.values(parent.artifacts ?? {})) assert.equal(sha256(artifact.path), artifact.sha256, artifact.path);
const inventory = json(inventoryPath);
const p13 = json(p13Path);
assert.equal(inventory.summary.inventoryEntries, 6900);
assert.equal(inventory.summary.pendingLegacyEntries, 6618);
assert.equal(inventory.summary.capabilityCount, 15);
assert.equal(p13.status, "PASS");
assert.equal(p13.decision.inventoryPending, 6618);
assert.equal(p13.decision.fullHistoricalReproduction, false);
const claimMap = new Map([
["CAP-CORE-OBJECT", { claims: ["CAP-SCENE-OBJECT-ENGINE"], mode: "REPRESENTATIVE_SLICE", evidence: "scene/object visibility and transform" }],
["CAP-CORE-SCENE-GRAPH", { claims: ["CAP-SCENE-OBJECT-ENGINE"], mode: "REPRESENTATIVE_SLICE", evidence: "scene/object visibility and transform" }],
["CAP-MATERIAL-RENDER", { claims: ["CAP-MATERIAL-ANIMATION-ENGINE"], mode: "REPRESENTATIVE_SLICE", evidence: "material/UV and animation receipt; render remains separate" }],
["CAP-MESH-EDITING", { claims: ["CAP-MESH-TOPOLOGY-FAMILY"], mode: "REPRESENTATIVE_SLICE", evidence: "six topology operations" }],
["CAP-MODIFIER-SYSTEM", { claims: ["CAP-MODIFIER-PARAMETER-APPLY"], mode: "REPRESENTATIVE_SLICE", evidence: "DECIMATE apply" }],
["CAP-NODES-GRAPH", { claims: ["NODES.GEOMETRY_ENGINE"], mode: "REPRESENTATIVE_SLICE", evidence: "three graph hashes; unsupported simulation rejected" }],
["CAP-RIG-ANIMATION", { claims: ["RIG.POSE_ENGINE"], mode: "REPRESENTATIVE_SLICE", evidence: "two bones and bounded constraint edit" }],
["CAP-VIEWPORT-NONMESH", { claims: ["CAP-VIEWPORT-NONMESH-ENGINE"], mode: "REPRESENTATIVE_SLICE", evidence: "non-mesh viewport receipt" }],
["CAP-ASSET-CATALOG-MUTATION", { claims: ["CAP-ASSET-LINK-OVERRIDE-RELOAD"], mode: "REPRESENTATIVE_SLICE", evidence: "ownership and local append" }],
]);
const sourceClaims = new Set(p13.decision.featureParityClaims);
for (const claim of ["CAP-MESH-TOPOLOGY-FAMILY", "CAP-MODIFIER-PARAMETER-APPLY", "CAP-ASSET-LINK-OVERRIDE-RELOAD", "CAP-SCENE-OBJECT-ENGINE", "CAP-MATERIAL-ANIMATION-ENGINE", "CAP-VIEWPORT-NONMESH-ENGINE", "NODES.GEOMETRY_ENGINE", "RIG.POSE_ENGINE"]) assert(sourceClaims.has(claim), claim);
const groups = new Map();
for (const entry of inventory.entries) {
const group = groups.get(entry.capabilityId) ?? { capabilityId: entry.capabilityId, family: entry.family, layer: entry.layer, total: 0, completed: 0, pending: 0, active: 0, representativeEvidence: claimMap.get(entry.capabilityId) ?? { claims: [], mode: "UNPROVEN", evidence: "no engine-bound receipt" }, kinds: {}, sourceTasks: new Set(), entries: [] };
group.total += 1;
group[entry.legacyState] = (group[entry.legacyState] ?? 0) + 1;
group.kinds[entry.kind] = (group.kinds[entry.kind] ?? 0) + 1;
group.sourceTasks.add(entry.sourceTask);
group.entries.push({ id: entry.id, sourceTask: entry.sourceTask, kind: entry.kind, layer: entry.layer, legacyState: entry.legacyState, state: entry.state, parityClaim: entry.parityClaim, targetImplementationClass: entry.targetImplementationClass });
groups.set(entry.capabilityId, group);
}
const buckets = [...groups.values()].sort((a, b) => a.capabilityId.localeCompare(b.capabilityId)).map((group) => ({ ...group, sourceTasks: [...group.sourceTasks].sort(), evidenceState: group.representativeEvidence.claims.length > 0 ? "PARTIAL_REPRESENTATIVE" : "UNPROVEN", claimCount: group.representativeEvidence.claims.length, entries: group.entries.sort((a, b) => a.id.localeCompare(b.id)) }));
assert.equal(buckets.length, 15);
assert.equal(buckets.reduce((sum, bucket) => sum + bucket.total, 0), 6900);
assert.equal(buckets.reduce((sum, bucket) => sum + (bucket.pending ?? 0), 0), 6618);
assert.equal(buckets.reduce((sum, bucket) => sum + (bucket.completed ?? 0), 0), 281);
assert.equal(buckets.reduce((sum, bucket) => sum + (bucket.active ?? 0), 0), 1);
const entryDigest = crypto.createHash("sha256").update(JSON.stringify(buckets.flatMap((bucket) => bucket.entries.map((entry) => [entry.id, entry.legacyState, entry.capabilityId ?? bucket.capabilityId])))).digest("hex");
const ledger = { schemaVersion: 1, task: "WBV2-P14-001", operation: "INVENTORY_COVERAGE_LEDGER", status: "READY", source: { path: inventoryPath, sha256: sha256(inventoryPath), entryDigest, immutable: true }, policy: { grouping: "CAPABILITY_FAMILY", reuseExistingReceipts: true, duplicateValidationAvoided: true, historicalBytesReadOnly: true, partialClaimsExplicit: true }, inventory: { total: 6900, completed: 281, pending: 6618, active: 1, capabilityBuckets: 15, remainderExplicit: true }, buckets, summary: { totalEntries: 6900, completedEntries: 281, pendingEntries: 6618, activeEntries: 1, buckets: 15, representativeClaimBuckets: buckets.filter((bucket) => bucket.claimCount > 0).length, unprovenBuckets: buckets.filter((bucket) => bucket.claimCount === 0).length, repeatedBlenderRuns: 0, repeatedChromiumRuns: 0, sourceClaimsReused: p13.decision.featureParityClaims.length } };
const compactBuckets = buckets.map(({ entries, ...bucket }) => ({ ...bucket, entries: entries.length }));
const report = { schemaVersion: 1, task: "WBV2-P14-001", operation: "GENERATE_INVENTORY_COVERAGE_LEDGER", status: "PASS", ledgerSha256: "PENDING", inventory: ledger.inventory, entryDigest, buckets: compactBuckets, efficiency: { fullInventoryStreamed: true, existingReceiptsReused: true, repeatedBlenderRuns: 0, repeatedChromiumRuns: 0, duplicateValidationAvoided: true, oneLedgerScan: true }, policy: ledger.policy, nextTask: "WBV2-P14-002" };
if (!write) { process.stdout.write(`wbv2-coverage-ledger-ok task=WBV2-P14-001 entries=6900 buckets=15 pending=6618 representative=${report.buckets.filter((b) => b.claimCount > 0).length} repeatedRuns=0 next=WBV2-P14-002\n`); process.exit(0); }
fs.mkdirSync(absolute(outputRoot), { recursive: true });
fs.writeFileSync(absolute(ledgerPath), `${JSON.stringify(ledger, null, 2)}\n`);
fs.writeFileSync(absolute(matrixPath), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P14-001", operation: "CAPABILITY_BATCH_SUMMARY", sourceLedger: ledgerPath, sourceLedgerSha256: sha256(ledgerPath), buckets: compactBuckets, entryDigest }, null, 2)}\n`);
report.ledgerSha256 = sha256(ledgerPath);
fs.writeFileSync(absolute(reportPath), `${JSON.stringify(report, null, 2)}\n`);
fs.writeFileSync(absolute(statusPath), `# WBV2-P14-001 status\n\n- task: \`WBV2-P14-001\`; parent: \`WBV2-P14-000\`; status: \`done\`\n- inventory streamed: \`6900\` entries across \`15\` capability buckets\n- state: \`281 completed\`, \`1 active\`, \`6618 pending\`\n- representative-evidence buckets: \`${report.buckets.filter((b) => b.claimCount > 0).length}\`; unproven buckets: \`${report.buckets.filter((b) => b.claimCount === 0).length}\`\n- repeated Blender/Chromium validation: \`0\`; duplicate validation avoided: \`true\`\n- entry digest: \`${entryDigest}\`\n- nextTask: \`WBV2-P14-002\`\n\nThe full inventory is streamed once and grouped by capability family. Existing P13 receipts are attached only as representative slices; no bucket is promoted to complete parity unless every entry has independent evidence. The 6618-entry remainder remains explicit.\n`);
const previousPlan = json("tests/golden/WBV2-P14-000/coverage-task-plan.json");
const nextPlan = structuredClone(previousPlan); nextPlan.parentRecoveryPlan = { path: "tests/golden/WBV2-P14-000/coverage-task-plan.json", sha256: sha256("tests/golden/WBV2-P14-000/coverage-task-plan.json") }; nextPlan.tasks = nextPlan.tasks.map((task) => task.id === "WBV2-P14-001" ? { ...task, status: "done", ready: false } : task.id === "WBV2-P14-002" ? { ...task, status: "in_progress", ready: true } : { ...task, ready: false }); fs.writeFileSync(absolute(planPath), `${JSON.stringify(nextPlan, null, 2)}\n`);
fs.writeFileSync(absolute("docs/tasks/WBV2-P14-002.md"), read("docs/tasks/WBV2-P14-002.md").replace("- status: planned", "- status: in_progress"));
execFileSync(process.execPath, [absolute("tools/web/generate-v2-task-index.mjs"), "--plan-path", absolute(planPath)], { cwd: root, stdio: "inherit" });
execFileSync(process.execPath, [absolute("tools/web/check-task-context.mjs"), "--task", "WBV2-P14-001", "--write"], { cwd: root, stdio: "inherit" });
const artifactPaths = { parentManifest: parentPath, inventory: inventoryPath, p13Gate: p13Path, ledger: ledgerPath, batchSummary: matrixPath, report: reportPath, generator: "tools/web/generate-wbv2-coverage-ledger.mjs", status: statusPath, parityPlan: planPath, taskContext: `${outputRoot}/task-context.json` };
const artifacts = Object.fromEntries(Object.entries(artifactPaths).map(([name, file]) => [name, { path: file, sha256: sha256(file) }]));
const manifest = { schemaVersion: 1, task: "WBV2-P14-001", parentTask: "WBV2-P14-000", operation: "GENERATE_INVENTORY_COVERAGE_LEDGER", status: "done", enablingTask: true, parityStateChange: false, runtime: "READ_ONLY_STREAMED_INVENTORY_LEDGER", artifacts, assertions: { inventoryTotal: 6900, completedEntries: 281, activeEntries: 1, pendingEntries: 6618, capabilityBuckets: 15, allEntriesAccounted: true, representativeEvidenceBuckets: report.buckets.filter((b) => b.claimCount > 0).length, unprovenBuckets: report.buckets.filter((b) => b.claimCount === 0).length, repeatedBlenderRuns: 0, repeatedChromiumRuns: 0, duplicateValidationAvoided: true, deterministic: true, historicalReproduction: false }, nextTask: "WBV2-P14-002" };
fs.writeFileSync(absolute(manifestPath), `${JSON.stringify(manifest, null, 2)}\n`);
let queue = read("docs/EXECUTION_QUEUE.md"); queue = queue.replace(/\| 当前任务 \| `[^`]+` \|/u, "| 当前任务 | `WBV2-P14-002` |").replace(/\| parent manifest \| `[^`]+` \|/u, "| parent manifest | `tests/golden/WBV2-P14-001/manifest.json` |").replace(/\| 任务卡 \| \[[^\]]+\]\([^\)]+\) \|/u, "| 任务卡 | [`tasks/WBV2-P14-002.md`](tasks/WBV2-P14-002.md) |"); fs.writeFileSync(absolute("docs/EXECUTION_QUEUE.md"), queue);
let nextTaskFile = read("nextTask.md"); nextTaskFile = nextTaskFile.replace(/\| Current task when this file was written \| `[^`]+` \|/u, "| Current task when this file was written | `WBV2-P14-002` |").replace(/\| Current task state \| `[^`]+` \|/u, "| Current task state | `in_progress` |").replace(/\| Parent manifest \| `[^`]+` \|/u, "| Parent manifest | `tests/golden/WBV2-P14-001/manifest.json` |").replace(/\| Current task card \| `[^`]+` \|/u, "| Current task card | `docs/tasks/WBV2-P14-002.md` |").replace(/\| Current task-context nextTask \| `[^`]+` \|/u, "| Current task-context nextTask | `WBV2-P14-003` |").replace(/\| Focused command \| `[^`]+` \|/u, "| Focused command | `node tools/web/generate-wbv2-capability-evidence-matrix.mjs --write` |"); fs.writeFileSync(absolute("nextTask.md"), nextTaskFile);
process.stdout.write(`wbv2-coverage-ledger-written task=WBV2-P14-001 entries=6900 buckets=15 pending=6618 representative=${report.buckets.filter((b) => b.claimCount > 0).length} repeatedRuns=0 next=WBV2-P14-002 artifacts=${Object.keys(artifacts).length}\n`);