Files
workinf_Blender_Wasm/web/tests/e2e/wbv2-material-image-production.spec.ts
mes123456 a078648297
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
feat(web): complete PBR shader, asset library and offscreen render chain
- generate a desktop-Blender PBR asset library and seed catalog v2 into OPFS
- add React asset browser, material preview sphere and Web PBR render panel
- extend shader graph/compiler to the finite 14-node set and native properties
- add image colour-space editing, scene-camera still rendering and asset repair
- add focused E2E/unit coverage and implementation status notes

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-11-11 14:59:43 +08:00

65 lines
5.4 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/attribute_scene.blend"));
const fixtureSha256 = crypto.createHash("sha256").update(fixture).digest("hex");
const pngBase64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M/wHwAF/gL+W7j8WQAAAABJRU5ErkJggg==";
test("WBV2-P1100-003 preserves imported Image and shader image-node links", async ({ page }) => {
test.setTimeout(180_000);
await page.goto("/?engine=manual");
const result = await page.evaluate(async (input) => {
const { WebEngineClient } = await import("/src/engine-client/WebEngineClient.ts");
const client = new WebEngineClient({ timeoutMs: 60_000 });
let reopenedClient: WebEngineClient | null = null;
const summary = (snapshot: any, imageId: string, materialId: string) => {
const image = snapshot.images?.find((entry: any) => entry.id === imageId);
const material = snapshot.materials?.find((entry: any) => entry.id === materialId);
if (!image || !material) throw new Error("imported image or material missing");
return { revision: snapshot.revision, image: { id: image.id, name: image.name, packed: image.packed, packedByteLength: image.packedByteLength }, nodes: material.nodes, links: material.links, imageIds: material.imageIds ?? [] };
};
try {
const opened = await client.openBlend(Uint8Array.from(input.bytes).buffer);
const material = opened.snapshot.materials?.[0];
if (!material) throw new Error("basic fixture has no material");
const imported = await client.applyCommand({ type: "importImage", name: "WebImportedImage", mimeType: "image/png", width: 1, height: 1, base64: input.pngBase64 } as any);
if (!imported.snapshot.materials?.some((candidate: any) => candidate.id === material.id)) throw Object.assign(new Error("importImage dropped the existing material from SceneIR"), { importedImageCount: imported.snapshot.images?.length, importedMaterialCount: imported.snapshot.materials?.length, importedRevision: imported.snapshot.revision });
const image = imported.snapshot.images?.find((entry: any) => entry.name === "WebImportedImage");
if (!image) throw new Error("importImage did not return an image");
const linked = await client.applyCommand({ type: "setMaterialImageNode", materialId: material.id, imageId: image.id, usage: "BASE_COLOR" } as any);
const afterLink = summary(linked.snapshot, image.id, material.id);
const undo = await client.applyCommand({ type: "undo" } as any);
const redo = await client.applyCommand({ type: "redo" } as any);
const malformed = await client.applyCommand({ type: "setMaterialImageNode", materialId: material.id, imageId: "image:missing", usage: "BASE_COLOR" } as any).then(() => ({ code: "NO_ERROR" })).catch((error: any) => ({ code: error?.code, message: error?.message }));
const afterMalformed = await client.snapshot();
const saved = await client.saveBlend();
client.terminate();
reopenedClient = new WebEngineClient({ timeoutMs: 60_000 });
const reopened = await reopenedClient.openBlend(saved.slice(0));
const afterReopen = summary(reopened.snapshot, image.id, material.id);
return { fixtureSha256: input.fixtureSha256, materialId: material.id, imageId: image.id, importedRevision: imported.snapshot.revision, linkedRevision: linked.snapshot.revision, afterLink, undo: summary(undo.snapshot, image.id, material.id), redo: summary(redo.snapshot, image.id, material.id), malformed, malformedRevisionPreserved: afterMalformed.snapshot.revision === redo.snapshot.revision, 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), importedImageCount: error?.importedImageCount, importedMaterialCount: error?.importedMaterialCount, importedRevision: error?.importedRevision } } as any; }
finally { client.terminate(); reopenedClient?.terminate(); }
}, { bytes: Array.from(fixture), fixtureSha256, pngBase64 });
fs.mkdirSync(path.join(root, "tests/golden/WBV2-P1100-003"), { recursive: true });
fs.writeFileSync(path.join(root, "tests/golden/WBV2-P1100-003/material-image-production.json"), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P1100-003", operation: "MATERIAL_IMAGE_MAIN_CHROMIUM", browser: "chromium", queueMutation: false, ...result }, null, 2)}\n`);
expect(result.error).toBeUndefined();
expect(result.fixtureSha256).toBe(fixtureSha256);
expect(result.importedRevision).toBeGreaterThan(1);
expect(result.linkedRevision).toBe(result.importedRevision + 1);
expect(result.afterLink.image.packed).toBe(true);
expect(result.afterLink.nodes.some((node: any) => node.type === "IMAGE_TEXTURE")).toBe(true);
expect(result.afterLink.links.length).toBeGreaterThan(0);
expect(result.malformed.code).not.toBe("NO_ERROR");
expect(result.malformedRevisionPreserved).toBe(true);
expect(result.afterReopen.image.packed).toBe(true);
expect(result.afterReopen.nodes).toEqual(result.afterLink.nodes);
expect(result.afterReopen.links).toEqual(result.afterLink.links);
expect(result.afterReopen.revision).toBe(1);
expect(result.savedSha256).not.toBe(fixtureSha256);
});