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 fixture = fs.readFileSync(path.join(root, "tests/files/web/nonmesh_scene.blend")); const fixtureSha256 = crypto.createHash("sha256").update(fixture).digest("hex"); test("WBV2-P1101-000 preserves deleteNonMeshData Main recovery semantics", 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 state = (snapshot: any, dataId: string, ownerId: string) => ({ revision: snapshot.revision, hasData: Boolean(snapshot.nonMeshData?.some((entry: any) => entry.id === dataId)), hasOwner: Boolean(snapshot.nodes?.some((entry: any) => entry.id === ownerId)) }); try { const opened = await client.openBlend(Uint8Array.from(input.bytes).buffer); const data = opened.snapshot.nonMeshData?.find((entry: any) => entry.type === "CURVE"); const owner = data && opened.snapshot.nodes?.find((entry: any) => entry.dataId === data.id); if (!data || !owner) throw new Error("nonmesh fixture has no owned Curve"); const before = state(opened.snapshot, data.id, owner.id); const deleted = await client.applyCommand({ type: "deleteNonMeshData", dataId: data.id } as any); const afterDelete = state(deleted.snapshot, data.id, owner.id); const undo = await client.applyCommand({ type: "undo" } as any); const redo = await client.applyCommand({ type: "redo" } as any); const malformed = await client.applyCommand({ type: "deleteNonMeshData", dataId: "curve:missing" } as any).then(() => ({ code: "NO_ERROR" })).catch((error: any) => ({ code: error?.code, message: error?.message })); const afterMalformed = await client.snapshot(); const saved = await client.saveBlend(); const reopened = await reopenedClient.openBlend(saved.slice(0)); return { fixtureSha256: input.fixtureSha256, dataId: data.id, ownerId: owner.id, before, afterDelete, undo: state(undo.snapshot, data.id, owner.id), redo: state(redo.snapshot, data.id, owner.id), malformed, malformedRevisionPreserved: afterMalformed.snapshot.revision === redo.snapshot.revision, reopened: state(reopened.snapshot, data.id, owner.id), savedSha256: await crypto.subtle.digest("SHA-256", saved).then((hash) => Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, "0")).join("")) }; } catch (error: any) { return { error: { code: error?.code, message: error?.message, detail: String(error) } } as any; } finally { client.terminate(); reopenedClient.terminate(); } }, { bytes: Array.from(fixture), fixtureSha256 }); fs.mkdirSync(path.join(root, "tests/golden/WBV2-P1101-000"), { recursive: true }); fs.writeFileSync(path.join(root, "tests/golden/WBV2-P1101-000/nonmesh-delete-production.json"), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P1101-000", operation: "NONMESH_DELETE_MAIN_CHROMIUM", browser: "chromium", queueMutation: false, ...result }, null, 2)}\n`); expect(result.error).toBeUndefined(); expect(result.fixtureSha256).toBe(fixtureSha256); expect(result.before.hasData).toBe(true); expect(result.before.hasOwner).toBe(true); expect(result.afterDelete).toMatchObject({ hasData: false, hasOwner: false }); const stateOnly = ({ revision: _revision, ...state }: any) => state; expect(stateOnly(result.undo)).toEqual(stateOnly(result.before)); expect(stateOnly(result.redo)).toEqual(stateOnly(result.afterDelete)); expect(result.malformed.code).not.toBe("NO_ERROR"); expect(result.malformedRevisionPreserved).toBe(true); expect(stateOnly(result.reopened)).toEqual(stateOnly(result.afterDelete)); expect(result.reopened.revision).toBe(1); expect(result.savedSha256).not.toBe(fixtureSha256); });