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 => { 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"); });