Files
workinf_Blender_Wasm/web/tests/e2e/wbv2-object-delete-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

4 lines
3.3 KiB
TypeScript

import { expect, test } from "@playwright/test";import crypto from "node:crypto";import fs from "node:fs";import path from "node:path";
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-P22-002";const productionPath=process.env.WBV2_BATCH_PRODUCTION??`tests/golden/${task}/object-delete-production.json`;const sourceUnits=JSON.parse(process.env.WBV2_BATCH_UNITS??'["operator:OBJECT_OT_delete"]');
test("WBV2-P22-002 binds deleteObject to compiled WASM Main",async({page})=>{test.setTimeout(120000);await page.goto("/");const result=await page.evaluate(async(bytes)=>{const{WebEngineClient}=await import("/src/engine-client/WebEngineClient.ts");const client=new WebEngineClient({timeoutMs:30000}),reopened=new WebEngineClient({timeoutMs:30000});try{const opened=await client.openBlend(Uint8Array.from(bytes).buffer);const object=opened.snapshot.nodes.find(n=>n.type==="MESH");if(!object)throw new Error("basic scene has no mesh object");const baseRevision=opened.snapshot.revision;const beforeCount=opened.snapshot.nodes.length;const deleted=await client.applyCommand({type:"deleteObject",objectId:object.id}as any);const undone=await client.applyCommand({type:"undo"});const redone=await client.applyCommand({type:"redo"});const malformed=await client.applyCommand({type:"deleteObject",objectId:"object:missing"}as any).then(()=>({code:"NO_ERROR"})).catch((e:any)=>({code:e?.code,message:e?.message}));const afterMalformed=await client.snapshot();const saved=await client.saveBlend();const reopen=await reopened.openBlend(saved);return{browser:"chromium",baseRevision,beforeCount,deleteRevision:deleted.snapshot.revision,undoRevision:undone.snapshot.revision,redoRevision:redone.snapshot.revision,afterCount:deleted.snapshot.nodes.length,deletedId:object.id,malformed,malformedRevisionPreserved:afterMalformed.snapshot.revision===redone.snapshot.revision,reopenedCount:reopen.snapshot.nodes.length,reopenedDeleted:!reopen.snapshot.nodes.some(n=>n.id===object.id),reopenedRevision:reopen.snapshot.revision,savedSha256:await(async(v)=>{const h=await crypto.subtle.digest("SHA-256",v);return Array.from(new Uint8Array(h),b=>b.toString(16).padStart(2,"0")).join("")})(saved)}}finally{client.terminate();reopened.terminate()}} ,Array.from(fixture));fs.mkdirSync(path.join(root,"tests/golden/WBV2-P22-002"),{recursive:true});const output=process.env.WBV2_DELETE_REPORT??"object-delete-production.json";fs.writeFileSync(path.join(root,"tests/golden/WBV2-P22-002",output),`${JSON.stringify({schemaVersion:1,task:"WBV2-P22-002",operation:"OBJECT_DELETE_ENGINE_CHROMIUM",queueMutation:false,fixtureSha256,...result},null,2)}\n`);expect(result.browser).toBe("chromium");expect(result.afterCount).toBe(result.beforeCount-1);expect(result.deleteRevision).toBe(result.baseRevision+1);expect(result.undoRevision).toBe(result.baseRevision+2);expect(result.redoRevision).toBe(result.baseRevision+3);expect(result.malformed.code).not.toBe("NO_ERROR");expect(result.malformedRevisionPreserved).toBe(true);expect(result.reopenedCount).toBe(result.afterCount);expect(result.reopenedDeleted).toBe(true);expect(result.reopenedRevision).toBe(1)});