fix(web): close unattended operator authorization loop
This commit is contained in:
@@ -440,6 +440,7 @@ PREFERRED_BATCHES = [
|
||||
# command gate and fixture; no recipe is allowed to infer coverage from a
|
||||
# source filename alone.
|
||||
AUTO_OPERATOR_RECIPES = [
|
||||
{"moduleId": "OBJECT_MATERIAL_SLOT_ASSIGN_OPERATOR_BATCH", "title": "verify material slot assign operator through native Main", "owner": "OBJECT", "identifier": "OBJECT_OT_material_slot_assign", "fixture": "tests/files/web/basic_scene.blend", "test": "web/tests/e2e/wbv2-material-slot-assign-batch-production.spec.ts", "production": "tests/golden/{task}/material-slot-assign-production.json", "operation": "MATERIAL_SLOT_ASSIGN"},
|
||||
{"moduleId": "OBJECT_MATERIAL_SLOT_REMOVE_OPERATOR_BATCH", "title": "verify material slot remove operator through native Main", "owner": "OBJECT", "identifier": "OBJECT_OT_material_slot_remove", "fixture": "tests/files/web/basic_scene.blend", "test": "web/tests/e2e/wbv2-material-slot-production.spec.ts", "production": "tests/golden/{task}/material-slot-production.json", "operation": "MATERIAL_SLOT_REMOVE", "slotOperation": "REMOVE"},
|
||||
{"moduleId": "MESH_DECIMATE_OPERATOR_BATCH", "title": "verify mesh decimate operator through native Main", "owner": "MESH", "identifier": "MESH_OT_decimate", "fixture": "tests/files/web/generated/WBV2-P4-001-MODIFIER.DECLARED_SLICES.blend", "test": "web/tests/e2e/wbv2-modifier-parameter-production.spec.ts", "production": "tests/golden/{task}/modifier-parameter-production.json", "operation": "DECIMATE"},
|
||||
{"moduleId": "OBJECT_MATERIAL_SLOT_ADD_OPERATOR_BATCH", "title": "verify material slot add operator through native Main", "owner": "OBJECT", "identifier": "OBJECT_OT_material_slot_add", "fixture": "tests/files/web/basic_scene.blend", "test": "web/tests/e2e/wbv2-material-slot-production.spec.ts", "production": "tests/golden/{task}/material-slot-production.json", "operation": "MATERIAL_SLOT_ADD"},
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
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-MATERIAL-SLOT-ASSIGN";
|
||||
const productionPath = process.env.WBV2_BATCH_PRODUCTION ?? `tests/golden/${task}/material-slot-assign-production.json`;
|
||||
const sourceUnits = JSON.parse(process.env.WBV2_BATCH_UNITS ?? "[\"operator:OBJECT_OT_material_slot_assign\"]") as string[];
|
||||
|
||||
test("native material slot assign batch preserves Main recovery semantics", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
const result = await page.evaluate(async (bytes) => {
|
||||
const { WebEngineClient } = await import("/src/engine-client/WebEngineClient.ts");
|
||||
const client = new WebEngineClient({ timeoutMs: 60_000 });
|
||||
const reopened = new WebEngineClient({ timeoutMs: 60_000 });
|
||||
const shape = (error: any) => ({ code: error?.code, message: error?.message });
|
||||
try {
|
||||
const opened = await client.openBlend(Uint8Array.from(bytes).buffer);
|
||||
const object: any = opened.snapshot.nodes.find((node: any) => node.type === "MESH");
|
||||
const mesh: any = object && opened.snapshot.meshes.find((candidate: any) => candidate.id === object.dataId);
|
||||
if (!object || !mesh || !mesh.faceCount) throw new Error("basic scene has no mesh face");
|
||||
const added = await client.applyCommand({ type: "addMaterialSlot", objectId: object.id, name: "WebAssignMaterial" } as any);
|
||||
const slotIndex = (added.snapshot.nodes.find((node: any) => node.id === object.id)?.materialSlotIds?.length ?? 1) - 1;
|
||||
const assigned = await client.applyCommand({ type: "assignMaterialFaces", meshId: mesh.id, faceIndices: [0], slotIndex } as any);
|
||||
const undo = await client.applyCommand({ type: "undo" });
|
||||
const redo = await client.applyCommand({ type: "redo" });
|
||||
const malformed = await client.applyCommand({ type: "assignMaterialFaces", meshId: "mesh:missing", faceIndices: [0], slotIndex } as any).then(() => ({ code: "NO_ERROR" })).catch(shape);
|
||||
const afterMalformed = await client.snapshot();
|
||||
const saved = await client.saveBlend();
|
||||
const restored = await reopened.openBlend(saved.slice(0));
|
||||
const assignedMesh: any = assigned.snapshot.meshes.find((candidate: any) => candidate.id === mesh.id);
|
||||
const restoredMesh: any = restored.snapshot.meshes.find((candidate: any) => candidate.id === mesh.id);
|
||||
return { browser: "chromium", baseRevision: opened.snapshot.revision, addRevision: added.snapshot.revision, assignRevision: assigned.snapshot.revision, undoRevision: undo.snapshot.revision, redoRevision: redo.snapshot.revision, assigned: Boolean(assignedMesh?.materialSlotIds?.length && assignedMesh.materialSlotIds.includes("material:WebAssignMaterial")), restored: Boolean(restoredMesh?.materialSlotIds?.length && restoredMesh.materialSlotIds.includes("material:WebAssignMaterial")), assignedMesh, restoredMesh, malformed, malformedRevisionPreserved: afterMalformed.snapshot.revision === redo.snapshot.revision, reopenedRevision: restored.snapshot.revision };
|
||||
} finally { client.terminate(); reopened.terminate(); }
|
||||
}, Array.from(fixture));
|
||||
fs.mkdirSync(path.dirname(path.join(root, productionPath)), { recursive: true });
|
||||
fs.writeFileSync(path.join(root, productionPath), `${JSON.stringify({ schemaVersion: 1, task, operation: "MATERIAL_SLOT_ASSIGN_ENGINE_CHROMIUM", browser: "chromium", queueMutation: false, fixture: fixturePath, fixtureSha256, sourceUnits, ...result }, null, 2)}\n`);
|
||||
expect(result.browser).toBe("chromium");
|
||||
expect(result.addRevision).toBe(result.baseRevision + 1);
|
||||
expect(result.assignRevision).toBe(result.baseRevision + 2);
|
||||
expect(result.undoRevision).toBe(result.baseRevision + 3);
|
||||
expect(result.redoRevision).toBe(result.baseRevision + 4);
|
||||
expect(result.assigned).toBe(true);
|
||||
expect(result.restored).toBe(true);
|
||||
expect(result.malformed.code).not.toBe("NO_ERROR");
|
||||
expect(result.malformedRevisionPreserved).toBe(true);
|
||||
expect(result.reopenedRevision).toBe(1);
|
||||
});
|
||||
Reference in New Issue
Block a user