chore(web): continuous handoff WBV2-P1287-001
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

This commit is contained in:
mes123456
2026-09-05 06:18:51 +08:00
parent c774935592
commit 67212a2c32
13 changed files with 31913 additions and 4 deletions

View File

@@ -0,0 +1,53 @@
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 fixturePath = process.env.WBV2_BATCH_FIXTURE ?? "tests/files/web/basic_scene.blend";
const fixture = fs.readFileSync(path.join(root, fixturePath));
const fixtureSha256 = crypto.createHash("sha256").update(fixture).digest("hex");
const task = process.env.WBV2_BATCH_TASK ?? "WBV2-P1100-003";
const productionPath = process.env.WBV2_BATCH_PRODUCTION ?? `tests/golden/${task}/material-slot-production.json`;
const sourceUnits = JSON.parse(process.env.WBV2_BATCH_UNITS ?? "[\"operator:OBJECT_OT_material_slot_add\"]") as string[];
test("WBV2-P1100-003 preserves addMaterialSlot through Main 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 materialNames = (snapshot: any) => snapshot.materials.map((material: any) => material.name);
try {
const opened = await client.openBlend(Uint8Array.from(input.bytes).buffer);
const object = opened.snapshot.nodes.find((node: any) => node.type === "MESH");
if (!object) throw new Error("basic scene has no mesh object");
const before = materialNames(opened.snapshot);
const added = await client.applyCommand({ type: "addMaterialSlot", objectId: object.id, name: "WebSlotMaterial" } as any);
const afterAdd = materialNames(added.snapshot);
const undo = await client.applyCommand({ type: "undo" } as any);
const redo = await client.applyCommand({ type: "redo" } as any);
const malformed = await client.applyCommand({ type: "addMaterialSlot", objectId: "object:missing", name: "Bad" } as any).then(() => ({ code: "NO_ERROR" })).catch((error: any) => ({ code: error?.code, message: error?.message }));
const afterMalformed = await client.snapshot();
const saved = await client.saveBlend();
const reopened = await reopenedClient.openBlend(saved.slice(0));
return { fixtureSha256: input.fixtureSha256, objectId: object.id, before, afterAdd, undo: materialNames(undo.snapshot), redo: materialNames(redo.snapshot), malformed, malformedRevisionPreserved: afterMalformed.snapshot.revision === redo.snapshot.revision, reopened: materialNames(reopened.snapshot), beforeRevision: opened.snapshot.revision, addRevision: added.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.dirname(path.join(root, productionPath)), { recursive: true });
fs.writeFileSync(path.join(root, productionPath), `${JSON.stringify({ schemaVersion: 1, task, operation: "MATERIAL_SLOT_MAIN_CHROMIUM", browser: "chromium", queueMutation: false, fixture: fixturePath, fixtureSha256, sourceUnits, ...result }, null, 2)}\n`);
expect(result.error).toBeUndefined();
expect(result.fixtureSha256).toBe(fixtureSha256);
expect(result.afterAdd).toContain("WebSlotMaterial");
expect(result.addRevision).toBe(result.beforeRevision + 1);
expect(result.undo).toEqual(result.before);
expect(result.redo).toEqual(result.afterAdd);
expect(result.malformed.code).not.toBe("NO_ERROR");
expect(result.malformedRevisionPreserved).toBe(true);
expect(result.reopened).toEqual(result.afterAdd);
expect(result.reopenedRevision).toBe(1);
expect(result.savedSha256).not.toBe(fixtureSha256);
});