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-P12-002"); const fixture = fs.readFileSync(path.join(root, "tests/files/web/generated/WBV2-P2-002-OBJECT.TRANSFORM_HIERARCHY.blend")); const sourceSha256 = crypto.createHash("sha256").update(fixture).digest("hex"); test("WBV2-P12-002 executes visibility and transform transactions through 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 shape = (error: any) => ({ code: error?.code, message: error?.message }); const objectState = (snapshot: any, id: string) => { const object = snapshot.nodes.find((candidate: any) => candidate.id === id); if (!object) throw new Error(`object missing: ${id}`); return { id: object.id, visible: object.visible, parentId: object.parentId, translation: object.transform?.translation ?? object.translation, worldMatrix: object.worldMatrix }; }; 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 parentId = "object:WBV2P2002Parent"; const childId = "object:WBV2P2002Child"; const beforeParent = objectState(opened.snapshot, parentId); const beforeChild = objectState(opened.snapshot, childId); const hidden = await client.applyCommand({ type: "setObjectVisibility", objectId: parentId, visible: false, baseRevision: opened.snapshot.revision } as any); const transformed = await client.applyCommand({ type: "setObjectTransform", objectId: childId, translation: [0.5, 2.5, 0], rotationEuler: [0, 0, 0], scale: [1, 1, 1], baseRevision: hidden.snapshot.revision } as any); const afterParent = objectState(transformed.snapshot, parentId); const afterChild = objectState(transformed.snapshot, childId); const stale = await client.applyCommand({ type: "setObjectVisibility", objectId: parentId, visible: true, baseRevision: opened.snapshot.revision } as any).then(() => ({ code: "NO_ERROR" })).catch(shape); const malformed = await client.applyCommand({ type: "setObjectTransform", objectId: childId, translation: [0.5, 2.5], rotationEuler: [0, 0, 0], scale: [1, 1, 1], baseRevision: transformed.snapshot.revision } as any).then(() => ({ code: "NO_ERROR" })).catch(shape); const unchanged = (await client.snapshot()).snapshot; const saved = await client.saveBlend(); const savedSha256 = await digest(saved.slice(0)); const reopened = await reopenedClient.openBlend(saved.slice(0)); const reopenedParent = objectState(reopened.snapshot, parentId); const reopenedChild = objectState(reopened.snapshot, childId); return { baseRevision: opened.snapshot.revision, hiddenRevision: hidden.snapshot.revision, transformedRevision: transformed.snapshot.revision, beforeParent, beforeChild, afterParent, afterChild, stale, malformed, unchangedParent: objectState(unchanged, parentId), unchangedChild: objectState(unchanged, childId), reopenedParent, reopenedChild, savedSha256, sourceSha256: await digest(Uint8Array.from(input.bytes).buffer), exactSaveReopen: JSON.stringify({ parent: afterParent, child: afterChild }) === JSON.stringify({ parent: reopenedParent, child: reopenedChild }) }; } finally { client.terminate(); reopenedClient.terminate(); } }, { bytes: Array.from(fixture) }); fs.mkdirSync(evidenceRoot, { recursive: true }); const output = process.env.WBV2_SCENE_OBJECT_REPORT ?? "scene-object-production.json"; fs.writeFileSync(path.join(evidenceRoot, output), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P12-002", operation: "SCENE_OBJECT_WORKFLOW_ENGINE_CHROMIUM", browser: "chromium", queueMutation: false, ...result }, null, 2)}\n`); expect(result.sourceSha256).toBe(sourceSha256); expect(result.hiddenRevision).toBe(result.baseRevision + 1); expect(result.transformedRevision).toBe(result.baseRevision + 2); expect(result.afterParent.visible).toBe(false); expect(result.afterChild.translation).toEqual([0.5, 2.5, 0]); expect(result.exactSaveReopen).toBe(true); expect(result.stale.code).not.toBe("NO_ERROR"); expect(result.stale.message).toContain("REVISION_CONFLICT"); expect(result.malformed.code).not.toBe("NO_ERROR"); expect(result.unchangedParent).toEqual(result.afterParent); expect(result.unchangedChild).toEqual(result.afterChild); expect(result.savedSha256).not.toBe(sourceSha256); });