Files
workinf_Blender_Wasm/web/tests/e2e/wbv2-scene-multiview-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

67 lines
3.9 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-P1131-001 binds scene multiview 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?.multiviewSettings) throw new Error("scene multiview settings are unavailable");
const beforeRevision = opened.snapshot.revision;
const before = scene.multiviewSettings;
const edited = await client.applyCommand({ type: "setSceneMultiviewSettings", dataId: scene.id, properties: { enabled: !before.enabled, viewsFormat: before.viewsFormat === 0 ? 1 : 0, imageViewsFormat: (before.imageViewsFormat + 1) % 3, stereoDisplayMode: (before.stereoDisplayMode + 1) % 5, interlaceSwap: !before.interlaceSwap } } as any);
const after = edited.snapshot.scenes[0].multiviewSettings;
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: "setSceneMultiviewSettings", dataId: scene.id, properties: { stereoDisplayMode: 99 } } 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, edited.snapshot.revision, undo.snapshot.revision, redo.snapshot.revision],
before,
after,
malformed,
malformedRevisionPreserved: afterMalformed.revision === beforeMalformed.revision,
reopened: reopenedScene.multiviewSettings,
exactSaveReopen: JSON.stringify(after) === JSON.stringify(reopenedScene.multiviewSettings),
savedSha256: await digest(saved),
};
} finally {
client.terminate();
reopened.terminate();
}
}, Array.from(fixture));
fs.mkdirSync(path.join(root, "tests/golden/WBV2-P1131-001"), { recursive: true });
fs.writeFileSync(path.join(root, "tests/golden/WBV2-P1131-001", "scene-multiview-production.json"), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P1131-001", operation: "SCENE_MULTIVIEW_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);
});