1/**
2 * Point the floci-backed suites at a locally built emulator when one exists.
3 *
4 * `pnpm floci:build` tags the `submodules/floci` checkout as `floci:dev`;
5 * that is how an emulator patch gets exercised before its release image is
6 * published to GHCR. When no such image exists the env is left unset so the
7 * floci package resolves the pinned release image — hard-defaulting to a
8 * missing ref would fail every suite's `docker run` before a test can run.
9 *
10 * Must run before any child `bun test` is spawned: `ensureFloci` reads
11 * `ALCHEMY_FLOCI_IMAGE` in the child, and a container running a different
12 * image than the resolved one is recreated.
13 */
14export const preferLocalFlociImage = (label: string): void => {
15 if (process.env.ALCHEMY_FLOCI_IMAGE) return;
16 const devImage = Bun.spawnSync(["docker", "image", "inspect", "floci:dev"], {
17 stdout: "ignore",
18 stderr: "ignore",
19 });
20 if (devImage.exitCode === 0) {
21 process.env.ALCHEMY_FLOCI_IMAGE = "floci:dev";
22 console.log(`${label}: using locally built floci:dev image`);
23 } else {
24 console.log(
25 `${label}: no local floci:dev image (pnpm floci:build) — using the pinned release image`,
26 );
27 }
28};