import fs from "node:fs"; import path from "node:path"; import { test, expect } from "@playwright/test"; import { NativeUIWorkflow, observeNative } from "../fixtures/native-ui-workflow"; const root = path.resolve(import.meta.dirname, "../../.."); test("compare SceneIR and bytes across repeated pythonReset", async ({ page }, testInfo) => { test.setTimeout(240_000); await observeNative(page); await page.goto("/"); await page.getByTestId("blend-file-input").setInputFiles(path.join(root, "blender-5.2.0/tests/files/sequence_editing/effects/fx_comp.blend")); await expect.poll(async () => page.locator("main.blender-app").evaluate((n) => (n as HTMLElement).dataset.projectId), { timeout: 60000 }).toBe("fx_comp"); await expect(page.getByTestId("engine-status")).toContainText("SceneIR", { timeout: 60000 }); const out = await page.evaluate(async () => { const worker = (window as any).__nativeWorkflowEngine as Worker; const send = (command: any) => new Promise((resolve, reject) => { const requestId = `sem-${crypto.randomUUID()}`; const receive = (event: MessageEvent) => { if (event.data?.requestId !== requestId || event.data?.kind !== 'result') return; worker.removeEventListener('message', receive); if (event.data.ok) resolve(event.data.result); else reject(new Error(`${event.data.error?.code}: ${event.data.error?.message}`)); }; worker.addEventListener('message', receive); worker.postMessage({ requestId, command }); }); const digestBytes = (buf: ArrayBuffer) => crypto.subtle.digest('SHA-256', buf).then((h) => Array.from(new Uint8Array(h), (b) => b.toString(16).padStart(2, '0')).join('').slice(0, 16)); const digestJson = (value: unknown) => crypto.subtle.digest('SHA-256', new TextEncoder().encode(JSON.stringify(value))).then((h) => Array.from(new Uint8Array(h), (b) => b.toString(16).padStart(2, '0')).join('').slice(0, 16)); const snapshotDigest = async () => { const s = (await send({ type: 'snapshot' })).snapshot; const { revision, ...rest } = s as Record; return { revision, digest: await digestJson(rest) }; }; const log: any = {}; log.snapA = await snapshotDigest(); log.bytesA = await digestBytes((await send({ type: 'saveBlend' })).blend as ArrayBuffer); await send({ type: 'jsonCommand', cmd: 'pythonReset', params: {} }); log.snapB = await snapshotDigest(); log.bytesB = await digestBytes((await send({ type: 'saveBlend' })).blend as ArrayBuffer); await send({ type: 'jsonCommand', cmd: 'pythonReset', params: {} }); log.snapC = await snapshotDigest(); log.bytesC = await digestBytes((await send({ type: 'saveBlend' })).blend as ArrayBuffer); await send({ type: 'jsonCommand', cmd: 'pythonReset', params: {} }); log.bytesD = await digestBytes((await send({ type: 'saveBlend' })).blend as ArrayBuffer); return log; }); fs.writeFileSync("/tmp/reset-semantic.json", JSON.stringify(out, null, 2)); });