import { expect, test } from "./support/deployed-test"; import crypto from "node:crypto"; import fs from "node:fs"; import path from "node:path"; import { FIXTURES, REPO_ROOT, gotoApp, openProject, receipt, shot, waitEngineBoot, waitEngineReady } from "./support/deployed"; /** * Preflight for the deployed origin. * * Two different questions live here: "does the server hand out the build this * repository produced" (HTTP level, no browser needed) and "does a real headed * browser reach a working engine" (UI level). Both are gates for the rest of * the suite; a failure here means the later chapters prove nothing. */ test.describe.configure({ mode: "serial" }); test.use({ viewport: { width: 1600, height: 900 } }); function localWasmPath(): string | null { for (const candidate of ["web/dist/vendor/blender/web_engine.wasm", "web/app/public/vendor/blender/web_engine.wasm"]) { const file = path.join(REPO_ROOT, candidate); if (fs.existsSync(file)) return file; } return null; } test("[preflight-http] @smoke 线上入口提供隔离响应头、引擎清单与手册页", async ({ request }, testInfo) => { const origin = process.env.WEB_ORIGIN ?? "https://49.232.250.35:58014"; const index = await request.get("/"); expect(index.status(), `${origin}/`).toBe(200); const headers = index.headers(); expect(headers["cross-origin-opener-policy"]).toBe("same-origin"); expect(headers["cross-origin-embedder-policy"]).toBe("require-corp"); expect(headers["cross-origin-resource-policy"]).toBe("same-origin"); expect(headers["content-security-policy"] ?? "").toContain("wasm-unsafe-eval"); const indexEtag = headers["etag"] ?? null; const manifestResponse = await request.get("/wasm-module-manifest.json"); expect(manifestResponse.status()).toBe(200); const manifest = await manifestResponse.json() as { releaseId?: string; modules: Array<{ id: string; resources: { single?: { sha256?: string } } }>; }; expect(typeof manifest.releaseId).toBe("string"); const engine = manifest.modules.find((module) => module.id === "debug-incremental") ?? manifest.modules[0]; const remoteWasm = engine?.resources?.single?.sha256 ?? null; expect(remoteWasm, "engine manifest must pin a wasm hash").toBeTruthy(); /* Bind the live bytes to the locally built artifact. */ const wasmFile = localWasmPath(); expect(wasmFile, "a local web build must exist to compare against").toBeTruthy(); const localWasm = crypto.createHash("sha256").update(fs.readFileSync(wasmFile!)).digest("hex"); expect(remoteWasm, "deployed wasm must be the local build").toBe(localWasm); const manual = await request.get("/manuals/index.html"); expect(manual.status()).toBe(200); const range = await request.get("/vendor/blender/web_engine.wasm", { headers: { Range: "bytes=0-15" } }); expect(range.status()).toBe(206); expect(range.headers()["content-type"]).toBe("application/wasm"); expect((await range.body()).byteLength).toBe(16); const evidence = await shotlessReceipt(testInfo, { workflow: "HTTP preflight: isolation headers, wasm manifest hash vs local build, manual page, range request", origin, releaseId: manifest.releaseId, remoteWasm, localWasm, indexEtag, status: "PASS", }); expect(evidence.releaseId).toBeTruthy(); }); /** HTTP-only cases have no page to photograph; keep the same receipt shape. */ function shotlessReceipt(testInfo: Parameters[0], data: Record) { receipt(testInfo, data); return data; } test("[preflight-boot] @smoke 有头浏览器加载引擎并进入 SceneIR", async ({ page }, testInfo) => { await gotoApp(page, "web"); const status = await waitEngineBoot(page); const isolation = await page.evaluate(() => ({ secureContext: window.isSecureContext, crossOriginIsolated: window.crossOriginIsolated, webdriver: navigator.webdriver, })); expect(isolation.secureContext).toBe(true); expect(isolation.crossOriginIsolated).toBe(true); const image = await shot(page, testInfo, "booted"); receipt(testInfo, { workflow: "headed Chromium -> /?ui=web -> WASM ABI ready -> engine left the starting state", engineStatus: status, isolation, screenshot: image, status: "PASS", }); }); test("[preflight-fixture] 练习工程可打开且对象数正确", async ({ page }, testInfo) => { await gotoApp(page, "web"); const engineStatus = await openProject(page, FIXTURES.studio, { objects: 6, active: /PBR Studio Ground/ }); await expect(page.getByTestId("scene-stats")).toContainText(/Objects 6/, { timeout: 15_000 }); const stats = (await page.getByTestId("scene-stats").innerText()).trim(); const image = await shot(page, testInfo, "studio-open"); receipt(testInfo, { workflow: "upload web/app/public/tutorial/pbr/studio.blend -> SceneIR -> Objects 6", engineStatus, fixture: path.relative(REPO_ROOT, FIXTURES.studio), sceneStats: stats, screenshot: image, status: "PASS", }); });