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/generated/WBV2-P4-001-MODIFIER.DECLARED_SLICES.blend")); const fixtureSha256 = crypto.createHash("sha256").update(fixture).digest("hex"); test("WBV2-P1107-000 preserves Modifier visibility flags through Main recovery", 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 summary = (snapshot: any, meshId: string, uuid: string) => { const modifier = snapshot.meshes?.find((mesh: any) => mesh.id === meshId)?.modifierStack?.find((entry: any) => entry.uuid === uuid); if (!modifier) throw new Error(`modifier missing: ${uuid}`); return { revision: snapshot.revision, flags: { showViewport: modifier.showViewport, showRender: modifier.showRender, showEditMode: modifier.showEditMode, showOnCage: modifier.showOnCage } }; }; try { const opened = await client.openBlend(Uint8Array.from(input.bytes).buffer); const mesh = opened.snapshot.meshes?.find((entry: any) => entry.modifierStack?.length); const modifier = mesh?.modifierStack?.find((entry: any) => entry.type === "BEVEL") ?? mesh?.modifierStack?.[0]; if (!mesh || !modifier) throw new Error("modifier fixture has no editable modifier"); const before = summary(opened.snapshot, mesh.id, modifier.uuid); const stackIdentity = (snapshot: any) => snapshot.meshes.find((entry: any) => entry.id === mesh.id) ?.modifierStack.map((entry: any) => ({ uuid: entry.uuid, type: entry.type })); const stackBefore = stackIdentity(opened.snapshot); const edited = await client.applyCommand({ type: "setModifierVisibility", meshId: mesh.id, modifierUuid: modifier.uuid, showViewport: false, showRender: false, showEditMode: true, showOnCage: true } as any); const afterEdit = summary(edited.snapshot, mesh.id, modifier.uuid); const undo = await client.applyCommand({ type: "undo" } as any); const redo = await client.applyCommand({ type: "redo" } as any); const malformed = await client.applyCommand({ type: "setModifierVisibility", meshId: mesh.id, modifierUuid: "modifier:missing", showViewport: true, showRender: true, showEditMode: true, showOnCage: false } 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)); const afterReopen = summary(reopened.snapshot, mesh.id, modifier.uuid); return { fixtureSha256: input.fixtureSha256, meshId: mesh.id, modifierUuid: modifier.uuid, before, stackBefore, stackAfterReopen: stackIdentity(reopened.snapshot), afterEdit, undo: summary(undo.snapshot, mesh.id, modifier.uuid), redo: summary(redo.snapshot, mesh.id, modifier.uuid), malformed, malformedRevisionPreserved: afterMalformed.snapshot.revision === redo.snapshot.revision, afterReopen, 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-P1107-000"), { recursive: true }); fs.writeFileSync(path.join(root, "tests/golden/WBV2-P1107-000/modifier-visibility-production.json"), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P1107-000", operation: "MODIFIER_VISIBILITY_MAIN_CHROMIUM", browser: "chromium", queueMutation: false, ...result }, null, 2)}\n`); expect(result.error).toBeUndefined(); expect(result.fixtureSha256).toBe(fixtureSha256); expect(result.afterEdit.flags).toEqual({ showViewport: false, showRender: false, showEditMode: true, showOnCage: true }); expect(result.undo.flags).toEqual(result.before.flags); expect(result.redo.flags).toEqual(result.afterEdit.flags); expect(result.malformed.code).not.toBe("NO_ERROR"); expect(result.malformedRevisionPreserved).toBe(true); expect(result.afterReopen.flags).toEqual(result.afterEdit.flags); expect(result.afterReopen.revision).toBe(1); expect(result.stackBefore.length).toBeGreaterThan(1); expect(result.stackAfterReopen).toEqual(result.stackBefore); expect(result.savedSha256).not.toBe(fixtureSha256); });