Files
workinf_Blender_Wasm/web/tests/e2e/wbv2-geometry-nodes-production.spec.ts
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

48 lines
3.7 KiB
TypeScript

import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
import { expect, test } from "@playwright/test";
const root = path.resolve(import.meta.dirname, "../../..");
const evidenceRoot = path.join(root, "tests/golden/WBV2-P13-002");
const fixturePath = path.join(root, "tests/files/web/modifier_geometry_nodes_scene.blend");
const fixture = fs.readFileSync(fixturePath);
const sourceSha256 = crypto.createHash("sha256").update(fixture).digest("hex");
test("WBV2-P13-002 binds Geometry Nodes graph evidence to compiled WASM Main", async ({ page }) => {
test.setTimeout(180_000);
await page.goto("/");
const result = await page.evaluate(async (input) => {
const { WebEngineClient } = await import("/src/engine-client/WebEngineClient.ts");
const client = new WebEngineClient({ timeoutMs: 60_000 });
const reopenedClient = new WebEngineClient({ timeoutMs: 60_000 });
const digest = async (value: ArrayBuffer): Promise<string> => { const hash = await crypto.subtle.digest("SHA-256", value); return Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, "0")).join(""); };
try {
const opened = await client.openBlend(Uint8Array.from(input.bytes).buffer);
const graphs = opened.snapshot.geometryNodeGraphs ?? [];
if (graphs.length < 2) throw new Error("Geometry Nodes fixture has fewer than two graphs");
const hashesBefore = graphs.map((graph: any) => ({ name: graph.name, graphHash: graph.graphHash, nodes: graph.nodes.map((node: any) => node.type).sort(), links: graph.links.length }));
const unsupported = graphs.find((graph: any) => graph.nodes.some((node: any) => node.type === "GeometryNodeSimulationOutput")) ?? graphs[graphs.length - 1];
const meshId = opened.snapshot.meshes[0]?.id ?? "mesh:missing";
const attempt = await client.applyCommand({ type: "setGeometryNodeGraph", meshId, graph: unsupported, baseRevision: opened.snapshot.revision } as any).then(() => ({ code: "NO_ERROR" })).catch((error: any) => ({ code: error?.code, message: error?.message }));
const after = await client.snapshot();
const saved = await client.saveBlend();
const savedSha256 = await digest(saved.slice(0));
const reopened = await reopenedClient.openBlend(saved.slice(0));
const hashesAfter = (reopened.snapshot.geometryNodeGraphs ?? []).map((graph: any) => ({ name: graph.name, graphHash: graph.graphHash, nodes: graph.nodes.map((node: any) => node.type).sort(), links: graph.links.length }));
return { baseRevision: opened.snapshot.revision, afterRevision: after.snapshot.revision, graphCount: graphs.length, hashesBefore, hashesAfter, unsupportedName: unsupported.name, attempt, savedSha256, sourceSha256: await digest(Uint8Array.from(input.bytes).buffer), saveReopenExact: JSON.stringify(hashesBefore) === JSON.stringify(hashesAfter) };
}
finally { client.terminate(); reopenedClient.terminate(); }
}, { bytes: Array.from(fixture) });
fs.mkdirSync(evidenceRoot, { recursive: true });
const output = process.env.WBV2_GEOMETRY_NODES_REPORT ?? "geometry-nodes-production.json";
fs.writeFileSync(path.join(evidenceRoot, output), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P13-002", operation: "GEOMETRY_NODES_ENGINE_CHROMIUM", browser: "chromium", queueMutation: false, ...result }, null, 2)}\n`);
expect(result.sourceSha256).toBe(sourceSha256);
expect(result.graphCount).toBeGreaterThanOrEqual(2);
expect(result.hashesBefore.length).toBe(result.hashesAfter.length);
expect(result.hashesBefore.every((entry) => /^[a-f0-9]{64}$/u.test(entry.graphHash ?? ""))).toBe(true);
expect(result.saveReopenExact).toBe(true);
expect(result.afterRevision).toBe(result.baseRevision);
expect(result.attempt.code).not.toBe("NO_ERROR");
});