Files
workinf_Blender_Wasm/web/tests/e2e/b3-pack-openmainfile-probe.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

60 lines
3.3 KiB
TypeScript

import fs from "node:fs";
import path from "node:path";
import { test } from "@playwright/test";
import { NativeUIWorkflow, observeNative } from "../fixtures/native-ui-workflow";
const root = path.resolve(import.meta.dirname, "../../..");
const effects = path.join(root, "blender-5.2.0/tests/files/sequence_editing/effects");
const blend = fs.readFileSync(path.join(effects, "fx_comp.blend"));
const mask = fs.readFileSync(path.join(effects, "mask.png"));
test("probe open_mainfile by staged path then pack_all", async ({ page }, testInfo) => {
test.setTimeout(180_000);
await observeNative(page);
await page.goto("/");
const flow = new NativeUIWorkflow(page, testInfo.outputPath("cases"));
await flow.command(() => page.getByTestId("blend-file-input").setInputFiles(path.join(effects, "fx_comp.blend")));
const out = await page.evaluate(async (input) => {
const worker = (window as any).__nativeWorkflowEngine as Worker;
const send = (command: any) => new Promise<any>((resolve, reject) => {
const requestId = `omf-${crypto.randomUUID()}`;
const receive = (event: MessageEvent) => {
if (event.data?.requestId !== requestId || event.data?.kind !== 'result') return;
worker.removeEventListener('message', receive);
if (event.data.ok) resolve(event.data.result); else reject(new Error(`${event.data.error?.code ?? 'NATIVE'}: ${event.data.error?.message ?? JSON.stringify(event.data.error)}`));
};
worker.addEventListener('message', receive); worker.postMessage({ requestId, command });
});
const py = (source: string) => send({ type: 'jsonCommand', cmd: 'pythonExec', params: { source, filename: 'OpenByPath.py', console: false } });
const log: any = {};
try {
const stage = await py([
"import bpy, os, base64",
"root = '/browser/pack-case'",
"os.makedirs(root, exist_ok=True)",
"open(root + '/fx_comp.blend', 'wb').write(base64.b64decode('" + input.blend + "'))",
"open(root + '/mask.png', 'wb').write(base64.b64decode('" + input.mask + "'))",
"print('STAGED', sorted(os.listdir(root)))",
].join("\n"));
log.stageOutput = String(stage.json?.output ?? '').slice(0, 600);
const open = await py([
"import bpy, os",
"print('OPEN', bpy.ops.wm.open_mainfile(filepath='/browser/pack-case/fx_comp.blend', load_ui=False, use_scripts=False))",
"print('FILEPATH', repr(bpy.data.filepath))",
"print('ABS', bpy.path.abspath('//mask.png'), os.path.exists(bpy.path.abspath('//mask.png')))",
"print('BEFORE', [(i.name, i.packed_file is not None) for i in bpy.data.images])",
"print('PACK', bpy.ops.file.pack_all())",
"print('AFTER', [(i.name, i.packed_file is not None, i.packed_file.size if i.packed_file else None) for i in bpy.data.images])",
].join("\n"));
log.openOutput = String(open.json?.output ?? '').slice(0, 2500);
log.openState = open.json?.state;
log.openRevision = open.snapshot?.revision;
const after = await send({ type: 'snapshot' });
log.afterRevision = after.snapshot?.revision;
log.afterSceneId = after.snapshot?.sceneId;
} catch (e: any) { log.error = String(e?.message ?? e); }
return log;
}, { blend: blend.toString("base64"), mask: mask.toString("base64") });
fs.writeFileSync("/tmp/pack-openmainfile-probe.json", JSON.stringify(out, null, 2));
});