Files
workinf_Blender_Wasm/web/tests/e2e/wbv2-scene-settings-production.spec.ts
mes123456 f3e21c6b98
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
chore: checkpoint web Blender migration source, tools and docs
Accumulated uncommitted work: GHOST Web backend, WebGL/GPU web layer,
web workflow engine and protocol, tooling, docs and task records.
Large generated evidence, user-testing archives, build snapshots and
imported test assets remain untracked.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-10 11:18:01 +08:00

69 lines
5.0 KiB
TypeScript

import { expect, test } from "@playwright/test";
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
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 binds scene compositor, performance and sampling settings to Main", async ({ page }) => {
test.setTimeout(120_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: 30_000 });
const reopened = new WebEngineClient({ timeoutMs: 30_000 });
const shape = (error: any) => ({ code: error?.code, message: error?.message });
const digest = async (value: ArrayBuffer): Promise<string> => {
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];
if (!scene?.compositorSettings || !scene.performanceSettings || !scene.samplingSettings) throw new Error("scene settings are unavailable");
const beforeRevision = opened.snapshot.revision;
const before = { compositor: scene.compositorSettings, performance: scene.performanceSettings, sampling: scene.samplingSettings };
const compositor = await client.applyCommand({ type: "setSceneCompositorSettings", dataId: scene.id, properties: { device: scene.compositorSettings.device === 0 ? 1 : 0, precision: scene.compositorSettings.precision === 0 ? 1 : 0 } } as any);
const performance = await client.applyCommand({ type: "setScenePerformanceSettings", dataId: scene.id, properties: { fixedThreads: !scene.performanceSettings.fixedThreads, threads: Math.min(1024, Math.max(1, scene.performanceSettings.threads + 1)), persistentData: !scene.performanceSettings.persistentData } } as any);
const sampling = await client.applyCommand({ type: "setSceneSamplingSettings", dataId: scene.id, properties: { filterSize: Math.min(100, scene.samplingSettings.filterSize + 0.25), dither: Math.min(100, scene.samplingSettings.dither + 0.1), pixelAspectX: scene.samplingSettings.pixelAspectX === 1 ? 2 : 1 } } as any);
const after = { compositor: sampling.snapshot.scenes[0].compositorSettings, performance: sampling.snapshot.scenes[0].performanceSettings, sampling: sampling.snapshot.scenes[0].samplingSettings };
const undo = await client.applyCommand({ type: "undo" });
const redo = await client.applyCommand({ type: "redo" });
const beforeMalformed = (await client.snapshot()).snapshot;
const malformed = await client.applyCommand({ type: "setSceneSamplingSettings", dataId: scene.id, properties: { filterSize: -1 } } as any).then(() => ({ code: "NO_ERROR" })).catch(shape);
const afterMalformed = (await client.snapshot()).snapshot;
const saved = await client.saveBlend();
const reopenedResult = await reopened.openBlend(saved.slice(0));
const reopenedScene = reopenedResult.snapshot.scenes.find((candidate) => candidate.id === scene.id)!;
return {
browser: "chromium",
sourceSha256: await digest(Uint8Array.from(bytes).buffer),
beforeRevision,
revisions: [beforeRevision, compositor.snapshot.revision, performance.snapshot.revision, sampling.snapshot.revision, undo.snapshot.revision, redo.snapshot.revision],
before,
after,
malformed,
malformedRevisionPreserved: afterMalformed.revision === beforeMalformed.revision,
reopened: { compositor: reopenedScene.compositorSettings, performance: reopenedScene.performanceSettings, sampling: reopenedScene.samplingSettings },
exactSaveReopen: JSON.stringify(after) === JSON.stringify({ compositor: reopenedScene.compositorSettings, performance: reopenedScene.performanceSettings, sampling: reopenedScene.samplingSettings }),
savedSha256: await digest(saved),
};
} finally {
client.terminate();
reopened.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-production.json"), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P1129-001", operation: "SCENE_SETTINGS_ENGINE_CHROMIUM", queueMutation: false, fixtureSha256, ...result }, null, 2)}\n`);
expect(result.browser).toBe("chromium");
expect(result.sourceSha256).toBe(fixtureSha256);
expect(result.revisions).toEqual(result.revisions.map((_, index) => result.beforeRevision + index));
expect(result.malformed.code).not.toBe("NO_ERROR");
expect(result.malformedRevisionPreserved).toBe(true);
expect(result.exactSaveReopen).toBe(true);
expect(result.savedSha256).not.toBe(fixtureSha256);
});