54 lines
10 KiB
JavaScript
54 lines
10 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-002";
|
|
const matrixPath = `${outputRoot}/capability-evidence-matrix.json`;
|
|
const reportPath = `${outputRoot}/capability-evidence-report.json`;
|
|
const statusPath = "docs/status/WBV2-P14-002.md";
|
|
const planPath = `${outputRoot}/coverage-task-plan.json`;
|
|
const manifestPath = `${outputRoot}/manifest.json`;
|
|
const parentPath = "tests/golden/WBV2-P14-001/manifest.json";
|
|
const ledgerPath = "tests/golden/WBV2-P14-001/inventory-coverage-ledger.json";
|
|
const ledgerReportPath = "tests/golden/WBV2-P14-001/coverage-ledger-report.json";
|
|
const gatePath = "tests/golden/WBV2-P13-005/high-value-domain-gate-report.json";
|
|
const matrixTemplatePath = "docs/BLENDER_WASM_CAPABILITY_MATRIX_TEMPLATE.json";
|
|
|
|
const parent = json(parentPath);
|
|
assert.equal(parent.task, "WBV2-P14-001"); assert.equal(parent.status, "done"); assert.equal(parent.nextTask, "WBV2-P14-002");
|
|
for (const artifact of Object.values(parent.artifacts ?? {})) assert.equal(sha256(artifact.path), artifact.sha256, artifact.path);
|
|
const ledger = json(ledgerPath); const ledgerReport = json(ledgerReportPath); const gate = json(gatePath);
|
|
assert.equal(ledger.status, "READY"); assert.equal(ledger.inventory.total, 6900); assert.equal(ledger.inventory.pending, 6618); assert.equal(ledger.buckets.length, 15);
|
|
assert.equal(ledgerReport.status, "PASS"); assert.equal(ledgerReport.ledgerSha256, sha256(ledgerPath)); assert.equal(gate.status, "PASS");
|
|
assert.equal(gate.decision.featureParityClaimCount, 8); assert.equal(gate.decision.fullHistoricalReproduction, false);
|
|
const claimSet = new Set(gate.decision.featureParityClaims);
|
|
|
|
const entries = ledger.buckets.map((bucket) => {
|
|
const claims = bucket.representativeEvidence?.claims ?? [];
|
|
for (const claim of claims) assert(claimSet.has(claim), `${bucket.capabilityId} references undeclared claim ${claim}`);
|
|
const complete = bucket.completed ?? 0; const pending = bucket.pending ?? 0; const active = bucket.active ?? 0;
|
|
const evidenceClass = claims.length > 0 ? "PARTIAL_REPRESENTATIVE" : active > 0 ? "ACTIVE_UNPROVEN" : pending > 0 ? "UNPROVEN_PENDING" : "LEGACY_COMPLETED_NO_ENGINE_CLAIM";
|
|
return { capabilityId: bucket.capabilityId, family: bucket.family, layer: bucket.layer, total: bucket.total, completed: complete, pending, active, evidenceClass, representativeClaims: claims, representativeEvidence: bucket.representativeEvidence?.evidence ?? "no engine-bound receipt", sourceTasks: bucket.sourceTasks, kinds: bucket.kinds, fullFamilyParity: false, inventoryRemainderExplicit: true };
|
|
}).sort((a, b) => a.capabilityId.localeCompare(b.capabilityId));
|
|
assert.equal(entries.reduce((sum, entry) => sum + entry.total, 0), 6900); assert.equal(entries.reduce((sum, entry) => sum + entry.pending, 0), 6618); assert.equal(entries.filter((entry) => entry.evidenceClass === "PARTIAL_REPRESENTATIVE").length, 7);
|
|
const matrix = { schemaVersion: 1, task: "WBV2-P14-002", operation: "CAPABILITY_EVIDENCE_MATRIX_RECONCILIATION", status: "READY", source: { ledger: ledgerPath, ledgerSha256: sha256(ledgerPath), ledgerReport: ledgerReportPath, ledgerReportSha256: sha256(ledgerReportPath), highValueGate: gatePath, highValueGateSha256: sha256(gatePath), template: matrixTemplatePath, templateSha256: sha256(matrixTemplatePath) }, policy: { representativeClaimsDoNotCloseFamily: true, fullFamilyParityRequiresEntryEvidence: true, inventoryRemainderExplicit: true, historicalBytesReadOnly: true, duplicateValidationAvoided: true }, inventory: { total: 6900, completed: 281, active: 1, pending: 6618, buckets: 15 }, entries };
|
|
const report = { schemaVersion: 1, task: "WBV2-P14-002", operation: "RECONCILE_CAPABILITY_EVIDENCE_MATRIX", status: "PASS", matrixSha256: "PENDING", inventory: matrix.inventory, evidenceClasses: { partialRepresentative: entries.filter((entry) => entry.evidenceClass === "PARTIAL_REPRESENTATIVE").length, unprovenPending: entries.filter((entry) => entry.evidenceClass === "UNPROVEN_PENDING").length, activeUnproven: entries.filter((entry) => entry.evidenceClass === "ACTIVE_UNPROVEN").length, legacyCompletedNoEngineClaim: entries.filter((entry) => entry.evidenceClass === "LEGACY_COMPLETED_NO_ENGINE_CLAIM").length }, featureClaims: [...claimSet], efficiency: { oneLedgerInput: true, existingReceiptsReused: true, repeatedBlenderRuns: 0, repeatedChromiumRuns: 0, duplicateValidationAvoided: true }, policy: matrix.policy, nextTask: "WBV2-P14-003" };
|
|
if (!write) { process.stdout.write(`wbv2-capability-evidence-matrix-ok task=WBV2-P14-002 buckets=15 partial=${report.evidenceClasses.partialRepresentative} pending=6618 claims=8 repeatedRuns=0 next=WBV2-P14-003\n`); process.exit(0); }
|
|
fs.mkdirSync(absolute(outputRoot), { recursive: true }); fs.writeFileSync(absolute(matrixPath), `${JSON.stringify(matrix, null, 2)}\n`); report.matrixSha256 = sha256(matrixPath); fs.writeFileSync(absolute(reportPath), `${JSON.stringify(report, null, 2)}\n`);
|
|
fs.writeFileSync(absolute(statusPath), `# WBV2-P14-002 status\n\n- task: \`WBV2-P14-002\`; parent: \`WBV2-P14-001\`; status: \`done\`\n- capability buckets reconciled: \`15\`; inventory: \`6900\` total, \`6618\` pending\n- representative-evidence buckets: \`${report.evidenceClasses.partialRepresentative}\`; unproven pending buckets: \`${report.evidenceClasses.unprovenPending}\`; active unproven: \`${report.evidenceClasses.activeUnproven}\`\n- engine-bound claims referenced: \`${claimSet.size}\`; full-family parity claims: \`0\`\n- repeated Blender/Chromium validation: \`0\`; duplicate validation avoided: \`true\`\n- nextTask: \`WBV2-P14-003\`\n\nThis matrix binds the P14 coverage ledger to the eight P13 feature claims. Representative receipts remain partial slices; a capability family is not complete until each entry has its own evidence.\n`);
|
|
const previousPlan = json("tests/golden/WBV2-P14-001/coverage-task-plan.json"); const nextPlan = structuredClone(previousPlan); nextPlan.parentRecoveryPlan = { path: "tests/golden/WBV2-P14-001/coverage-task-plan.json", sha256: sha256("tests/golden/WBV2-P14-001/coverage-task-plan.json") }; nextPlan.tasks = nextPlan.tasks.map((task) => task.id === "WBV2-P14-002" ? { ...task, status: "done", ready: false } : 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: 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-002", "--write"], { cwd: root, stdio: "inherit" });
|
|
const artifactPaths = { parentManifest: parentPath, ledger: ledgerPath, ledgerReport: ledgerReportPath, highValueGate: gatePath, matrixTemplate: matrixTemplatePath, matrix: matrixPath, report: reportPath, generator: "tools/web/generate-wbv2-capability-evidence-matrix.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-002", parentTask: "WBV2-P14-001", operation: "RECONCILE_CAPABILITY_EVIDENCE_MATRIX", status: "done", enablingTask: true, parityStateChange: false, runtime: "READ_ONLY_CAPABILITY_EVIDENCE_RECONCILIATION", artifacts, assertions: { inventoryTotal: 6900, inventoryPending: 6618, capabilityBuckets: 15, representativeEvidenceBuckets: report.evidenceClasses.partialRepresentative, unprovenPendingBuckets: report.evidenceClasses.unprovenPending, activeUnprovenBuckets: report.evidenceClasses.activeUnproven, engineBoundClaims: claimSet.size, fullFamilyParityClaims: 0, repeatedBlenderRuns: 0, repeatedChromiumRuns: 0, duplicateValidationAvoided: true, deterministic: true, historicalReproduction: false }, nextTask: "WBV2-P14-003" }; 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 | `in_progress` |").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-capability-evidence-matrix-written task=WBV2-P14-002 buckets=15 partial=${report.evidenceClasses.partialRepresentative} pending=6618 claims=8 repeatedRuns=0 next=WBV2-P14-003 artifacts=${Object.keys(artifacts).length}\n`);
|