104 lines
10 KiB
JavaScript
104 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-P12-004";
|
|
const productionPath = `${outputRoot}/viewport-nonmesh-production.json`;
|
|
const secondProductionPath = `${outputRoot}/viewport-nonmesh-production.second.json`;
|
|
const reportPath = `${outputRoot}/viewport-nonmesh-receipt-report.json`;
|
|
const statusPath = "docs/status/WBV2-P12-004.md";
|
|
const planPath = `${outputRoot}/domain-expansion-task-plan.json`;
|
|
const manifestPath = `${outputRoot}/manifest.json`;
|
|
const parentPath = "tests/golden/WBV2-P12-003/manifest.json";
|
|
const sourceViewportManifestPath = "tests/golden/WBV2-P2-004/manifest.json";
|
|
const sourceViewportReportPath = "tests/golden/WBV2-P2-004/viewport-report.json";
|
|
const sourceNonMeshManifestPath = "tests/golden/WBV2-P4-003/manifest.json";
|
|
const sourceNonMeshReportPath = "tests/golden/WBV2-P4-003/sculpt-report.json";
|
|
|
|
const parent = readJson(parentPath);
|
|
assert.equal(parent.task, "WBV2-P12-003");
|
|
assert.equal(parent.status, "done");
|
|
assert.equal(parent.nextTask, "WBV2-P12-004");
|
|
for (const artifact of Object.values(parent.artifacts ?? {})) assert.equal(sha256(artifact.path), artifact.sha256, artifact.path);
|
|
for (const [manifestPathValue, reportPathValue] of [[sourceViewportManifestPath, sourceViewportReportPath], [sourceNonMeshManifestPath, sourceNonMeshReportPath]]) {
|
|
const manifest = readJson(manifestPathValue);
|
|
const report = readJson(reportPathValue);
|
|
assert.equal(manifest.status, "done");
|
|
assert.equal(report.desktop.status, "EXACT");
|
|
assert.equal(report.wasm.status, "EXACT");
|
|
assert.equal(report.desktop.saveReopen, "EXACT");
|
|
const bound = Object.values(manifest.artifacts ?? {}).find((artifact) => artifact.path === reportPathValue);
|
|
assert.ok(bound);
|
|
assert.equal(bound.sha256, sha256(reportPathValue));
|
|
}
|
|
|
|
assert.equal(sha256(productionPath), sha256(secondProductionPath));
|
|
const production = readJson(productionPath);
|
|
assert.equal(production.task, "WBV2-P12-004");
|
|
assert.equal(production.browser, "chromium");
|
|
assert.equal(production.queueMutation, false);
|
|
assert.equal(production.viewport.sceneId, "scene:WBV2P2004ViewportScene");
|
|
assert.ok(production.viewport.readbackPixels > 0);
|
|
assert.ok(production.viewport.geometryBuffers > 0);
|
|
assert.deepEqual(production.viewport.resources, { activeRequests: 0, liveInputBytes: 0, liveNativeHandles: 0, liveStagingFiles: 0 });
|
|
assert.deepEqual(production.nonMesh.data.map((entry) => entry.type), ["CURVE", "POINT_CLOUD"]);
|
|
assert.ok(production.nonMesh.gates.every((gate) => gate.status === "READY"));
|
|
assert.equal(production.nonMesh.unknown.status, "BLOCKED");
|
|
assert.equal(production.nonMesh.unknown.issueCode, "NON_MESH_DATA_UNSUPPORTED");
|
|
assert.equal(production.nonMesh.editedRevision, production.nonMesh.baseRevision + 1);
|
|
assert.equal(production.nonMesh.saveReopenExact, true);
|
|
assert.equal(production.nonMesh.revisionAfterMalformed, production.nonMesh.editedRevision);
|
|
|
|
const receipt = {
|
|
schemaVersion: 1,
|
|
task: "WBV2-P12-004",
|
|
operation: "VIEWPORT_NONMESH_ENGINE_RECEIPT",
|
|
status: "PASS",
|
|
browser: "chromium",
|
|
queueMutation: false,
|
|
source: { viewport: { task: "WBV2-P2-004", manifest: sourceViewportManifestPath, manifestSha256: sha256(sourceViewportManifestPath), report: sourceViewportReportPath, reportSha256: sha256(sourceViewportReportPath) }, nonMesh: { task: "WBV2-P4-003", manifest: sourceNonMeshManifestPath, manifestSha256: sha256(sourceNonMeshManifestPath), report: sourceNonMeshReportPath, reportSha256: sha256(sourceNonMeshReportPath) }, reusedReadOnly: true },
|
|
production: { report: productionPath, reportSha256: sha256(productionPath), secondReport: secondProductionPath, secondReportSha256: sha256(secondProductionPath), deterministic: true, viewport: { sceneId: production.viewport.sceneId, meshCount: production.viewport.meshCount, geometryBuffers: production.viewport.geometryBuffers, readbackPixels: production.viewport.readbackPixels, resources: production.viewport.resources }, nonMesh: { data: production.nonMesh.data, gates: production.nonMesh.gates, curveId: production.nonMesh.curveId, baseRevision: production.nonMesh.baseRevision, editedRevision: production.nonMesh.editedRevision, unknown: production.nonMesh.unknown, malformed: production.nonMesh.malformed, revisionAfterMalformed: production.nonMesh.revisionAfterMalformed, saveReopen: production.nonMesh.saveReopenExact } },
|
|
assertions: { viewportPixelsNonblank: true, nonMeshDataExplicit: true, curveMainChanged: true, unsupportedDataBlocked: true, malformedRejected: true, resourceDisposalExact: true, saveReopenExact: true, historicalReproduction: false },
|
|
nextTask: "WBV2-P12-005",
|
|
};
|
|
if (!write) { process.stdout.write("wbv2-viewport-nonmesh-receipt-ok task=WBV2-P12-004 viewport=EXACT nonMesh=EXACT blockedUnknown=true saveReopen=EXACT deterministic=true next=WBV2-P12-005\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-P12-004 status\n\n- task: \`WBV2-P12-004\`; parent: \`WBV2-P12-003\`; status: \`done\`\n- viewport: scene \`scene:WBV2P2004ViewportScene\`; readback pixels \`${production.viewport.readbackPixels}\`; resources disposed exact\n- non-mesh: Curve + Point Cloud binary gates READY; Curve revision \`1 -> 2\`\n- unknown data: BLOCKED; malformed Curve edit rejected without revision change\n- save/reopen: \`EXACT\`; nextTask: \`WBV2-P12-005\`\n\nExisting P2-004 viewport and P4-003 non-mesh source receipts are reused read-only. The production Chromium test binds nonblank viewport readback and bounded non-mesh capability/Curve mutation to the compiled WASM Main, with unsupported data remaining explicit.\n`);
|
|
const previousPlan = readJson("tests/golden/WBV2-P12-003/domain-expansion-task-plan.json");
|
|
const nextPlan = structuredClone(previousPlan);
|
|
nextPlan.parentRecoveryPlan = { path: "tests/golden/WBV2-P12-003/domain-expansion-task-plan.json", sha256: sha256("tests/golden/WBV2-P12-003/domain-expansion-task-plan.json") };
|
|
nextPlan.tasks = nextPlan.tasks.map((task) => task.id === "WBV2-P12-004" ? { ...task, status: "done", ready: false } : task.id === "WBV2-P12-005" ? { ...task, status: "in_progress", ready: true } : { ...task, ready: false });
|
|
fs.writeFileSync(absolute(planPath), `${JSON.stringify(nextPlan, null, 2)}\n`);
|
|
const nextCardPath = "docs/tasks/WBV2-P12-005.md";
|
|
fs.writeFileSync(absolute(nextCardPath), read(nextCardPath).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-P12-004", "--write"], { cwd: root, stdio: "inherit" });
|
|
const artifactPaths = { parentManifest: parentPath, viewportManifest: sourceViewportManifestPath, viewportReport: sourceViewportReportPath, nonMeshManifest: sourceNonMeshManifestPath, nonMeshReport: sourceNonMeshReportPath, production: productionPath, productionSecond: secondProductionPath, e2e: "web/tests/e2e/wbv2-viewport-nonmesh-production.spec.ts", client: "web/app/src/engine-client/WebEngineClient.ts", viewport: "web/app/src/three-adapter/viewport.ts", generator: "tools/web/generate-wbv2-viewport-nonmesh-receipt.mjs", report: reportPath, 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-P12-004", parentTask: "WBV2-P12-003", operation: "VIEWPORT_NONMESH_ENGINE_RECEIPT", status: "done", enablingTask: false, parityStateChange: true, runtime: "PLAYWRIGHT_CHROMIUM_WEBENGINE_WASM", artifacts, assertions: { viewportPixelsNonblank: true, nonMeshDataExplicit: true, curveMainChanged: true, unsupportedDataBlocked: true, resourceDisposalExact: true, saveReopen: "EXACT", deterministic: true, historicalReproduction: false }, nextTask: "WBV2-P12-005" };
|
|
fs.writeFileSync(absolute(manifestPath), `${JSON.stringify(manifest, null, 2)}\n`);
|
|
let queue = read("docs/EXECUTION_QUEUE.md");
|
|
queue = queue.replace(/\| 当前任务 \| `[^`]+` \|/u, "| 当前任务 | `WBV2-P12-005` |")
|
|
.replace(/\| parent manifest \| `[^`]+` \|/u, "| parent manifest | `tests/golden/WBV2-P12-004/manifest.json` |")
|
|
.replace(/\| 任务卡 \| \[[^\]]+\]\([^\)]+\) \|/u, "| 任务卡 | [`tasks/WBV2-P12-005.md`](tasks/WBV2-P12-005.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-P12-005` |")
|
|
.replace(/\| Current task state \| `[^`]+` \|/u, "| Current task state | `in_progress` |")
|
|
.replace(/\| Parent manifest \| `[^`]+` \|/u, "| Parent manifest | `tests/golden/WBV2-P12-004/manifest.json` |")
|
|
.replace(/\| Current task card \| `[^`]+` \|/u, "| Current task card | `docs/tasks/WBV2-P12-005.md` |")
|
|
.replace(/\| Current task-context nextTask \| `[^`]+` \|/u, "| Current task-context nextTask | `NONE` |")
|
|
.replace(/\| Focused command \| `[^`]+` \|/u, "| Focused command | `node tools/web/generate-wbv2-domain-parity-gate.mjs --write` |");
|
|
fs.writeFileSync(absolute("nextTask.md"), nextTaskFile);
|
|
process.stdout.write(`wbv2-viewport-nonmesh-receipt-written task=WBV2-P12-004 viewport=EXACT nonMesh=EXACT saveReopen=EXACT next=WBV2-P12-005 artifacts=${Object.keys(artifacts).length}\n`);
|