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-P1136-001 preserves Font advanced fields and links 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, dataId: string) => { const font = snapshot.nonMeshData?.find((entry: any) => entry.id === dataId); if (!font) throw new Error(`font missing: ${dataId}`); return { revision: snapshot.revision, characters: font.fontCharacters?.map((item: any) => ({ ...item })), textBoxes: font.fontTextBoxes?.map((item: any) => ({ ...item })), activeTextBox: font.activeFontTextBox, links: font.fontLinks ? { ...font.fontLinks } : null }; }; try { const opened = await client.openBlend(Uint8Array.from(input.bytes).buffer); const font = opened.snapshot.nonMeshData?.find((entry: any) => entry.type === "FONT" && entry.fontCharacters?.length && entry.fontTextBoxes?.length); if (!font) throw new Error("fixture has no Font advanced data"); const dataId = font.id as string; const before = summary(opened.snapshot, dataId); const characters = font.fontCharacters.map((item: any, index: number) => index === 0 ? { ...item, kern: 0.1 } : { ...item }); const advanced = await client.applyCommand({ type: "setFontAdvanced", dataId, characters, textBoxes: font.fontTextBoxes.map((item: any) => ({ ...item })), activeTextBox: font.activeFontTextBox } as any); const afterAdvanced = summary(advanced.snapshot, dataId); const advancedUndo = await client.applyCommand({ type: "undo" } as any); const advancedRedo = await client.applyCommand({ type: "redo" } as any); const links = { ...font.fontLinks }; const linked = await client.applyCommand({ type: "setFontLinks", dataId, links } as any); const afterLinks = summary(linked.snapshot, dataId); const malformed = await client.applyCommand({ type: "setFontAdvanced", dataId, characters: [], textBoxes: font.fontTextBoxes, activeTextBox: 0 } as any).then(() => ({ code: "NO_ERROR" })).catch((error: any) => ({ code: error?.code, message: error?.message })); const afterMalformed = summary((await client.snapshot()).snapshot, dataId); const saved = await client.saveBlend(); const reopened = await reopenedClient.openBlend(saved.slice(0)); const afterReopen = summary(reopened.snapshot, dataId); return { fixtureSha256: input.fixtureSha256, dataId, before, afterAdvanced, advancedUndo: summary(advancedUndo.snapshot, dataId), advancedRedo: summary(advancedRedo.snapshot, dataId), afterLinks, malformed, afterMalformed, 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-P1136-001"), { recursive: true }); fs.writeFileSync(path.join(root, "tests/golden/WBV2-P1136-001/font-advanced-production.json"), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P1136-001", operation: "FONT_ADVANCED_MAIN_CHROMIUM", browser: "chromium", queueMutation: false, ...result }, null, 2)}\n`); expect(result.error).toBeUndefined(); expect(result.fixtureSha256).toBe(fixtureSha256); expect(result.afterAdvanced.characters[0].kern).toBeCloseTo(0.1, 5); expect(result.advancedUndo.characters).toEqual(result.before.characters); expect(result.advancedRedo.characters).toEqual(result.afterAdvanced.characters); expect(result.afterLinks.links).toEqual(result.before.links); expect(result.malformed.code).not.toBe("NO_ERROR"); expect(result.afterMalformed.characters).toEqual(result.afterLinks.characters); expect(result.afterReopen.characters).toEqual(result.afterLinks.characters); expect(result.afterReopen.links).toEqual(result.afterLinks.links); expect(result.afterReopen.revision).toBe(1); expect(result.savedSha256).not.toBe(fixtureSha256); });