Files
workinf_Blender_Wasm/web/tests/e2e/wbv2-object-create-production.spec.ts
mes123456 dc7e2c98c4
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
Advance deduplicated object creation coverage
2026-08-28 14:34:52 +08:00

7 lines
3.1 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 fixture=fs.readFileSync(path.join(root,"tests/files/web/basic_scene.blend"));const fixtureSha256=crypto.createHash("sha256").update(fixture).digest("hex");
test("WBV2-P18-002 binds createPrimitive 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});const reopened=new WebEngineClient({timeoutMs:30000});const digest=async(v:ArrayBuffer)=>{const h=await crypto.subtle.digest("SHA-256",v);return Array.from(new Uint8Array(h),b=>b.toString(16).padStart(2,"0")).join("")};try{const opened=await client.openBlend(Uint8Array.from(bytes).buffer);const beforeCount=opened.snapshot.nodes.length;const baseRevision=opened.snapshot.revision;const created=await client.applyCommand({type:"createPrimitive",primitive:"CUBE",name:"WBV2P1802Cube",location:[1,2,3]}as any);const afterCreate=created.snapshot;const createdNode=afterCreate.nodes.find(n=>n.name==="WBV2P1802Cube");const undone=await client.applyCommand({type:"undo"});const redone=await client.applyCommand({type:"redo"});const malformed=await client.applyCommand({type:"createPrimitive",primitive:"SPHERE",name:"invalid",location:[0,0,0]}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,createRevision:afterCreate.revision,undoRevision:undone.snapshot.revision,redoRevision:redone.snapshot.revision,afterCount:afterCreate.nodes.length,createdNode:{id:createdNode?.id,name:createdNode?.name,type:createdNode?.type},malformed,malformedRevisionPreserved:afterMalformed.snapshot.revision===redone.snapshot.revision,reopenedCount:reopen.snapshot.nodes.length,reopenedRevision:reopen.snapshot.revision,savedSha256:await digest(saved)}}finally{client.terminate();reopened.terminate()}} ,Array.from(fixture));fs.mkdirSync(path.join(root,"tests/golden/WBV2-P18-002"),{recursive:true});const output=process.env.WBV2_CREATE_REPORT??"object-create-production.json";fs.writeFileSync(path.join(root,"tests/golden/WBV2-P18-002",output),`${JSON.stringify({schemaVersion:1,task:"WBV2-P18-002",operation:"OBJECT_CREATE_ENGINE_CHROMIUM",queueMutation:false,fixtureSha256,...result},null,2)}\n`);expect(result.browser).toBe("chromium");expect(result.afterCount).toBe(result.beforeCount+1);expect(result.createRevision).toBe(result.baseRevision+1);expect(result.undoRevision).toBe(result.baseRevision+2);expect(result.redoRevision).toBe(result.baseRevision+3);expect(result.createdNode.name).toBe("WBV2P1802Cube");expect(result.malformed.code).not.toBe("NO_ERROR");expect(result.malformedRevisionPreserved).toBe(true);expect(result.reopenedCount).toBe(result.afterCount);expect(result.reopenedRevision).toBe(1)});