Files
workinf_Blender_Wasm/web/tests/e2e/geometry-node-allowlist.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

76 lines
3.8 KiB
TypeScript

import { expect, test } from "@playwright/test";
import fs from "node:fs";
import path from "node:path";
const root = path.resolve(import.meta.dirname, "../../..");
const expected = JSON.parse(fs.readFileSync(
path.join(root, "tests/golden/M10-02/geometry-node-allowlist.json"),
"utf8",
));
const blendBytes = fs.readFileSync(path.join(root, expected.fixture));
test("M10-02 blocks non-allowlisted Main nodes without replacing the preserved graph", async ({ page }) => {
test.setTimeout(120_000);
expect((await import("node:crypto")).createHash("sha256").update(blendBytes).digest("hex"))
.toBe(expected.fixtureSha256);
await page.goto("/");
const result = await page.evaluate(async ({ bytes, expected }) => {
const { WebEngineClient } = await import("/src/engine-client/WebEngineClient.ts");
const source = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) as ArrayBuffer;
const client = new WebEngineClient({ timeoutMs: 60_000 });
await client.init();
const opened = await client.openBlend(source);
const supported = opened.snapshot.geometryNodeGraphs?.find((graph) => graph.name === expected.supportedGraph);
const unsupported = opened.snapshot.geometryNodeGraphs?.find((graph) => graph.name === expected.unsupportedGraph);
const meshId = opened.snapshot.meshes[0]?.id ?? "mesh:missing";
if (!supported || !unsupported) throw new Error("Geometry Node allowlist fixture graphs are missing");
const baseline = JSON.stringify(opened.snapshot.geometryNodeGraphs);
const revision = opened.snapshot.revision;
const unsupportedTypes = unsupported.nodes
.filter((node) => !expected.allowlist.includes(node.type))
.map((node) => node.type);
const attempt = async (graph: typeof supported) => {
try {
await client.applyCommand({ type: "setGeometryNodeGraph", meshId, graph });
return null;
}
catch (error) {
return error as { code?: string; message?: string };
}
};
const unsupportedError = await attempt(unsupported);
const afterUnsupported = await client.snapshot();
const supportedError = await attempt(supported);
const afterSupported = await client.snapshot();
const saved = await client.saveBlend();
const reopened = await client.openBlend(saved);
const graphShape = (snapshot: typeof opened.snapshot) => snapshot.geometryNodeGraphs
?.find((graph) => graph.name === supported.name)?.nodes.map((node) => node.type).sort();
client.terminate();
return {
unsupportedTypes,
unsupportedErrorCode: unsupportedError?.code,
supportedErrorCode: supportedError?.code,
unsupportedPreserved: JSON.stringify(afterUnsupported.snapshot.geometryNodeGraphs) === baseline,
supportedNodes: graphShape(afterSupported.snapshot),
reopenedNodes: graphShape(reopened.snapshot),
expectedSupportedNodes: supported.nodes.map((node) => node.type).sort(),
revisions: [revision, afterUnsupported.snapshot.revision, afterSupported.snapshot.revision],
graphHashes: [unsupported.graphHash, afterUnsupported.snapshot.geometryNodeGraphs?.find((graph) => graph.name === expected.unsupportedGraph)?.graphHash],
};
}, { bytes: new Uint8Array(blendBytes), expected });
expect(result).toEqual({
unsupportedTypes: expected.unsupportedNodeTypes,
unsupportedErrorCode: expected.unsupportedErrorCode,
supportedErrorCode: undefined,
unsupportedPreserved: true,
supportedNodes: result.expectedSupportedNodes,
reopenedNodes: result.expectedSupportedNodes,
expectedSupportedNodes: result.expectedSupportedNodes,
revisions: [result.revisions[0], result.revisions[0], result.revisions[0] + 1],
graphHashes: [result.graphHashes[0], result.graphHashes[0]],
});
expect(result.graphHashes[0]).toMatch(/^[0-9a-f]{64}$/);
});