49 lines
10 KiB
JavaScript
49 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-P16-002";
|
|
const productionPath = `${outputRoot}/paint-attributes-production.json`;
|
|
const secondProductionPath = `${outputRoot}/paint-attributes-production.second.json`;
|
|
const reportPath = `${outputRoot}/paint-attributes-receipt-report.json`;
|
|
const statusPath = "docs/status/WBV2-P16-002.md";
|
|
const planPath = `${outputRoot}/paint-task-plan.json`;
|
|
const manifestPath = `${outputRoot}/manifest.json`;
|
|
const parentPath = "tests/golden/WBV2-P16-001/manifest.json";
|
|
const selectionPath = "tests/golden/WBV2-P16-001/paint-selection-report.json";
|
|
const sourceReportPath = "tests/golden/WBV2-P4-003/sculpt-report.json";
|
|
const sourceRunnerPath = "tools/web/check-paint-roundtrip.mjs";
|
|
const sourceApiPath = "blender-5.2.0/source/blender/web_engine/web_engine_api.cpp";
|
|
const sourceTestPath = "web/tests/e2e/wbv2-paint-attributes-production.spec.ts";
|
|
const colorFixturePath = "tests/files/web/attribute_scene.blend";
|
|
const weightFixturePath = "tests/files/web/rigged_shape_scene.blend";
|
|
|
|
const parent = json(parentPath); const selection = json(selectionPath); const production = json(productionPath); const second = json(secondProductionPath);
|
|
assert.equal(parent.task, "WBV2-P16-001"); assert.equal(parent.status, "done"); assert.equal(parent.nextTask, "WBV2-P16-002"); for (const artifact of Object.values(parent.artifacts ?? {})) assert.equal(sha256(artifact.path), artifact.sha256, artifact.path);
|
|
assert.equal(selection.status, "PASS"); assert.equal(selection.candidate.capabilityId, "SCULPT.PAINT_ATTRIBUTES"); assert.equal(selection.inventory.matchedEntries, 117); assert.equal(selection.candidate.fullFamilyParity, false);
|
|
assert.equal(production.task, "WBV2-P16-002"); assert.equal(production.browser, "chromium"); assert.equal(production.queueMutation, false); assert.deepEqual(production, second);
|
|
assert.deepEqual(production.color.revisions, [1, 2, 3, 4]); assert.deepEqual(production.weight.revisions, [1, 2, 3, 4, 5]); assert.deepEqual(production.color.firstColor, [0.125, 0.375, 0.625, 0.875]); assert.deepEqual(production.color.reopenedColors, production.color.firstColor); assert.equal(production.color.malformed.code, "PAINT_SCHEMA_INVALID"); assert.equal(production.color.malformedRevisionPreserved, true); assert.equal(production.color.reopenedRevision, 1); assert.equal(production.weight.groupIndex >= 0, true); assert.ok(Math.abs(production.weight.vertex0 - 0.75) < 1e-5); assert.ok(Math.abs(production.weight.vertex1 - 0.25) < 1e-5); assert.ok(Math.abs(production.weight.normalizedSum - 1) < 1e-5); assert.equal(production.weight.saveReopen, true);
|
|
|
|
const inventoryBindings = [
|
|
{ id: "operator:paint.vertex_color_set", evidence: "setVertexColors", exact: true, reason: "bounded protocol command directly writes corner color attribute" },
|
|
{ id: "operator:paint.weight_set", evidence: "setVertexWeights", exact: true, reason: "bounded protocol command directly writes vertex group weights" },
|
|
];
|
|
const receipt = { schemaVersion: 1, task: "WBV2-P16-002", operation: "PAINT_ATTRIBUTES_ENGINE_RECEIPT", status: "PASS", browser: "chromium", queueMutation: false, source: { task: "WBV2-P16-001", manifest: parentPath, manifestSha256: sha256(parentPath), selection: selectionPath, selectionSha256: sha256(selectionPath), sourceReport: sourceReportPath, sourceReportSha256: sha256(sourceReportPath), runner: sourceRunnerPath, runnerSha256: sha256(sourceRunnerPath), api: sourceApiPath, apiSha256: sha256(sourceApiPath), productionTest: sourceTestPath, productionTestSha256: sha256(sourceTestPath), colorFixture: colorFixturePath, colorFixtureSha256: sha256(colorFixturePath), weightFixture: weightFixturePath, weightFixtureSha256: sha256(weightFixturePath) }, production: { report: productionPath, reportSha256: sha256(productionPath), secondReport: secondProductionPath, secondReportSha256: sha256(secondProductionPath), deterministic: true, operations: ["setVertexColors", "setVertexWeights"], colorRevisions: production.color.revisions, weightRevisions: production.weight.revisions, color: production.color, weight: production.weight, malformed: production.color.malformed, malformedMainMutation: false, saveReopen: "EXACT" }, inventoryBindings, assertions: { colorAttributeBound: true, weightAttributeBound: true, inventoryBindingsExact: true, undoRedoSequential: true, malformedRejected: true, mainUnchangedOnMalformed: true, saveReopenExact: true, deterministic: true, representativeSliceOnly: true, fullFamilyParity: false, historicalReproduction: false }, nextTask: "WBV2-P16-003" };
|
|
if (!write) { process.stdout.write(`wbv2-paint-receipt-ok task=WBV2-P16-002 operations=2 bindings=2 revisions=SEQUENTIAL malformed=REJECTED saveReopen=EXACT deterministic=true next=WBV2-P16-003\n`); process.exit(0); }
|
|
fs.mkdirSync(absolute(outputRoot), { recursive: true }); fs.writeFileSync(absolute(reportPath), `${JSON.stringify(receipt, null, 2)}\n`); fs.writeFileSync(absolute(statusPath), `# WBV2-P16-002 status\n\n- task: \`WBV2-P16-002\`; parent: \`WBV2-P16-001\`; status: \`done\`\n- Chromium/WASM Main operations: \`setVertexColors\`, \`setVertexWeights\`\n- exact inventory bindings: \`operator:paint.vertex_color_set\`, \`operator:paint.weight_set\`\n- revisions: colors \`1 -> 4\`; weights \`1 -> 5\`; malformed color input rejected\n- save/reopen: \`EXACT\`; deterministic second run: \`true\`\n- representative slice: \`true\`; full-family parity: \`false\`; inventory pending before overlay: \`6618\`\n- nextTask: \`WBV2-P16-003\`\n\nThe production receipt binds two specific paint operators to the compiled WASM Main. Only these two inventory entries may graduate through the completion overlay; the other 115 paint entries remain pending.\n`);
|
|
const previousPlan = json("tests/golden/WBV2-P16-001/paint-task-plan.json"); const nextPlan = structuredClone(previousPlan); nextPlan.parentRecoveryPlan = { path: "tests/golden/WBV2-P16-001/paint-task-plan.json", sha256: sha256("tests/golden/WBV2-P16-001/paint-task-plan.json") }; nextPlan.tasks = nextPlan.tasks.map((task) => task.id === "WBV2-P16-002" ? { ...task, status: "done", ready: false } : task.id === "WBV2-P16-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-P16-003.md"), read("docs/tasks/WBV2-P16-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-P16-002", "--write"], { cwd: root, stdio: "inherit" });
|
|
const artifactPaths = { parentManifest: parentPath, selection: selectionPath, sourceReport: sourceReportPath, runner: sourceRunnerPath, api: sourceApiPath, productionTest: sourceTestPath, colorFixture: colorFixturePath, weightFixture: weightFixturePath, production: productionPath, productionSecond: secondProductionPath, report: reportPath, generator: "tools/web/generate-wbv2-paint-receipt.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-P16-002", parentTask: "WBV2-P16-001", operation: "PAINT_ATTRIBUTES_ENGINE_RECEIPT", status: "done", enablingTask: false, parityStateChange: true, runtime: "PLAYWRIGHT_CHROMIUM_WEBENGINE_WASM", artifacts, assertions: { operations: 2, exactInventoryBindings: inventoryBindings.length, boundInventoryIds: inventoryBindings.map((binding) => binding.id), colorAttributeBound: true, weightAttributeBound: true, undoRedoSequential: true, malformedRejected: true, saveReopen: "EXACT", deterministic: true, representativeSliceOnly: true, fullFamilyParity: false, inventoryTotal: 6900, inventoryPending: 6618, historicalReproduction: false }, nextTask: "WBV2-P16-003" }; fs.writeFileSync(absolute(manifestPath), `${JSON.stringify(manifest, null, 2)}\n`);
|
|
let queue = read("docs/EXECUTION_QUEUE.md"); queue = queue.replace(/\| 当前任务 \| `[^`]+` \|/u, "| 当前任务 | `WBV2-P16-003` |").replace(/\| parent manifest \| `[^`]+` \|/u, "| parent manifest | `tests/golden/WBV2-P16-002/manifest.json` |").replace(/\| 任务卡 \| \[[^\]]+\]\([^\)]+\) \|/u, "| 任务卡 | [`tasks/WBV2-P16-003.md`](tasks/WBV2-P16-003.md) |"); fs.writeFileSync(absolute("docs/EXECUTION_QUEUE.md"), queue);
|
|
let nextTask = read("nextTask.md"); nextTask = nextTask.replace(/\| Current task when this file was written \| `[^`]+` \|/u, "| Current task when this file was written | `WBV2-P16-003` |").replace(/\| Current task state \| `[^`]+` \|/u, "| Current task state | `in_progress` |").replace(/\| Parent manifest \| `[^`]+` \|/u, "| Parent manifest | `tests/golden/WBV2-P16-002/manifest.json` |").replace(/\| Current task card \| `[^`]+` \|/u, "| Current task card | `docs/tasks/WBV2-P16-003.md` |").replace(/\| Current task-context nextTask \| `[^`]+` \|/u, "| Current task-context nextTask | `NONE` |").replace(/\| Focused command \| `[^`]+` \|/u, "| Focused command | `node tools/web/generate-wbv2-paint-gate.mjs --write` |"); fs.writeFileSync(absolute("nextTask.md"), nextTask);
|
|
process.stdout.write(`wbv2-paint-receipt-written task=WBV2-P16-002 operations=2 bindings=2 revisions=SEQUENTIAL malformed=REJECTED saveReopen=EXACT deterministic=true next=WBV2-P16-003 artifacts=${Object.keys(artifacts).length}\n`);
|