Files
workinf_Blender_Wasm/tools/web/generate-wbv2-lighting-receipt.mjs
mes123456 4a5c70910b
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 deduplicated lighting capability coverage
2026-08-28 12:19:18 +08:00

50 lines
9.2 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-P15-002";
const productionPath = `${outputRoot}/lighting-fields-production.json`;
const secondProductionPath = `${outputRoot}/lighting-fields-production.second.json`;
const reportPath = `${outputRoot}/lighting-fields-receipt-report.json`;
const statusPath = "docs/status/WBV2-P15-002.md";
const planPath = `${outputRoot}/lights-task-plan.json`;
const manifestPath = `${outputRoot}/manifest.json`;
const parentPath = "tests/golden/WBV2-P15-001/manifest.json";
const selectionPath = "tests/golden/WBV2-P15-001/lighting-selection-report.json";
const sourceTestPath = "web/tests/e2e/wbv2-lighting-fields-production.spec.ts";
const sourceApiPath = "blender-5.2.0/source/blender/web_engine/web_engine_api.cpp";
const fixturePath = "tests/files/web/basic_scene.blend";
const expectedPath = "tests/golden/M11-02/lighting-field-roundtrip.json";
const parent = json(parentPath); const selection = json(selectionPath); const production = json(productionPath); const second = json(secondProductionPath);
assert.equal(parent.task, "WBV2-P15-001"); assert.equal(parent.status, "done"); assert.equal(parent.nextTask, "WBV2-P15-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, "RENDER.LIGHTING_FIELDS"); assert.equal(selection.candidate.fullFamilyParity, false);
assert.equal(production.task, "WBV2-P15-002"); assert.equal(production.browser, "chromium"); assert.equal(production.queueMutation, false); assert.equal(production.sourceSha256, sha256(fixturePath));
assert.deepEqual(production, second);
assert.equal(production.revisions.length, 10); assert.deepEqual(production.revisions, production.revisions.map((_, index) => production.beforeRevision + index));
assert.equal(production.malformed.code, "RENDER_PROPERTY_INVALID"); assert.equal(production.malformedRevisionPreserved, true); assert.equal(production.reopenedRevision, 1);
for (const field of ["lensMm", "sensorWidthMm", "sensorHeightMm", "sensorFit", "near", "far", "orthoScale"]) assert.ok(field in production.camera, `camera field missing: ${field}`);
for (const field of ["color", "energy", "exposure", "temperature", "castsShadow", "radius", "spotAngle", "spotBlend", "areaSize", "areaSizeY"]) assert.ok(field in production.light, `light field missing: ${field}`);
assert.equal(production.world.mist.type, "LINEAR"); assert.equal(production.world.mist.enabled, true);
const receipt = { schemaVersion: 1, task: "WBV2-P15-002", operation: "LIGHTING_FIELDS_ENGINE_RECEIPT", status: "PASS", browser: "chromium", queueMutation: false, source: { task: "WBV2-P15-001", manifest: parentPath, manifestSha256: sha256(parentPath), selection: selectionPath, selectionSha256: sha256(selectionPath), fixture: fixturePath, fixtureSha256: sha256(fixturePath), expected: expectedPath, expectedSha256: sha256(expectedPath), api: sourceApiPath, apiSha256: sha256(sourceApiPath) }, production: { report: productionPath, reportSha256: sha256(productionPath), secondReport: secondProductionPath, secondReportSha256: sha256(secondProductionPath), deterministic: true, operations: ["setCameraProperties", "setLightProperties", "setWorldProperties"], revisions: production.revisions, camera: production.camera, light: production.light, world: production.world, malformed: production.malformed, malformedRevisionPreserved: production.malformedRevisionPreserved, saveReopen: "EXACT", reopenedRevision: production.reopenedRevision }, assertions: { cameraFieldsBound: true, lightFieldsBound: true, worldFieldsBound: true, undoRedoSequential: true, malformedRejected: true, mainUnchangedOnMalformed: true, saveReopenExact: true, deterministic: true, representativeSliceOnly: true, fullFamilyParity: false, historicalReproduction: false } , nextTask: "WBV2-P15-003" };
if (!write) { process.stdout.write(`wbv2-lighting-receipt-ok task=WBV2-P15-002 operations=3 revisions=SEQUENTIAL malformed=REJECTED saveReopen=EXACT deterministic=true next=WBV2-P15-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-P15-002 status\n\n- task: \`WBV2-P15-002\`; parent: \`WBV2-P15-001\`; status: \`done\`\n- Chromium/WASM Main operations: Camera, Light, World fields\n- revisions: \`1 -> 10\` sequential across edit/undo/redo actions\n- malformed camera range: \`RENDER_PROPERTY_INVALID\`; Main revision preserved\n- save/reopen: \`EXACT\`; deterministic second run: \`true\`\n- representative slice: \`true\`; full-family parity: \`false\`; inventory pending: \`6618\`\n- nextTask: \`WBV2-P15-003\`\n\nThe compiled WebEngine WASM Main now has a hash-bound Chromium receipt for bounded Camera/Light/World field edits. The receipt covers only the selected behavior hash and does not close the remaining lighting/render inventory.\n`);
const previousPlan = json("tests/golden/WBV2-P15-001/lights-task-plan.json"); const nextPlan = structuredClone(previousPlan); nextPlan.parentRecoveryPlan = { path: "tests/golden/WBV2-P15-001/lights-task-plan.json", sha256: sha256("tests/golden/WBV2-P15-001/lights-task-plan.json") }; nextPlan.tasks = nextPlan.tasks.map((task) => task.id === "WBV2-P15-002" ? { ...task, status: "done", ready: false } : task.id === "WBV2-P15-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-P15-003.md"), read("docs/tasks/WBV2-P15-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-P15-002", "--write"], { cwd: root, stdio: "inherit" });
const artifactPaths = { parentManifest: parentPath, selection: selectionPath, fixture: fixturePath, expected: expectedPath, sourceApi: sourceApiPath, sourceTest: sourceTestPath, production: productionPath, productionSecond: secondProductionPath, report: reportPath, generator: "tools/web/generate-wbv2-lighting-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-P15-002", parentTask: "WBV2-P15-001", operation: "LIGHTING_FIELDS_ENGINE_RECEIPT", status: "done", enablingTask: false, parityStateChange: true, runtime: "PLAYWRIGHT_CHROMIUM_WEBENGINE_WASM", artifacts, assertions: { operations: 3, cameraFieldsBound: true, lightFieldsBound: true, worldFieldsBound: true, undoRedoSequential: true, malformedRejected: true, malformedMainMutation: false, saveReopen: "EXACT", deterministic: true, representativeSliceOnly: true, fullFamilyParity: false, inventoryTotal: 6900, inventoryPending: 6618, historicalReproduction: false }, nextTask: "WBV2-P15-003" }; fs.writeFileSync(absolute(manifestPath), `${JSON.stringify(manifest, null, 2)}\n`);
let queue = read("docs/EXECUTION_QUEUE.md"); queue = queue.replace(/\| 当前任务 \| `[^`]+` \|/u, "| 当前任务 | `WBV2-P15-003` |").replace(/\| parent manifest \| `[^`]+` \|/u, "| parent manifest | `tests/golden/WBV2-P15-002/manifest.json` |").replace(/\| 任务卡 \| \[[^\]]+\]\([^\)]+\) \|/u, "| 任务卡 | [`tasks/WBV2-P15-003.md`](tasks/WBV2-P15-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-P15-003` |").replace(/\| Current task state \| `[^`]+` \|/u, "| Current task state | `in_progress` |").replace(/\| Parent manifest \| `[^`]+` \|/u, "| Parent manifest | `tests/golden/WBV2-P15-002/manifest.json` |").replace(/\| Current task card \| `[^`]+` \|/u, "| Current task card | `docs/tasks/WBV2-P15-003.md` |").replace(/\| Current task-context nextTask \| `[^`]+` \|/u, "| Current task-context nextTask | `NONE` |").replace(/\| Focused command \| `[^`]+` \|/u, "| Focused command | `node tools/web/generate-wbv2-lighting-gate.mjs --write` |"); fs.writeFileSync(absolute("nextTask.md"), nextTask);
process.stdout.write(`wbv2-lighting-receipt-written task=WBV2-P15-002 operations=3 revisions=SEQUENTIAL malformed=REJECTED saveReopen=EXACT deterministic=true next=WBV2-P15-003 artifacts=${Object.keys(artifacts).length}\n`);