Files
workinf_Blender_Wasm/web/tests/e2e/wbv2-physics-manifest-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

59 lines
4.1 KiB
TypeScript

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/modifier_physics_scene.blend"));
const fixtureSha256 = crypto.createHash("sha256").update(fixture).digest("hex");
test("WBV2-P1117-000 preserves Physics manifest Main persistence and validation", 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 physics = (snapshot: any) => JSON.stringify(snapshot.physicsSimulation ?? { schemaVersion: 1, systems: [] });
let stage = "open";
try {
const opened = await client.openBlend(Uint8Array.from(input.bytes).buffer);
const manifest = { schemaVersion: 1, systems: [{ id: "physics:web-test", family: "RIGID_BODY", ownerObjectId: "object:PhysicsBuild", settingsHash: "a".repeat(64), settings: { mass: 1.5 }, dependencyIds: [] }] };
const before = physics(opened.snapshot);
stage = "apply";
const applied = await client.applyCommand({ type: "setPhysicsSimulation", manifest } as any);
const after = physics(applied.snapshot);
stage = "undo";
const undo = await client.applyCommand({ type: "undo" } as any);
stage = "redo";
const redo = await client.applyCommand({ type: "redo" } as any);
const malformedManifest = { ...manifest, systems: [{ ...manifest.systems[0], ownerObjectId: "object:missing" }] };
stage = "malformed";
const malformed = await client.applyCommand({ type: "setPhysicsSimulation", manifest: malformedManifest } as any).then(() => ({ code: "NO_ERROR" })).catch((error: any) => ({ code: error?.code, message: error?.message }));
stage = "snapshot-after-malformed";
const afterMalformed = await client.snapshot();
stage = "save";
const saved = await client.saveBlend();
stage = "reopen";
const reopened = await reopenedClient.openBlend(saved.slice(0));
return { fixtureSha256: input.fixtureSha256, manifest, systemCount: manifest.systems.length, before, after, undo: physics(undo.snapshot), redo: physics(redo.snapshot), malformed, malformedRevisionPreserved: afterMalformed.snapshot.revision === redo.snapshot.revision, reopened: physics(reopened.snapshot), revisions: [opened.snapshot.revision, applied.snapshot.revision, undo.snapshot.revision, 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), stage } } as any; }
finally { client.terminate(); reopenedClient.terminate(); }
}, { bytes: Array.from(fixture), fixtureSha256 });
fs.mkdirSync(path.join(root, "tests/golden/WBV2-P1117-000"), { recursive: true });
fs.writeFileSync(path.join(root, "tests/golden/WBV2-P1117-000/physics-manifest-production.json"), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P1117-000", operation: "PHYSICS_MANIFEST_MAIN_CHROMIUM", browser: "chromium", queueMutation: false, ...result }, null, 2)}\n`);
expect(result.error).toBeUndefined();
expect(result.fixtureSha256).toBe(fixtureSha256);
expect(result.systemCount).toBeGreaterThan(0);
expect(JSON.parse(result.after)).toEqual(result.manifest);
expect(result.revisions).toEqual([result.revisions[0], result.revisions[0] + 1, result.revisions[0] + 2, result.revisions[0] + 3]);
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);
});