Files
orca/config/scripts/mobile-web-app/mobile-web-app-bundle-test-fixture.mjs
Neil 9bd6272fdf refactor(tooling): organize build, CI, and test owners (#38130)
* refactor(tooling): organize test runtime and maintenance owners

* test(tooling): preserve relocated runtime fixture dependency edges

* refactor(tooling): preserve xterm routing owner checks

* ci(tooling): include routing owner in sparse checkout

* test(tooling): preserve copied workflow dependency closures

* fix(tooling): normalize hashed JSON assets in release parity

* fix(tooling): distinguish asset aliases from literal references

* fix(tooling): frame normalized asset reference payloads

* fix(tooling): normalize decoded JSON asset references

* refactor(tooling): organize build, CI and release owners

* fix(tooling): align moved generator and workflow path contracts

* fix(tooling): update generated plugin bundle owner banners

* test(tooling): create relocated mobile verifier fixture directories

* test(tooling): copy headless detector dependency closure

* test(tooling): align native batch policy fixtures with owner path

* fix(tooling): link moved reliability command to historical evidence

* fix(tooling): preserve nested sandbox owners and canonical guide source

* fix(tooling): target release version owners in checkout fixture
2026-11-04 21:08:19 -08:00

53 lines
1.8 KiB
JavaScript

import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { dirname, join } from 'node:path'
import { deserialize, serialize } from 'node:v8'
import {
bundleMobileWebApp,
buildMobileWebAppBundle
} from '../build/mobile-web-app/build-mobile-web-app-bundle.mjs'
export async function withScratch(run) {
const scratch = await mkdtemp(join(tmpdir(), 'orca-mobile-web-app-test-'))
try {
return await run(scratch)
} finally {
await rm(scratch, { recursive: true, force: true })
}
}
// Snapshots preserve Buffer methods and give each assertion its own mutable copy.
let appBundleSnapshot
let writtenBundleSnapshot
export async function readAppBundle() {
appBundleSnapshot ??= bundleMobileWebApp().then(serialize)
// Deserialized Buffers alias their snapshot, so copy it before exposing them.
return deserialize(Buffer.from(await appBundleSnapshot))
}
export async function readWrittenBundle() {
writtenBundleSnapshot ??= withScratch(async (scratch) => {
const { outDir, ...result } = await buildMobileWebAppBundle({ outDir: join(scratch, 'bundle') })
const html = await readFile(join(outDir, 'index.html'), 'utf8')
const files = await Promise.all(
['manifest.json', ...result.manifest.assets.map((asset) => asset.path)].map(async (file) => ({
file,
bytes: await readFile(join(outDir, file))
}))
)
return serialize({ ...result, html, files })
})
return deserialize(Buffer.from(await writtenBundleSnapshot))
}
export async function copyWrittenBundle(outDir) {
const snapshot = await readWrittenBundle()
for (const { file, bytes } of snapshot.files) {
const destination = join(outDir, file)
await mkdir(dirname(destination), { recursive: true })
await writeFile(destination, bytes)
}
return { ...snapshot, outDir }
}