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/nla_time_mapping_scene.blend")); const fixtureSha256 = crypto.createHash("sha256").update(fixture).digest("hex"); test("WBV2-P1112-000 preserves setNLAStack Main submission and rejects invalid actions", 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 stack = (snapshot: any) => JSON.stringify(snapshot.nlaTracks ?? []); try { const opened = await client.openBlend(Uint8Array.from(input.bytes).buffer); const ownerId = opened.snapshot.nlaTracks?.[0]?.ownerId; if (!ownerId || !opened.snapshot.nlaTracks?.length) throw new Error("NLA fixture has no tracks"); const before = stack(opened.snapshot); const applied = await client.applyCommand({ type: "setNLAStack", objectId: ownerId, tracks: opened.snapshot.nlaTracks, baseRevision: opened.snapshot.revision } as any); const after = stack(applied.snapshot); const undo = await client.applyCommand({ type: "undo" } as any); const redo = await client.applyCommand({ type: "redo" } as any); const malformedTracks = opened.snapshot.nlaTracks.map((track: any) => ({ ...track, strips: track.strips.map((strip: any) => ({ ...strip, actionId: "action:missing" })) })); const malformed = await client.applyCommand({ type: "setNLAStack", objectId: ownerId, tracks: malformedTracks, baseRevision: redo.snapshot.revision } 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, ownerId, before, after, undo: stack(undo.snapshot), redo: stack(redo.snapshot), malformed, malformedRevisionPreserved: afterMalformed.snapshot.revision === redo.snapshot.revision, reopened: stack(reopened.snapshot), beforeRevision: opened.snapshot.revision, appliedRevision: applied.snapshot.revision, undoRevision: undo.snapshot.revision, redoRevision: redo.snapshot.revision, reopenedRevision: reopened.snapshot.revision, 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-P1112-000"), { recursive: true }); fs.writeFileSync(path.join(root, "tests/golden/WBV2-P1112-000/nla-stack-production.json"), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P1112-000", operation: "NLA_STACK_MAIN_CHROMIUM", browser: "chromium", queueMutation: false, ...result }, null, 2)}\n`); expect(result.error).toBeUndefined(); expect(result.fixtureSha256).toBe(fixtureSha256); expect(result.after).toBe(result.before); expect(result.appliedRevision).toBe(result.beforeRevision + 1); expect(result.undo).toBe(result.before); expect(result.redo).toBe(result.after); expect(result.malformed.code).not.toBe("NO_ERROR"); expect(result.malformedRevisionPreserved).toBe(true); expect(result.reopened).toBe(result.after); expect(result.reopenedRevision).toBe(1); expect(result.savedSha256).not.toBe(fixtureSha256); });