Files
workinf_Blender_Wasm/web/tests/e2e/wbv2-grease-pencil-strokes-production.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

56 lines
4.8 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/modifier_grease_pencil_scene.blend"));
const fixtureSha256 = crypto.createHash("sha256").update(fixture).digest("hex");
test("WBV2-P1114-000 preserves Grease Pencil stroke edits through recovery and reopen", async ({ page }) => {
test.setTimeout(180_000);
await page.goto("/");
const result = await page.evaluate(async (input) => {
const { WebEngineClient } = await import("/src/engine-client/WebEngineClient.ts");
const client = new WebEngineClient({ timeoutMs: 60_000 });
const reopenedClient = new WebEngineClient({ timeoutMs: 60_000 });
const point = (snapshot: any, dataId: string, layerId: string, frame: number) => snapshot.greasePencils?.find((candidate: any) => candidate.id === dataId)?.layers.find((layer: any) => layer.id === layerId)?.frames.find((candidate: any) => candidate.frame === frame)?.drawing.strokes?.[0]?.points?.[0];
try {
const opened = await client.openBlend(Uint8Array.from(input.bytes).buffer);
const data = opened.snapshot.greasePencils?.[0];
const layer = data?.layers?.[0];
const drawingFrame = layer?.frames?.[0];
if (!data || !layer || !drawingFrame) throw new Error("Grease Pencil fixture is incomplete");
const strokes = drawingFrame.drawing.strokes.map((stroke: any, strokeIndex: number) => ({ cyclic: stroke.cyclic, materialIndex: stroke.materialIndex, points: (stroke.points ?? []).map((item: any, pointIndex: number) => ({ ...item, position: strokeIndex === 0 && pointIndex === 0 ? [item.position[0] + 0.25, item.position[1], item.position[2]] : [...item.position] })) }));
const before = point(opened.snapshot, data.id, layer.id, drawingFrame.frame);
const edited = await client.applyCommand({ type: "setGreasePencilStrokes", dataId: data.id, layerId: layer.id, frame: drawingFrame.frame, baseRevision: opened.snapshot.revision, strokes } as any);
const afterEdit = point(edited.snapshot, data.id, layer.id, drawingFrame.frame);
const undo = await client.applyCommand({ type: "undo" } as any);
const afterUndo = point(undo.snapshot, data.id, layer.id, drawingFrame.frame);
const redo = await client.applyCommand({ type: "redo" } as any);
const afterRedo = point(redo.snapshot, data.id, layer.id, drawingFrame.frame);
const malformed = await client.applyCommand({ type: "setGreasePencilStrokes", dataId: data.id, layerId: layer.id, frame: -1, baseRevision: redo.snapshot.revision, strokes } as any).then(() => ({ code: "NO_ERROR" })).catch((error: any) => ({ code: error?.code, message: error?.message }));
const afterMalformed = (await client.snapshot()).snapshot;
const saved = await client.saveBlend();
const reopened = await reopenedClient.openBlend(saved.slice(0));
const afterReopen = point(reopened.snapshot, data.id, layer.id, drawingFrame.frame);
return { fixtureSha256: input.fixtureSha256, dataId: data.id, layerId: layer.id, frame: drawingFrame.frame, before, afterEdit, afterUndo, afterRedo, malformed, malformedRevisionPreserved: afterMalformed.revision === redo.snapshot.revision, afterReopen, editRevision: edited.snapshot.revision, undoRevision: undo.snapshot.revision, redoRevision: redo.snapshot.revision, reopenedRevision: reopened.snapshot.revision, 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) } } as any; }
finally { client.terminate(); reopenedClient.terminate(); }
}, { bytes: Array.from(fixture), fixtureSha256 });
fs.mkdirSync(path.join(root, "tests/golden/WBV2-P1114-000"), { recursive: true });
fs.writeFileSync(path.join(root, "tests/golden/WBV2-P1114-000/grease-pencil-strokes-production.json"), `${JSON.stringify({ schemaVersion: 1, task: "WBV2-P1114-000", operation: "GREASE_PENCIL_STROKES_MAIN_CHROMIUM", browser: "chromium", queueMutation: false, ...result }, null, 2)}\n`);
expect(result.error).toBeUndefined();
expect(result.fixtureSha256).toBe(fixtureSha256);
expect(result.editRevision).toBeGreaterThan(0);
expect(result.afterEdit.position[0]).toBeCloseTo(result.before.position[0] + 0.25, 5);
expect(result.afterUndo.position).toEqual(result.before.position);
expect(result.afterRedo.position).toEqual(result.afterEdit.position);
expect(result.malformed.code).not.toBe("NO_ERROR");
expect(result.malformedRevisionPreserved).toBe(true);
expect(result.afterReopen.position).toEqual(result.afterRedo.position);
expect(result.reopenedRevision).toBe(1);
expect(result.savedSha256).not.toBe(fixtureSha256);
});