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>
70 lines
3.7 KiB
TypeScript
70 lines
3.7 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 diffs to owning ID with corrected parsing", 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 = `m2-${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: 'M2.py', console: false } });
|
|
await py("import bpy\nbpy.context.scene['probe_marker']='m1'");
|
|
const a = new Uint8Array((await send({ type: 'saveBlend' })).blend as ArrayBuffer);
|
|
await send({ type: 'jsonCommand', cmd: 'pythonReset', params: {} });
|
|
const b = new Uint8Array((await send({ type: 'saveBlend' })).blend as ArrayBuffer);
|
|
const view = new DataView(a.buffer, a.byteOffset, a.byteLength);
|
|
const blockCodes: Array<{ code: string; start: number; len: number }> = [];
|
|
let offset = 12;
|
|
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);
|
|
blockCodes.push({ code, start: offset, len });
|
|
offset += 20 + len;
|
|
if (code === 'ENDB' || len <= 0) break;
|
|
}
|
|
// Owner = the most recent ID block (code "ID") whose 2-char type + 64-char name precede the offset.
|
|
const ownerOf = (pos: number) => {
|
|
let owner = '(none)';
|
|
for (const blk of blockCodes) {
|
|
if (blk.start > pos) break;
|
|
if (blk.code === 'ID' && blk.start + 20 + 66 <= a.byteLength) {
|
|
const type = String.fromCharCode(a[blk.start + 20], a[blk.start + 21]);
|
|
const raw = new TextDecoder().decode(a.subarray(blk.start + 22, blk.start + 88)).replace(/\0.*$/s, '');
|
|
owner = `${type}:${raw}`;
|
|
}
|
|
}
|
|
return owner;
|
|
};
|
|
const diffs: Array<Record<string, unknown>> = [];
|
|
const limit = Math.min(a.byteLength, b.byteLength);
|
|
let i = 0;
|
|
while (i < limit && diffs.length < 40) {
|
|
if (a[i] !== b[i]) {
|
|
let j = i;
|
|
while (j < limit && a[j] !== b[j]) j++;
|
|
const hex = (arr: Uint8Array) => Array.from(arr.subarray(i, Math.min(j, i + 24))).map((v) => v.toString(16).padStart(2, '0')).join(' ');
|
|
diffs.push({ runStart: i, runLen: j - i, owner: ownerOf(i), a: hex(a), b: hex(b) });
|
|
i = j;
|
|
} else i++;
|
|
}
|
|
return { lenA: a.byteLength, lenB: b.byteLength, diffs };
|
|
});
|
|
fs.writeFileSync("/tmp/reset-diff2.json", JSON.stringify(out, null, 2));
|
|
});
|