Files
workinf_Blender_Wasm/tools/web/generate-wbv2-advanced-ledger.mjs
mes123456 ea18416ff2
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
Advance WBV2 high-value domains through P13
2026-08-28 07:11:47 +08:00

86 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 readJson = (file) => JSON.parse(read(file));
const sha256 = (file) => crypto.createHash("sha256").update(fs.readFileSync(absolute(file))).digest("hex");
const outputRoot = "tests/golden/WBV2-P13-001";
const ledgerPath = `${outputRoot}/advanced-ledger.json`;
const reportPath = `${outputRoot}/advanced-ledger-report.json`;
const sourceIndexPath = `${outputRoot}/advanced-source-index.json`;
const statusPath = "docs/status/WBV2-P13-001.md";
const planPath = `${outputRoot}/high-value-task-plan.json`;
const manifestPath = `${outputRoot}/manifest.json`;
const parentPath = "tests/golden/WBV2-P13-000/manifest.json";
const inventoryPath = "tests/golden/WBV2-P0-002/parity-map.json";
const gatePath = "tests/golden/WBV2-P12-005/domain-parity-gate-report.json";
const sourceTasks = [
"WBV2-P3-001", "WBV2-P3-002", "WBV2-P3-003", "WBV2-P3-004", "WBV2-P3-005",
"WBV2-P4-001", "WBV2-P4-002", "WBV2-P4-003", "WBV2-P4-004",
"WBV2-P5-001", "WBV2-P5-002", "WBV2-P5-003", "WBV2-P6-001", "WBV2-P6-002", "WBV2-P6-003",
];
const domainByTask = new Map([["WBV2-P3-001", "MATERIAL"], ["WBV2-P3-002", "ANIMATION"], ["WBV2-P3-003", "RIG"], ["WBV2-P3-004", "IO"], ["WBV2-P3-005", "ASSET"], ["WBV2-P4-001", "MODIFIER"], ["WBV2-P4-002", "GEOMETRY_NODES"], ["WBV2-P4-003", "SCULPT_NONMESH"], ["WBV2-P4-004", "SIMULATION"], ["WBV2-P5-001", "RENDER"], ["WBV2-P5-002", "MEDIA"], ["WBV2-P5-003", "SERVER"], ["WBV2-P6-001", "SECURITY"], ["WBV2-P6-002", "RELIABILITY"], ["WBV2-P6-003", "RELEASE"]]);
const parent = readJson(parentPath);
assert.equal(parent.task, "WBV2-P13-000");
assert.equal(parent.status, "done");
assert.equal(parent.nextTask, "WBV2-P13-001");
for (const artifact of Object.values(parent.artifacts ?? {})) assert.equal(sha256(artifact.path), artifact.sha256, artifact.path);
const inventory = readJson(inventoryPath);
const entries = sourceTasks.map((task) => {
const manifestPath = `tests/golden/${task}/manifest.json`;
const manifest = readJson(manifestPath);
assert.equal(manifest.status, "done", task);
const artifacts = Object.values(manifest.artifacts ?? {}).map((artifact) => {
const exists = fs.existsSync(absolute(artifact.path));
const currentHash = exists ? sha256(artifact.path) : null;
return { path: artifact.path, recordedSha256: artifact.sha256, exists, currentHash, drift: !exists || currentHash !== artifact.sha256 };
});
return { task, domain: domainByTask.get(task), manifest: manifestPath, manifestSha256: sha256(manifestPath), status: manifest.status, operation: manifest.operation, artifactCount: artifacts.length, currentDriftCount: artifacts.filter((artifact) => artifact.drift).length, evidenceClass: artifacts.some((artifact) => artifact.drift) ? "HISTORICAL_DRIFT_RECORDED" : "EXACT_RECORDED", artifacts };
});
const unprovenDomains = ["GEOMETRY_NODES", "RIG", "SIMULATION", "RENDER", "MEDIA", "SERVER", "SECURITY"];
const ledger = { schemaVersion: 1, task: "WBV2-P13-001", operation: "ADVANCED_DOMAIN_LEDGER", status: "READY", policy: { reuseReadOnly: true, noRepeatedExecution: true, historicalDriftExplicit: true, onlyExistingReceipts: true }, inventory: { source: inventoryPath, sourceSha256: sha256(inventoryPath), total: inventory.summary.inventoryEntries, pending: inventory.summary.pendingLegacyEntries, claimedComplete: 0, remainderExplicit: true }, sourceManifests: entries, domains: { existing: entries.map((entry) => entry.domain), unproven: unprovenDomains }, summary: { manifestsDone: entries.length, artifactRecords: entries.reduce((sum, entry) => sum + entry.artifactCount, 0), historicalDriftManifests: entries.filter((entry) => entry.currentDriftCount > 0).length, repeatedBlenderRuns: 0, repeatedChromiumRuns: 0, unprovenDomains, engineBoundExisting: ["WBV2-P12-005"] } };
const sourceIndex = { schemaVersion: 1, task: "WBV2-P13-001", operation: "ADVANCED_SOURCE_MANIFEST_INDEX", gate: gatePath, gateSha256: sha256(gatePath), entries: entries.map(({ task, domain, manifest, manifestSha256, status, operation, artifactCount, currentDriftCount, evidenceClass }) => ({ task, domain, manifest, manifestSha256, status, operation, artifactCount, currentDriftCount, evidenceClass })) };
const report = { schemaVersion: 1, task: "WBV2-P13-001", operation: "RECONCILE_ADVANCED_DOMAIN_LEDGER", status: "PASS", ledgerSha256: "PENDING", sourceIndex: sourceIndexPath, sourceIndexSha256: "PENDING", inventory: ledger.inventory, summary: ledger.summary, reuse: { existingManifestsRead: entries.length, existingArtifactRecords: ledger.summary.artifactRecords, repeatedBlenderRuns: 0, repeatedChromiumRuns: 0, newProductionClaims: 0 }, policy: { historicalReportsUntouched: true, currentDriftRecorded: true, unprovenDomainsExplicit: true }, nextTask: "WBV2-P13-002" };
if (!write) { process.stdout.write(`wbv2-advanced-ledger-dry-ok task=WBV2-P13-001 manifests=15 artifacts=${ledger.summary.artifactRecords} repeatedRuns=0 next=WBV2-P13-002\n`); process.exit(0); }
fs.mkdirSync(absolute(outputRoot), { recursive: true });
fs.writeFileSync(absolute(ledgerPath), `${JSON.stringify(ledger, null, 2)}\n`);
fs.writeFileSync(absolute(sourceIndexPath), `${JSON.stringify(sourceIndex, null, 2)}\n`);
report.ledgerSha256 = sha256(ledgerPath);
report.sourceIndexSha256 = sha256(sourceIndexPath);
fs.writeFileSync(absolute(reportPath), `${JSON.stringify(report, null, 2)}\n`);
execFileSync(process.execPath, [absolute("tools/web/check-wbv2-advanced-ledger.mjs")], { cwd: root, stdio: "inherit" });
fs.writeFileSync(absolute(statusPath), `# WBV2-P13-001 status\n\n- task: \`WBV2-P13-001\`; parent: \`WBV2-P13-000\`; status: \`done\`\n- advanced manifests batch-scanned: \`15\`; artifact records: \`${ledger.summary.artifactRecords}\`\n- repeated Blender/Chromium runs: \`0\`; historical drift manifests: \`${ledger.summary.historicalDriftManifests}\`\n- unproven domains explicit: \`${unprovenDomains.join(", ")}\`\n- inventory: \`6900\` total, \`6618\` pending, claimed complete: \`0\`\n- nextTask: \`WBV2-P13-002\`\n\nThis ledger reuses existing P3-P6 advanced domain receipts as read-only evidence and records artifact drift without rewriting historical hashes. No repeated Blender or Chromium execution was performed. Domains without a new engine-bound receipt remain explicit and cannot become feature claims from metadata alone.\n`);
const previousPlan = readJson("tests/golden/WBV2-P13-000/high-value-task-plan.json");
const nextPlan = structuredClone(previousPlan);
nextPlan.parentRecoveryPlan = { path: "tests/golden/WBV2-P13-000/high-value-task-plan.json", sha256: sha256("tests/golden/WBV2-P13-000/high-value-task-plan.json") };
nextPlan.tasks = nextPlan.tasks.map((task) => task.id === "WBV2-P13-001" ? { ...task, status: "done", ready: false } : task.id === "WBV2-P13-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-P13-002.md"), read("docs/tasks/WBV2-P13-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-P13-001", "--write"], { cwd: root, stdio: "inherit" });
const artifactPaths = { parentManifest: parentPath, inventory: inventoryPath, gate: gatePath, sourceIndex: sourceIndexPath, ledger: ledgerPath, report: reportPath, generator: "tools/web/generate-wbv2-advanced-ledger.mjs", checker: "tools/web/check-wbv2-advanced-ledger.mjs", parityPlan: planPath, status: statusPath, 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-P13-001", parentTask: "WBV2-P13-000", operation: "RECONCILE_ADVANCED_DOMAIN_LEDGER", status: "done", enablingTask: true, parityStateChange: false, runtime: "READ_ONLY_ADVANCED_MANIFEST_BATCH_SCAN", artifacts, assertions: { sourceManifests: 15, artifactRecords: ledger.summary.artifactRecords, repeatedBlenderRuns: 0, repeatedChromiumRuns: 0, historicalDriftExplicit: true, unprovenDomains: unprovenDomains.length, inventoryTotal: 6900, inventoryPending: 6618, inventoryClaimedComplete: 0, historicalReproduction: false }, nextTask: "WBV2-P13-002" };
fs.writeFileSync(absolute(manifestPath), `${JSON.stringify(manifest, null, 2)}\n`);
let queue = read("docs/EXECUTION_QUEUE.md");
queue = queue.replace(/\| 当前任务 \| `[^`]+` \|/u, "| 当前任务 | `WBV2-P13-002` |")
.replace(/\| parent manifest \| `[^`]+` \|/u, "| parent manifest | `tests/golden/WBV2-P13-001/manifest.json` |")
.replace(/\| 任务卡 \| \[[^\]]+\]\([^\)]+\) \|/u, "| 任务卡 | [`tasks/WBV2-P13-002.md`](tasks/WBV2-P13-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-P13-002` |")
.replace(/\| Current task state \| `[^`]+` \|/u, "| Current task state | `in_progress` |")
.replace(/\| Parent manifest \| `[^`]+` \|/u, "| Parent manifest | `tests/golden/WBV2-P13-001/manifest.json` |")
.replace(/\| Current task card \| `[^`]+` \|/u, "| Current task card | `docs/tasks/WBV2-P13-002.md` |")
.replace(/\| Current task-context nextTask \| `[^`]+` \|/u, "| Current task-context nextTask | `WBV2-P13-003` |")
.replace(/\| Focused command \| `[^`]+` \|/u, "| Focused command | `npm --prefix web run test:e2e -- --workers=1 tests/e2e/wbv2-geometry-nodes-production.spec.ts` |");
fs.writeFileSync(absolute("nextTask.md"), nextTaskFile);
process.stdout.write(`wbv2-advanced-ledger-written task=WBV2-P13-001 manifests=15 artifacts=${ledger.summary.artifactRecords} repeatedRuns=0 next=WBV2-P13-002\n`);