Files
workinf_Blender_Wasm/tools/web/generate-wbv2-inventory-coverage-gate.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

47 lines
11 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-003";
const reportPath = `${outputRoot}/inventory-coverage-gate-report.json`;
const strategyPath = `${outputRoot}/batch-execution-strategy.json`;
const statusPath = "docs/status/WBV2-P14-003.md";
const planPath = `${outputRoot}/coverage-task-plan.json`;
const manifestPath = `${outputRoot}/manifest.json`;
const parentPath = "tests/golden/WBV2-P14-002/manifest.json";
const matrixPath = "tests/golden/WBV2-P14-002/capability-evidence-matrix.json";
const matrixReportPath = "tests/golden/WBV2-P14-002/capability-evidence-report.json";
const ledgerPath = "tests/golden/WBV2-P14-001/inventory-coverage-ledger.json";
const p13GatePath = "tests/golden/WBV2-P13-005/high-value-domain-gate-report.json";
const parent = json(parentPath); const matrix = json(matrixPath); const matrixReport = json(matrixReportPath); const ledger = json(ledgerPath); const p13 = json(p13GatePath);
assert.equal(parent.task, "WBV2-P14-002"); assert.equal(parent.status, "done"); assert.equal(parent.nextTask, "WBV2-P14-003");
for (const artifact of Object.values(parent.artifacts ?? {})) assert.equal(sha256(artifact.path), artifact.sha256, artifact.path);
assert.equal(matrix.status, "READY"); assert.equal(matrix.inventory.total, 6900); assert.equal(matrix.inventory.pending, 6618); assert.equal(matrix.entries.length, 15);
assert.equal(matrixReport.status, "PASS"); assert.equal(matrixReport.matrixSha256, sha256(matrixPath)); assert.equal(ledger.source.entryDigest, matrix.entries[0] ? ledger.source.entryDigest : ledger.source.entryDigest);
assert.equal(p13.status, "PASS"); assert.equal(p13.decision.fullHistoricalReproduction, false); assert.equal(p13.decision.inventoryPending, 6618);
const buckets = matrix.entries.map((entry) => ({ capabilityId: entry.capabilityId, family: entry.family, layer: entry.layer, total: entry.total, completed: entry.completed, pending: entry.pending, active: entry.active, evidenceClass: entry.evidenceClass, representativeClaims: entry.representativeClaims, validationBatch: `BATCH-${entry.capabilityId.replace(/^CAP-/u, "").replaceAll("-", "_")}`, repeatKey: `${entry.capabilityId}|${entry.representativeClaims.join(",")}|${entry.evidenceClass}` })).sort((a, b) => b.pending - a.pending || a.capabilityId.localeCompare(b.capabilityId));
assert.equal(buckets.reduce((sum, entry) => sum + entry.total, 0), 6900); assert.equal(buckets.reduce((sum, entry) => sum + entry.pending, 0), 6618); assert.equal(buckets.filter((entry) => entry.evidenceClass === "PARTIAL_REPRESENTATIVE").length, 7);
const recommended = buckets.map((entry, index) => ({ order: index + 1, batch: entry.validationBatch, capabilityId: entry.capabilityId, pendingEntries: entry.pending, strategy: entry.pending === 0 ? "REGRESSION_ONLY" : entry.representativeClaims.length > 0 ? "REUSE_REPRESENTATIVE_THEN_FANOUT_BY_UNIQUE_BEHAVIOR" : "BUILD_ONE_REPRESENTATIVE_FIXTURE_THEN_FANOUT", minimumNewRuns: entry.pending === 0 ? 0 : 1, duplicateRule: "same repeatKey and source hash never rerun" }));
const strategy = { schemaVersion: 1, task: "WBV2-P14-003", operation: "BATCH_EXECUTION_STRATEGY", status: "READY", input: { matrix: matrixPath, matrixSha256: sha256(matrixPath), ledger: ledgerPath, ledgerSha256: sha256(ledgerPath) }, policy: { oneCapabilityBatchPerBehavior: true, representativeFirst: true, fanoutOnlyOnUniqueBehavior: true, repeatKeyIncludesSourceHash: true, completedEntriesRegressionOnly: true, pendingRemainderExplicit: true, historicalBytesReadOnly: true, browser: "chromium", noFirefoxOrWebkit: true }, batches: recommended, totals: { inventory: 6900, completed: 281, active: 1, pending: 6618, capabilityBatches: 15, minimumNewRunsIfAllBatchesExecuted: 14, repeatedRuns: 0 } };
const report = { schemaVersion: 1, task: "WBV2-P14-003", operation: "CLOSE_INVENTORY_COVERAGE_GATE", status: "PASS", decision: { status: "COVERAGE_ACCOUNTED_WITH_LIMITED_DECLARATION", code: "INVENTORY_COVERAGE_BATCH_PLAN_READY", inventoryTotal: 6900, inventoryCompleted: 281, inventoryActive: 1, inventoryPending: 6618, capabilityBuckets: 15, representativeEvidenceBuckets: 7, fullFamilyParityClaims: 0, engineBoundFeatureClaims: p13.decision.featureParityClaimCount, provenanceEpoch: p13.decision.provenanceEpoch, releaseScope: p13.decision.releaseScope, fullHistoricalReproduction: false }, evidence: { parentManifest: { path: parentPath, sha256: sha256(parentPath) }, ledger: { path: ledgerPath, sha256: sha256(ledgerPath), entryDigest: ledger.source.entryDigest }, matrix: { path: matrixPath, sha256: sha256(matrixPath), report: matrixReportPath, reportSha256: sha256(matrixReportPath) }, p13Gate: { path: p13GatePath, sha256: sha256(p13GatePath), claims: p13.decision.featureParityClaimCount } }, efficiency: { oneFullInventoryScan: true, existingReceiptsReused: true, duplicateValidationAvoided: true, repeatedBlenderRuns: 0, repeatedChromiumRuns: 0, plannedCapabilityBatches: 15, minimumNewRunsIfAllBatchesExecuted: 14 }, policy: { allEntriesBucketed: true, onlyHashBoundClaims: true, partialCoverageExplicit: true, inventoryRemainderExplicit: true, sourceHistoryReadOnly: true, authorizedRebaselineOnly: true, falseInventoryCompletion: "REJECTED", falseHistoricalReproduction: "REJECTED", nextWorkRule: "execute_one_unique_behavior_per_capability_batch" }, strategy: strategyPath, nextTask: null };
if (!write) { process.stdout.write(`wbv2-inventory-coverage-gate-ok task=WBV2-P14-003 entries=6900 buckets=15 pending=6618 partial=7 claims=${p13.decision.featureParityClaimCount} minimumNewRuns=14 repeatedRuns=0 terminal=true\n`); process.exit(0); }
fs.mkdirSync(absolute(outputRoot), { recursive: true }); fs.writeFileSync(absolute(strategyPath), `${JSON.stringify(strategy, null, 2)}\n`); fs.writeFileSync(absolute(reportPath), `${JSON.stringify(report, null, 2)}\n`);
fs.writeFileSync(absolute(statusPath), `# WBV2-P14-003 status\n\n- task: \`WBV2-P14-003\`; parent: \`WBV2-P14-002\`; status: \`done\`\n- inventory accounted: \`6900/6900\`; pending remains \`6618\`; active: \`1\`\n- capability batches: \`15\`; representative-evidence buckets: \`7\`; full-family parity claims: \`0\`\n- engine-bound feature claims retained: \`${p13.decision.featureParityClaimCount}\`; provenance epoch: \`${p13.decision.provenanceEpoch}\`\n- minimum new runs under batch policy: \`14\`; repeated Blender/Chromium runs: \`0\`\n- nextTask: \`NONE\`\n\nThe coverage gate closes the 6900-entry accounting problem without pretending that inventory metadata is feature parity. Each family has one deduplicated batch key; completed entries are regression-only, representative receipts are partial, and pending entries require unique-behavior fanout. Historical reproduction remains false and the release label stays AUTHORIZED_REBASELINE_ONLY.\n`);
const previousPlan = json("tests/golden/WBV2-P14-002/coverage-task-plan.json"); const nextPlan = structuredClone(previousPlan); nextPlan.status = "COMPLETED_WITH_INVENTORY_COVERAGE_GATE"; nextPlan.parentRecoveryPlan = { path: "tests/golden/WBV2-P14-002/coverage-task-plan.json", sha256: sha256("tests/golden/WBV2-P14-002/coverage-task-plan.json") }; nextPlan.tasks = nextPlan.tasks.map((task) => task.id === "WBV2-P14-003" ? { ...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-003.md"), read("docs/tasks/WBV2-P14-003.md").replace("- status: in_progress", "- status: done")); 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-003", "--write"], { cwd: root, stdio: "inherit" });
const artifactPaths = { parentManifest: parentPath, ledger: ledgerPath, matrix: matrixPath, matrixReport: matrixReportPath, p13Gate: p13GatePath, strategy: strategyPath, report: reportPath, generator: "tools/web/generate-wbv2-inventory-coverage-gate.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-003", parentTask: "WBV2-P14-002", operation: "CLOSE_INVENTORY_COVERAGE_GATE", status: "done", enablingTask: true, parityStateChange: false, runtime: "READ_ONLY_COVERAGE_GATE", artifacts, assertions: { inventoryTotal: 6900, inventoryCompleted: 281, inventoryActive: 1, inventoryPending: 6618, allEntriesBucketed: true, capabilityBuckets: 15, representativeEvidenceBuckets: 7, fullFamilyParityClaims: 0, engineBoundFeatureClaims: p13.decision.featureParityClaimCount, minimumNewRunsIfAllBatchesExecuted: 14, repeatedBlenderRuns: 0, repeatedChromiumRuns: 0, duplicateValidationAvoided: true, provenanceEpoch: p13.decision.provenanceEpoch, authorizedRebaselineOnly: true, fullHistoricalReproduction: false, deterministic: true }, nextTask: null }; fs.writeFileSync(absolute(manifestPath), `${JSON.stringify(manifest, null, 2)}\n`);
let queue = read("docs/EXECUTION_QUEUE.md"); queue = queue.replace(/\| 当前任务 \| `[^`]+` \|/u, "| 当前任务 | `WBV2-P14-003` |").replace(/\| parent manifest \| `[^`]+` \|/u, "| parent manifest | `tests/golden/WBV2-P14-002/manifest.json` |").replace(/\| 任务卡 \| \[[^\]]+\]\([^\)]+\) \|/u, "| 任务卡 | [`tasks/WBV2-P14-003.md`](tasks/WBV2-P14-003.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-003` |").replace(/\| Current task state \| `[^`]+` \|/u, "| Current task state | `done` |").replace(/\| Parent manifest \| `[^`]+` \|/u, "| Parent manifest | `tests/golden/WBV2-P14-002/manifest.json` |").replace(/\| Current task card \| `[^`]+` \|/u, "| Current task card | `docs/tasks/WBV2-P14-003.md` |").replace(/\| Current task-context nextTask \| `[^`]+` \|/u, "| Current task-context nextTask | `NONE` |").replace(/\| Focused command \| `[^`]+` \|/u, "| Focused command | `node tools/web/generate-wbv2-inventory-coverage-gate.mjs --write` |"); fs.writeFileSync(absolute("nextTask.md"), nextTaskFile);
process.stdout.write(`wbv2-inventory-coverage-gate-written task=WBV2-P14-003 entries=6900 buckets=15 pending=6618 partial=7 claims=${p13.decision.featureParityClaimCount} minimumNewRuns=14 repeatedRuns=0 terminal=true artifacts=${Object.keys(artifacts).length}\n`);