Files
workinf_Blender_Wasm/web/tests/e2e/b3-reset-diff-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

67 lines
3.8 KiB
TypeScript

import fs from "node:fs";
import path from "node:path";
import { test, expect } from "@playwright/test";
import { NativeUIWorkflow, observeNative } from "../fixtures/native-ui-workflow";
const root = path.resolve(import.meta.dirname, "../../..");
test("map reset byte diffs to owning ID and check session uids", async ({ page }, testInfo) => {
test.setTimeout(240_000);
await observeNative(page);
await page.goto("/");
await page.getByTestId("blend-file-input").setInputFiles(path.join(root, "blender-5.2.0/tests/files/sequence_editing/effects/fx_comp.blend"));
await expect.poll(async () => page.locator("main.blender-app").evaluate((n) => (n as HTMLElement).dataset.projectId), { timeout: 60000 }).toBe("fx_comp");
await expect(page.getByTestId("engine-status")).toContainText("SceneIR", { timeout: 60000 });
const out = await page.evaluate(async () => {
const worker = (window as any).__nativeWorkflowEngine as Worker;
const send = (command: any) => new Promise<any>((resolve, reject) => {
const requestId = `md-${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}: ${event.data.error?.message}`));
};
worker.addEventListener('message', receive); worker.postMessage({ requestId, command });
});
const py = (source: string) => send({ type: 'jsonCommand', cmd: 'pythonExec', params: { source, filename: 'Md.py', console: false } });
const uidProbe = "import bpy\nimport json\nprint('UIDS', json.dumps({'objects': [(o.name, o.session_uid) for o in bpy.data.objects], 'images': [(i.name, i.session_uid) for i in bpy.data.images], 'scenes': [(s.name, s.session_uid) for s in bpy.data.scenes]}))";
const uidText = async () => String((await py(uidProbe)).json?.output ?? '').split('UIDS ')[1]?.trim() ?? '';
await py("import bpy\nbpy.context.scene['probe_marker']='m1'");
const uidsBefore = await uidText();
const a = new Uint8Array((await send({ type: 'saveBlend' })).blend as ArrayBuffer);
await send({ type: 'jsonCommand', cmd: 'pythonReset', params: {} });
const uidsAfter = await uidText();
const b = new Uint8Array((await send({ type: 'saveBlend' })).blend as ArrayBuffer);
const blocks: Array<{ code: string; start: number; len: number; id?: string }> = [];
const view = new DataView(a.buffer, a.byteOffset, a.byteLength);
let offset = 12, lastId = '(none)';
while (offset + 20 <= a.byteLength) {
const code = String.fromCharCode(a[offset], a[offset + 1], a[offset + 2], a[offset + 3]);
const len = view.getInt32(offset + 4, true);
let id: string | undefined;
if (code === 'ID' && offset + 20 + 66 <= a.byteLength) {
const raw = new TextDecoder().decode(a.subarray(offset + 22, offset + 86));
lastId = raw.replace(/\0.*$/s, '');
id = lastId;
}
blocks.push({ code, start: offset, len, id });
offset += 20 + len;
if (code === 'ENDB' || len <= 0) break;
}
const nameOf = (pos: number) => {
let owner = '(none)', block = 'header';
for (const blk of blocks) {
if (blk.start > pos) break;
block = `${blk.code}@${blk.start}+${blk.len}`;
if (blk.id !== undefined) owner = blk.id;
}
return { block, owner };
};
const diffs: Array<Record<string, unknown>> = [];
const limit = Math.min(a.byteLength, b.byteLength);
for (let i = 0; i < limit && diffs.length < 10; i++) if (a[i] !== b[i]) diffs.push({ offset: i, a: a[i], b: b[i], ...nameOf(i) });
return { lenA: a.byteLength, lenB: b.byteLength, diffs, uidsBefore, uidsAfter };
});
fs.writeFileSync("/tmp/reset-diff.json", JSON.stringify(out, null, 2));
});