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/basic_scene.blend")); const fixtureSha256 = crypto.createHash("sha256").update(fixture).digest("hex"); test("WBV2-P1129-001 covers the remaining Scene settings Main commands", async ({ page }) => { test.setTimeout(180_000); await page.goto("/"); const result = await page.evaluate(async (bytes) => { const { WebEngineClient } = await import("/src/engine-client/WebEngineClient.ts"); const client = new WebEngineClient({ timeoutMs: 60_000 }); const reopenedClient = new WebEngineClient({ timeoutMs: 60_000 }); const digest = async (value: ArrayBuffer): Promise => { const hash = await crypto.subtle.digest("SHA-256", value); return Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, "0")).join(""); }; try { const opened = await client.openBlend(Uint8Array.from(bytes).buffer); const scene = opened.snapshot.scenes[0]; const layerName = scene?.viewLayers?.[0]?.name; const collectionId = scene?.rootCollectionId === "collection:Collection" ? "collection:Scene Collection" : "collection:Collection"; if (!scene || !layerName) throw new Error("basic scene has no Scene/ViewLayer settings"); const definitions: Array<{ type: string; dataId?: string; objectId?: string; lightgroup?: string | null; properties?: Record; layerName?: string; collectionId?: string; aovs?: Array<{ name: string; type: number }>; lightgroups?: string[] }> = [ { type: "setSceneProperties", properties: { exposure: 0.25 } }, { type: "setSceneRenderSettings", properties: { resolutionPercentage: 90 } }, { type: "setSceneAudioSettings", properties: { volume: 0.8 } }, { type: "setSceneUnitSettings", properties: { scaleLength: 1 } }, { type: "setSceneTimelineSettings", properties: { fps: 24 } }, { type: "setScenePipelineSettings", properties: { useCompositor: !scene.pipelineSettings.useCompositor } }, { type: "setSceneBindings", properties: { cameraObjectId: scene.cameraObjectId, worldId: scene.worldId } }, { type: "setSceneViewLayerSettings", layerName, properties: { useRender: !scene.viewLayers[0].useRender } }, { type: "setSceneCollectionSettings", layerName, collectionId: "collection:Collection", properties: { exclude: true } }, { type: "setSceneBorderSettings", properties: { enabled: true, minX: 0.1, maxX: 0.9, minY: 0.1, maxY: 0.9 } }, { type: "setSceneSimplifySettings", properties: { subsurfViewport: 5 } }, { type: "setSceneColorManagement", properties: { temperature: 6500 } }, { type: "setSceneImageFormat", properties: { fileType: "PNG" } }, { type: "setSceneMotionBlur", properties: { enabled: true } }, { type: "setSceneHairSettings", properties: { subdivisions: 1 } }, { type: "setSceneStampSettings", properties: { userText: "Web" } }, { type: "setSceneLineSettings", properties: { thickness: 2 } }, { type: "setSceneViewLayerPassSettings", layerName, properties: { alphaThreshold: 0.25 } }, { type: "setSceneViewLayerAOVs", layerName, aovs: [{ name: "WebAOV", type: 0 }] }, { type: "setSceneViewLayerLightgroups", layerName, lightgroups: ["WebLightGroup"] }, { type: "setObjectLightgroup", objectId: scene.cameraObjectId, lightgroup: "WebLightGroup" }, { type: "setWorldLightgroup", dataId: scene.worldId, lightgroup: "WebLightGroup" }, ]; const beforeRevision = opened.snapshot.revision; const revisions: number[] = []; for (const definition of definitions) { const payload = { ...definition } as any; if (!payload.dataId) payload.dataId = scene.id; const applied = await client.applyCommand(payload); revisions.push(applied.snapshot.revision); } const afterColorManagement = (await client.snapshot()).snapshot.scenes.find((candidate: any) => candidate.id === scene.id)?.colorManagement; const beforeMalformed = (await client.snapshot()).snapshot; const malformed = await client.applyCommand({ type: "setSceneImageFormat", dataId: scene.id, properties: { fileType: "NOT_A_FORMAT" } } as any).then(() => ({ code: "NO_ERROR" })).catch((error: any) => ({ code: error?.code, message: error?.message })); const afterMalformed = (await client.snapshot()).snapshot; const undo = await client.applyCommand({ type: "undo" } as any); const redo = await client.applyCommand({ type: "redo" } as any); const saved = await client.saveBlend(); const reopened = await reopenedClient.openBlend(saved.slice(0)); const reopenedScene = reopened.snapshot.scenes.find((candidate: any) => candidate.id === scene.id); return { browser: "chromium", beforeRevision, commandCount: definitions.length, revisions, afterColorManagement, malformed, malformedRevisionPreserved: afterMalformed.revision === beforeMalformed.revision, undoRevision: undo.snapshot.revision, redoRevision: redo.snapshot.revision, reopenedRevision: reopened.snapshot.revision, reopenedScene, savedSha256: await digest(saved), sourceSha256: await digest(Uint8Array.from(bytes).buffer) }; } catch (error: any) { return { error: { code: error?.code, message: error?.message, detail: String(error) } } as any; } finally { client.terminate(); reopenedClient.terminate(); } }, Array.from(fixture)); fs.mkdirSync(path.join(root, "tests/golden/WBV2-P1129-001"), { recursive: true }); fs.writeFileSync(path.join(root, "tests/golden/WBV2-P1129-001/scene-settings-expanded-production.json"), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P1129-001", operation: "SCENE_SETTINGS_EXPANDED_ENGINE_CHROMIUM", browser: "chromium", queueMutation: false, fixtureSha256, ...result }, null, 2)}\n`); expect(result.error).toBeUndefined(); expect(result.browser).toBe("chromium"); expect(result.sourceSha256).toBe(fixtureSha256); expect(result.revisions).toEqual(result.revisions.map((_, index) => result.beforeRevision + index + 1)); expect(result.commandCount).toBe(22); expect(result.malformed.code).not.toBe("NO_ERROR"); expect(result.malformedRevisionPreserved).toBe(true); expect(result.undoRevision).toBe(result.beforeRevision + 23); expect(result.redoRevision).toBe(result.beforeRevision + 24); expect(result.reopenedRevision).toBe(1); expect(result.reopenedScene?.renderSettings?.resolutionPercentage).toBe(90); expect(result.reopenedScene?.timelineSettings?.fps).toBe(24); expect(result.reopenedScene?.stampSettings?.userText).toBe("Web"); expect(result.savedSha256).not.toBe(fixtureSha256); });