Files
workinf_Blender_Wasm/web/tests/e2e/wbv2-material-face-slot-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

62 lines
4.7 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/basic_scene.blend"));
const fixtureSha256 = crypto.createHash("sha256").update(fixture).digest("hex");
test("WBV2-P1100-003 preserves material face assignment and slot removal", 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 meshState = (snapshot: any, meshId: string) => {
const mesh = snapshot.meshes?.find((entry: any) => entry.id === meshId);
if (!mesh) throw new Error(`mesh missing: ${meshId}`);
return { revision: snapshot.revision, slots: mesh.materialSlotIds ?? [], triangleMaterialIndices: [...(mesh.triangleMaterialIndices ?? [])] };
};
try {
const opened = await client.openBlend(Uint8Array.from(input.bytes).buffer);
const object = opened.snapshot.nodes?.find((node: any) => node.type === "MESH");
if (!object?.dataId) throw new Error("basic fixture has no mesh object");
const meshId = object.dataId as string;
const before = meshState(opened.snapshot, meshId);
const added = await client.applyCommand({ type: "addMaterialSlot", objectId: object.id, name: "WebFaceMaterial" } as any);
const addedSecond = await client.applyCommand({ type: "addMaterialSlot", objectId: object.id, name: "WebFaceMaterialSecond" } as any);
const afterAdd = meshState(addedSecond.snapshot, meshId);
const assigned = await client.applyCommand({ type: "assignMaterialFaces", meshId, faceIndices: [0, 1], slotIndex: 1 } as any);
const afterAssign = meshState(assigned.snapshot, meshId);
const removed = await client.applyCommand({ type: "removeMaterialSlot", objectId: object.id, slotIndex: 1 } as any);
const afterRemove = meshState(removed.snapshot, meshId);
const undo = await client.applyCommand({ type: "undo" } as any);
const redo = await client.applyCommand({ type: "redo" } as any);
const malformed = await client.applyCommand({ type: "assignMaterialFaces", meshId, faceIndices: [999], slotIndex: 0 } as any).then(() => ({ code: "NO_ERROR" })).catch((error: any) => ({ code: error?.code, message: error?.message }));
const afterMalformed = meshState((await client.snapshot()).snapshot, meshId);
const saved = await client.saveBlend();
const reopened = await reopenedClient.openBlend(saved.slice(0));
const afterReopen = meshState(reopened.snapshot, meshId);
return { fixtureSha256: input.fixtureSha256, meshId, before, afterAdd, afterAssign, afterRemove, undo: meshState(undo.snapshot, meshId), redo: meshState(redo.snapshot, meshId), malformed, afterMalformed, afterReopen, 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) } } as any; }
finally { client.terminate(); reopenedClient.terminate(); }
}, { bytes: Array.from(fixture), fixtureSha256 });
fs.mkdirSync(path.join(root, "tests/golden/WBV2-P1100-003"), { recursive: true });
fs.writeFileSync(path.join(root, "tests/golden/WBV2-P1100-003/material-face-slot-production.json"), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P1100-003", operation: "MATERIAL_FACE_SLOT_MAIN_CHROMIUM", browser: "chromium", queueMutation: false, sourceRnaStructs: { "rna-struct:MaterialSlot": "mesh.materialSlotIds", "rna-struct:MeshPolygon": "mesh.triangleMaterialIndices" }, ...result }, null, 2)}\n`);
expect(result.error).toBeUndefined();
expect(result.fixtureSha256).toBe(fixtureSha256);
expect(result.afterAdd.slots.length).toBe(result.before.slots.length + 2);
expect(result.afterAssign.slots).toEqual(result.afterAdd.slots);
expect(result.afterAssign.revision).toBe(result.afterAdd.revision + 1);
expect(result.afterRemove.slots).toEqual(result.afterAdd.slots.slice(0, 1));
expect(result.undo.slots.length).toBe(result.afterAssign.slots.length);
expect(result.redo.slots).toEqual(result.afterRemove.slots);
expect(result.malformed.code).not.toBe("NO_ERROR");
expect(result.afterMalformed).toEqual(result.redo);
expect(result.afterReopen).toEqual({ ...result.afterRemove, revision: 1 });
expect(result.savedSha256).not.toBe(fixtureSha256);
});