import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; import ts from "../../web/node_modules/typescript/lib/typescript.js"; import crypto from "node:crypto"; const root = path.resolve(import.meta.dirname, "../.."); const sourcePath = path.join(root, "web/protocol/render-routing.ts"); const source = fs.readFileSync(sourcePath, "utf8").replace('import type { ErrorCode } from "./error";\n', ""); const transpiled = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.ES2022, target: ts.ScriptTarget.ES2022 }, fileName: sourcePath, reportDiagnostics: true }); assert.deepEqual(transpiled.diagnostics, []); const routing = await import(`data:text/javascript;base64,${Buffer.from(transpiled.outputText).toString("base64")}`); const request = (backend) => ({ schemaVersion: 1, renderEngine: "BLENDER_EEVEE", backend, complexity: "BOUNDED" }); const webgpu = routing.routeRenderExecution(request("WEBGPU")); const webgl2 = routing.routeRenderExecution(request("WEBGL2")); assert.equal(webgpu.status, "BLOCKED"); assert.equal(webgpu.target, "WEB_LOCAL_BOUNDED"); assert.equal(webgpu.issues[0].code, "WEBGPU_RENDERER_UNAVAILABLE"); assert.equal(webgl2.status, "READY"); assert.equal(webgl2.target, "WEB_LOCAL_BOUNDED"); const reportPath = path.join(root, "tests/golden/M14-01E/chromium-webgpu-boundary-report.json"); const manifestPath = path.join(root, "tests/golden/M14-01E/manifest.json"); const report = { schemaVersion: 1, task: "M14-01E", operation: "CHROMIUM_WEBGPU_FAIL_CLOSED_BOUNDARY", runtime: "NODE_PROTOCOL_WITH_CHROMIUM_PROBE_IDENTITY", chromiumProbeIdentitySha256: JSON.parse(fs.readFileSync(path.join(root, "tests/golden/M14-01D/probe-identity-report.json"), "utf8")).identitySha256, webgpu: { status: webgpu.status, target: webgpu.target, code: webgpu.issues[0].code }, webgl2: { status: webgl2.status, target: webgl2.target, reason: webgl2.reason }, execution: "DISABLED", nextTask: "M14-04A" }; if (process.env.UPDATE_M14_01E_REPORT === "1") { fs.mkdirSync(path.dirname(reportPath), { recursive: true }); fs.writeFileSync(reportPath, `${JSON.stringify(report, null, 2)}\n`); const fileDigest = (file) => crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex"); const relative = (file) => path.relative(root, file).replaceAll(path.sep, "/"); const artifactPaths = { parentManifest: path.join(root, "tests/golden/M14-01D/manifest.json"), checker: path.join(root, "tools/web/check-chromium-webgpu-boundary.mjs"), package: path.join(root, "web/package.json"), protocol: sourcePath, report: reportPath }; const artifacts = Object.fromEntries(Object.entries(artifactPaths).map(([name, file]) => [name, { path: relative(file), sha256: fileDigest(file) }])); fs.writeFileSync(manifestPath, `${JSON.stringify({ schemaVersion: 1, task: "M14-01E", parentTask: "M14-01D", enablingTask: false, parityStateChange: false, runtime: "NODE_PROTOCOL_WITH_CHROMIUM_PROBE_IDENTITY", operation: "CHROMIUM_WEBGPU_FAIL_CLOSED_BOUNDARY", artifacts, nextTask: "M14-04A" }, null, 2)}\n`); } assert.deepEqual(JSON.parse(fs.readFileSync(reportPath, "utf8")), report); const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8")); const fileDigest = (file) => crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex"); assert.deepEqual({ task: manifest.task, parentTask: manifest.parentTask, nextTask: manifest.nextTask }, { task: "M14-01E", parentTask: "M14-01D", nextTask: "M14-04A" }); for (const artifact of Object.values(manifest.artifacts)) assert.equal(fileDigest(path.join(root, artifact.path)), artifact.sha256, artifact.path); process.stdout.write(`chromium-webgpu-boundary-ok webgpu=${webgpu.status}/${webgpu.issues[0].code} webgl2=${webgl2.status} execution=DISABLED next=${manifest.nextTask}\n`);