diff --git a/.github/CI.md b/.github/CI.md index e0bde47043..89fece0eb1 100644 --- a/.github/CI.md +++ b/.github/CI.md @@ -145,6 +145,16 @@ Node-version output: only those checkouts resolve and install their production N job level. Current composites skip that fallback. Integration evidence verifies and records the actual selected version. +Docker Bun builders, runtimes and the React service generator use the same Bun +version as the root `packageManager` and CI, pinned to official `oven/bun` +multiarchitecture image digests. Update every flavor together; the CLI toolchain +guard rejects drift and native image checks execute the runtime version. Client +builds share `packages/ui/bin/build-client.ts`, which awaits Vite and its plugin +output before an explicit success exit. Keep each service's working directory; +SSR and development/watch commands retain their own arguments. The completion +marker distinguishes a build that resolved from a stalled process exit; it is +not proof of the cause of a stall before Vite resolves. + Shared checks and native CLI builds use the same Bun download key inputs: the root manifest, every declared workspace manifest, lockfile, patches and `bunfig.toml`. The independent document-node npm manifest is outside that workspace identity. diff --git a/.github/RELEASING.md b/.github/RELEASING.md index 08b5b3eea4..c73be6cd58 100644 --- a/.github/RELEASING.md +++ b/.github/RELEASING.md @@ -295,8 +295,11 @@ A published version is not a deployment. Deployments follow their own procedure. The workflow test stubs `gh`, so it proves the step's branching, not GitHub's lookup. This is a recorded decision: the step treats any failed lookup as a missing release and calls `gh release create`, so the draft check is only as reliable as gh's lookup. -- **A failed Release run after the tag.** Never move the tag. Re-run the Release run's failed - jobs (its concurrency never cancels a release), or release the fix as the next version. +- **A failed Release run after the tag.** Never move the tag. For a transient failure, + re-run **all jobs** of the same Release run (its concurrency never cancels a release). + The maintained adopter requires the complete publication job matrix from one current + attempt; failed-job-only retries omit earlier successes, and mixing attempts is refused. + If source must change, fix `main`, validate a new candidate and release the next version. ## Merging during a release, and the release lease diff --git a/knip.config.ts b/knip.config.ts index 06489e239c..03b5b0db6e 100644 --- a/knip.config.ts +++ b/knip.config.ts @@ -241,12 +241,14 @@ export default { entry: [ ...Object.values(uiPackage.exports), ...Object.values(uiPackage.bin), + // Invoked by path from service build scripts, not a published bin. + 'bin/build-client.ts', 'src/**/*.stories.{ts,tsx}', ], // Tailwind's CSS compiler must see public stylesheet imports too. project: ['**/*.{ts,tsx,css}'], ignoreDependencies: [ - // Type-only import in src/{pwa,seo/runtime}/vite-plugin.ts. Declared + // Build helper and src/{pwa,seo/runtime}/vite-plugin.ts imports. Declared // as an optional peer so consumers without a vite-driven service // don't have to install it; knip flags optional peers that are // referenced, which is exactly the pattern we want here. diff --git a/services/docs/scripts/build-client.ts b/packages/ui/bin/build-client.ts similarity index 72% rename from services/docs/scripts/build-client.ts rename to packages/ui/bin/build-client.ts index 4665ff7f6f..bf2eea3357 100644 --- a/services/docs/scripts/build-client.ts +++ b/packages/ui/bin/build-client.ts @@ -1,5 +1,6 @@ -// The Playwright webServer chains client build → preview with `&&`, so the -// chain advances only when the build PROCESS exits. `bun --bun vite build` +// Client build chains (Docker, workspace scripts and local preview) advance +// only when the build PROCESS exits. Keep the calling service as the cwd so +// Vite selects its own config and output paths. `bun --bun vite build` // occasionally never exits after a successful build, and the silent hang // starves the chain until the webServer timeout with zero tests run. // Building through the JS API and exiting explicitly removes the implicit @@ -8,7 +9,7 @@ // fires. The exit itself needs Bun ≥ 1.4.1 — earlier Bun ran rolldown's // N-API finalizers and cleanup hooks inside `process.exit()`, and the // evidence places CI's remaining stalls there (pinned in -// `.github/actions/setup-turbo/action.yml`). The line logged after `build()` +// `.github/actions/setup-turbo/action.yml` and Docker images). The line after `build()` // resolves puts any future stall on one side of the exit or the other. import { build } from 'vite'; diff --git a/services/ai-gateway/Dockerfile b/services/ai-gateway/Dockerfile index b427274012..ea9a118f4c 100644 --- a/services/ai-gateway/Dockerfile +++ b/services/ai-gateway/Dockerfile @@ -1,7 +1,7 @@ # AI Gateway Dockerfile — the Vite panel, served by the Bun server that also runs the gateway ARG VERSION=dev -FROM oven/bun:1.3.12 AS bun-bin +FROM oven/bun:1.4.2@sha256:9114c058aeae42162ee16dd5084b95fe9473970bb6bcb5b232ab1630f0546895 AS bun-bin # ============================================================================ # Stage 1: workspace deps @@ -58,14 +58,14 @@ WORKDIR /app/services/ai-gateway # stage carries no `node_modules`, so every import `server.ts` makes — # `@tale/ui/server`, the service's own modules, its dependencies — has to # be inlined here (the pattern `services/web` and `services/docs` use). -RUN bun --bun vite build \ +RUN bun --bun ../../packages/ui/bin/build-client.ts \ && bun build server.ts --target=bun --outfile=server.js --external bun WORKDIR /app # ============================================================================ # Stage 3: runtime # ============================================================================ -FROM oven/bun:1.3.12-slim AS runner +FROM oven/bun:1.4.2-slim@sha256:cb3bbbb08e13a4a2ff400f24c7a2a1d5efa83f6ef8544d52d95a519631e2fc61 AS runner ENV NODE_ENV=production \ PORT=3004 \ diff --git a/services/ai-gateway/package.json b/services/ai-gateway/package.json index bd3529bbeb..89f9ffd4a4 100644 --- a/services/ai-gateway/package.json +++ b/services/ai-gateway/package.json @@ -7,7 +7,7 @@ "scripts": { "setup": "echo 'Dependencies managed by root workspace'", "dev": "bun --bun vite", - "build": "bun --bun vite build", + "build": "bun --bun ../../packages/ui/bin/build-client.ts", "start": "bun server.ts", "lint": "bunx oxlint --type-aware", "lint:fix": "bunx oxlint --type-aware --fix", diff --git a/services/docs/Dockerfile b/services/docs/Dockerfile index 2b2a6e4c49..98115c8696 100644 --- a/services/docs/Dockerfile +++ b/services/docs/Dockerfile @@ -1,7 +1,7 @@ # Tale Docs Dockerfile — Vite SPA + Bun server, mirrors services/web. ARG VERSION=dev -FROM oven/bun:1.3.12 AS bun-bin +FROM oven/bun:1.4.2@sha256:9114c058aeae42162ee16dd5084b95fe9473970bb6bcb5b232ab1630f0546895 AS bun-bin # ============================================================================ # Stage 1: workspace deps @@ -60,7 +60,7 @@ WORKDIR /app/services/docs # `dist-seo/` and serves it via `createPrecompiledServer`, so no source # markdown is read at request time. RUN bun --bun scripts/build-search-index.ts \ - && bun --bun vite build \ + && bun --bun ../../packages/ui/bin/build-client.ts \ && bun --bun vite build --ssr app/entry-server.tsx --outDir dist-ssr \ && bun --bun scripts/prerender.ts \ && bun --bun /app/packages/ui/bin/seo-compile.ts ./scripts/seo.config.ts --out dist-seo \ @@ -70,7 +70,7 @@ WORKDIR /app # ============================================================================ # Stage 3: runtime # ============================================================================ -FROM oven/bun:1.3.12-slim AS runner +FROM oven/bun:1.4.2-slim@sha256:cb3bbbb08e13a4a2ff400f24c7a2a1d5efa83f6ef8544d52d95a519631e2fc61 AS runner ARG LOCALE_COOKIE_DOMAIN= # Re-declare DOCS_BASE_URL here so the runner stage can promote it to ENV; diff --git a/services/docs/package.json b/services/docs/package.json index c00f135605..3d35b88db3 100644 --- a/services/docs/package.json +++ b/services/docs/package.json @@ -7,8 +7,8 @@ "scripts": { "setup": "echo 'Dependencies managed by root workspace'", "dev": "bun --bun scripts/build-search-index.ts && bun --bun vite", - "build": "bun --bun scripts/build-search-index.ts && bun --bun vite build && bun --bun vite build --ssr app/entry-server.tsx --outDir dist-ssr && bun --bun scripts/prerender.ts && bun run seo:compile", - "build:client": "bun --bun vite build", + "build": "bun --bun scripts/build-search-index.ts && bun --bun ../../packages/ui/bin/build-client.ts && bun --bun vite build --ssr app/entry-server.tsx --outDir dist-ssr && bun --bun scripts/prerender.ts && bun run seo:compile", + "build:client": "bun --bun ../../packages/ui/bin/build-client.ts", "build:ssr": "bun --bun vite build --ssr app/entry-server.tsx --outDir dist-ssr", "prerender": "bun --bun scripts/prerender.ts", "build:search-index": "bun --bun scripts/build-search-index.ts", diff --git a/services/docs/playwright.config.ts b/services/docs/playwright.config.ts index 75d0fbd057..51ba02b306 100644 --- a/services/docs/playwright.config.ts +++ b/services/docs/playwright.config.ts @@ -25,7 +25,7 @@ export default createPlaywrightConfig({ // the web suite hit — the deps optimizer never finishes; `vite preview` // has no optimizer). SSR/prerender/SEO stay out of the command — the // suite exercises the SPA the dev server serves. The build runs through - // `scripts/build-client.ts` (vite's JS API + an explicit exit), not the + // `../../packages/ui/bin/build-client.ts` (vite's JS API + an explicit exit), not the // `vite build` CLI: the CLI process occasionally never exits after a // successful build, and the `&&` chain then starves silently until this // webServer timeout with zero tests run. The explicit exit is only safe @@ -35,7 +35,7 @@ export default createPlaywrightConfig({ // search. Ordinary local runs keep the client-only build below. (process.env.E2E_USE_BUILD === '1' ? '' - : `bun --bun scripts/build-search-index.ts && bun --bun scripts/build-client.ts && `) + + : `bun --bun scripts/build-search-index.ts && bun --bun ../../packages/ui/bin/build-client.ts && `) + `bun --bun vite preview --port ${PORT} --strictPort`, url: `http://localhost:${PORT}`, // Locally reuse an already-running `bun run dev`; in CI boot fresh. diff --git a/services/platform/Dockerfile b/services/platform/Dockerfile index be5ba7dadb..bde590e1f0 100644 --- a/services/platform/Dockerfile +++ b/services/platform/Dockerfile @@ -9,7 +9,7 @@ ARG VERSION=dev # Bun binary for all stages -FROM oven/bun:1.3.12 AS bun-bin +FROM oven/bun:1.4.2@sha256:9114c058aeae42162ee16dd5084b95fe9473970bb6bcb5b232ab1630f0546895 AS bun-bin # Node binary for the 0.5 backend roles (api/worker). The backend runs its .ts # sources directly via Node's type stripping (>= 22.18); only the binary is @@ -115,7 +115,7 @@ ENV NODE_ENV=production # `dist-seo/`. The runtime stage serves these via @tale/ui's precompiled # SEO server, so no source markdown is needed at request time. WORKDIR /app/services/platform -RUN bun --bun vite build \ +RUN bun --bun ../../packages/ui/bin/build-client.ts \ && bun scripts/check-sw-manifest.ts \ && bun scripts/check-entry-budget.ts \ && bun scripts/prerender-boot-shell.tsx \ diff --git a/services/platform/package.json b/services/platform/package.json index bc34a30195..b1d37f6e85 100644 --- a/services/platform/package.json +++ b/services/platform/package.json @@ -7,7 +7,7 @@ "setup": "echo 'Dependencies managed by root workspace'", "dev": "bun scripts/dev.ts", "dev:fast": "TALE_DEV_SKIP_DOCKER=1 bun scripts/dev.ts", - "build": "bun run configs:validate && bun --bun vite build && bun scripts/check-sw-manifest.ts && bun scripts/check-entry-budget.ts && bun scripts/prerender-boot-shell.tsx", + "build": "bun run configs:validate && bun --bun ../../packages/ui/bin/build-client.ts && bun scripts/check-sw-manifest.ts && bun scripts/check-entry-budget.ts && bun scripts/prerender-boot-shell.tsx", "start": "bun --bun vite preview", "lint": "bunx oxlint --type-aware", "lint:fix": "bunx oxlint --type-aware --fix", diff --git a/services/platform/scripts/dev-engine.ts b/services/platform/scripts/dev-engine.ts index 098d77c89e..36befd5575 100644 --- a/services/platform/scripts/dev-engine.ts +++ b/services/platform/scripts/dev-engine.ts @@ -1154,10 +1154,16 @@ export async function runDevFleet() { done: 'Production bundle built', }, () => - runCommand('bun', ['--bun', 'vite', 'build'], {}, platformRoot, { - label: 'vite', - classifier: viteClassifier, - }), + runCommand( + 'bun', + ['--bun', '../../packages/ui/bin/build-client.ts'], + {}, + platformRoot, + { + label: 'vite', + classifier: viteClassifier, + }, + ), ); } else { infoLine('Reusing existing dist/ (skipping vite build)'); diff --git a/services/platform/tests/integration/container-image-test.ts b/services/platform/tests/integration/container-image-test.ts index 0bbd1f552a..7cb37ad241 100644 --- a/services/platform/tests/integration/container-image-test.ts +++ b/services/platform/tests/integration/container-image-test.ts @@ -156,6 +156,30 @@ async function main(): Promise { if (r.failed > 0) return 1; + const { packageManager } = await Bun.file( + `${PROJECT_ROOT}/package.json`, + ).json(); + const expectedBun = packageManager.replace('bun@', ''); + for (const svc of ['platform', 'sandbox', 'sandbox-runtime']) { + const image = images.get(svc)!; + const bun = await capture([ + 'docker', + 'run', + '--rm', + '--network', + 'none', + '--entrypoint', + 'timeout', + image, + '10', + 'bun', + '--version', + ]); + if (bun.exitCode === 0 && bun.stdout.trim() === expectedBun) + r.pass(`${svc}: Bun ${expectedBun} matches the workspace toolchain`); + else r.fail(`${svc}: Bun runtime does not match ${expectedBun}`); + } + // 1. OCI label checks header('Checking OCI labels'); for (const svc of SERVICES) { diff --git a/services/platform/tests/integration/container-sandbox-runtime-test.ts b/services/platform/tests/integration/container-sandbox-runtime-test.ts index 37e00cb18c..257ad6d7f5 100644 --- a/services/platform/tests/integration/container-sandbox-runtime-test.ts +++ b/services/platform/tests/integration/container-sandbox-runtime-test.ts @@ -294,6 +294,9 @@ NODEEOF`, )?.[1]; if (!nodeVersion) throw new Error('Missing exact Node image pin'); probes.unshift({ slug: 'node', binary: 'node', version: nodeVersion }); + const bunVersion = dockerfile.match(/FROM oven\/bun:([\d.]+)@sha256:/)?.[1]; + if (!bunVersion) throw new Error('Missing exact Bun image pin'); + probes.unshift({ slug: 'bun', binary: 'bun', version: bunVersion }); const probeScript = String.raw` import json, os, re, signal, subprocess, sys, time diff --git a/services/platform/tests/integration/static-site-test.ts b/services/platform/tests/integration/static-site-test.ts index 2b51fe3126..bea4348d88 100644 --- a/services/platform/tests/integration/static-site-test.ts +++ b/services/platform/tests/integration/static-site-test.ts @@ -23,7 +23,7 @@ import { nonRootImageUser, sleep, } from './lib/docker'; -import { projectRoot } from './lib/exec'; +import { capture, projectRoot } from './lib/exec'; import { CYAN, GREEN, header, NC, RED, Results, YELLOW } from './lib/log'; interface StaticSiteProbe { @@ -146,6 +146,25 @@ export async function runStaticSiteTest( r.fail(`${svc}: no HEALTHCHECK instruction`); } + const { packageManager } = await Bun.file(`${root}/package.json`).json(); + const expectedBun = packageManager.replace('bun@', ''); + const bun = await capture([ + 'docker', + 'run', + '--rm', + '--network', + 'none', + '--entrypoint', + 'timeout', + image, + '10', + 'bun', + '--version', + ]); + if (bun.exitCode === 0 && bun.stdout.trim() === expectedBun) + r.pass(`${svc}: Bun ${expectedBun} matches the workspace toolchain`); + else r.fail(`${svc}: Bun runtime does not match ${expectedBun}`); + const sizeMb = metadata.sizeMb; if (sizeMb <= sizeBudgetMb) { r.pass(`${svc}: ${sizeMb} MB ≤ ${sizeBudgetMb} MB budget`); diff --git a/services/platform/tests/manual/reference/automation.md b/services/platform/tests/manual/reference/automation.md index cc98892a7f..608d8086bf 100644 --- a/services/platform/tests/manual/reference/automation.md +++ b/services/platform/tests/manual/reference/automation.md @@ -6,6 +6,14 @@ suite alongside the automated ones — they drive the same stack. ## Coverage map +Bun Docker builders, runtimes and the React service generator match the pinned +workspace/CI version with immutable image digests. All production client builds +share an awaited Vite helper; real subprocess fixtures prove service cwd, delayed +plugin output and nonzero build/close failures (`tools/cli/scripts/bun-toolchain.test.ts`, +`tools/cli/scripts/build-client.test.ts`). Native container smoke/conformance and +static-site builds cover the runtime upgrade; the intermittent hosted ARM build +stall still requires hosted observation. + Model access immediate saves roll back on failure (including after the affected-defaults confirmation), show one failure toast, remain retryable, and reconcile mounted controls with a fresh policy readback. Replaced readbacks diff --git a/services/platform/tests/manual/suites/performance.md b/services/platform/tests/manual/suites/performance.md index c49c8f4ec8..960f587c93 100644 --- a/services/platform/tests/manual/suites/performance.md +++ b/services/platform/tests/manual/suites/performance.md @@ -38,7 +38,7 @@ magnitude: `prod` on a local stack, add `TALE_E2E_SERVE_BUILD=1` to the environment of mode A's or B's `bun scripts/dev.ts`: it serves `dist/` through `vite preview`, which proxies the backend like the dev server, and runs - `bun --bun vite build` first when `dist/` is missing. Delete `dist/` to + `bun --bun ../../packages/ui/bin/build-client.ts` first when `dist/` is missing. Delete `dist/` to build again; the build alone needs about 3 GB of memory. > **Agent / measurement note**: diff --git a/services/sandbox-runtime/Dockerfile b/services/sandbox-runtime/Dockerfile index bb83cdf492..610a1e954a 100644 --- a/services/sandbox-runtime/Dockerfile +++ b/services/sandbox-runtime/Dockerfile @@ -18,7 +18,7 @@ # here — the image conformance test walks the registry. # --- daemon build stage: bundle runnerd to a single Node-target file -------- -FROM oven/bun:1 AS daemon-build +FROM oven/bun:1.4.2@sha256:9114c058aeae42162ee16dd5084b95fe9473970bb6bcb5b232ab1630f0546895 AS daemon-build WORKDIR /build COPY services/sandbox-runtime/daemon/ ./ RUN bun build --target=node src/main.ts --outfile /runnerd.mjs \ @@ -26,7 +26,7 @@ RUN bun build --target=node src/main.ts --outfile /runnerd.mjs \ # Gemini's system settings must be immutable and root-owned. Derive them # from the platform's existing harness interpreter, without a package install. -FROM oven/bun:1 AS gemini-settings-build +FROM oven/bun:1.4.2@sha256:9114c058aeae42162ee16dd5084b95fe9473970bb6bcb5b232ab1630f0546895 AS gemini-settings-build WORKDIR /build COPY services/platform/lib/harnesses/ services/platform/lib/harnesses/ COPY configs/platform/system/harnesses/gemini/harness.yml configs/platform/system/harnesses/gemini/harness.yml diff --git a/services/sandbox/Dockerfile b/services/sandbox/Dockerfile index 67f46cadca..6149e909d6 100644 --- a/services/sandbox/Dockerfile +++ b/services/sandbox/Dockerfile @@ -17,7 +17,6 @@ # docker build -f services/sandbox/Dockerfile . ARG VERSION=dev -ARG BUN_VERSION=1.3.12 ARG DOCKER_CLI_VERSION=27 # docker CLI stage — aliased so the runner stage can `COPY --from=docker-cli` @@ -28,7 +27,7 @@ FROM docker:${DOCKER_CLI_VERSION}-cli AS docker-cli # ============================================================================= # Stage 1: BUILDER — install full deps (incl. devDeps) for typecheck/tests # ============================================================================= -FROM oven/bun:${BUN_VERSION}-debian AS builder +FROM oven/bun:1.4.2-debian@sha256:4f6e31d1a54d6a3dd312daef655fc998101b5043d52e12592ac293ef04b9bc73 AS builder WORKDIR /app @@ -46,7 +45,7 @@ COPY packages/shared/src/monitoring/privacy.ts /packages/shared/src/monitoring/p # Stage 2: RUNNER — production deps only + docker CLI for spawning siblings # ============================================================================= # trivy:ignore:AVD-DS-0002 -- runs as root by design; needs /var/run/docker.sock -FROM oven/bun:${BUN_VERSION}-debian AS runner +FROM oven/bun:1.4.2-debian@sha256:4f6e31d1a54d6a3dd312daef655fc998101b5043d52e12592ac293ef04b9bc73 AS runner WORKDIR /app diff --git a/services/ui-docs/Dockerfile b/services/ui-docs/Dockerfile index a81422b01d..156eee5d23 100644 --- a/services/ui-docs/Dockerfile +++ b/services/ui-docs/Dockerfile @@ -1,7 +1,7 @@ # Tale UI Docs Dockerfile — Vite SPA + Bun server, mirrors services/docs. ARG VERSION=dev -FROM oven/bun:1.3.12 AS bun-bin +FROM oven/bun:1.4.2@sha256:9114c058aeae42162ee16dd5084b95fe9473970bb6bcb5b232ab1630f0546895 AS bun-bin # ============================================================================ # Stage 1: workspace deps @@ -62,7 +62,7 @@ WORKDIR /app/services/ui-docs # server.ts (and its `@tale/ui/*` source imports) into a self-contained # server.js — the runner stage carries no node_modules, mirroring web/docs. RUN bun --bun scripts/build-content.ts \ - && bun --bun vite build \ + && bun --bun ../../packages/ui/bin/build-client.ts \ && bun --bun vite build --ssr app/entry-server.tsx --outDir dist-ssr \ && bun --bun scripts/prerender.ts \ && bun --bun /app/packages/ui/bin/seo-compile.ts ./scripts/seo.config.ts --out dist-seo \ @@ -72,7 +72,7 @@ WORKDIR /app # ============================================================================ # Stage 3: runtime # ============================================================================ -FROM oven/bun:1.3.12-slim AS runner +FROM oven/bun:1.4.2-slim@sha256:cb3bbbb08e13a4a2ff400f24c7a2a1d5efa83f6ef8544d52d95a519631e2fc61 AS runner ARG LOCALE_COOKIE_DOMAIN= # Re-declare UI_DOCS_BASE_URL here so the runner stage can promote it to ENV; diff --git a/services/ui-docs/content/getting-started/installation.md b/services/ui-docs/content/getting-started/installation.md index 0ed9287e07..ebabfeaaed 100644 --- a/services/ui-docs/content/getting-started/installation.md +++ b/services/ui-docs/content/getting-started/installation.md @@ -32,7 +32,7 @@ For marketing components, also install `github:tale-project/tale#dist/marketing- For a reproducible release, replace the moving branch with a published `ui-v` tag and, when used, its matching `marketing-ui-v` tag. `` is a placeholder, not a tag to install literally. Commit the resulting lockfile. To deliberately refresh a moving Git dependency, use `bun install --force` and review the lockfile changes. -The packages' export maps point at TypeScript source. Run Vite through Bun (`bun --bun vite` and `bun --bun vite build`), as the Tale service scripts do. Use TypeScript's bundler module resolution and React JSX transform. Inside Tale-project repositories, select the appropriate shared `tsconfig` family rather than adding workspace-specific compiler options. +The packages' export maps point at TypeScript source. Run Vite through Bun (`bun --bun vite` for development and `bun --bun vite build` for a client build). In the Tale monorepo, use `bun run --filter @tale/ build` for the complete production build; its shared client helper waits for Vite plugins to finish before exiting. Use TypeScript's bundler module resolution and React JSX transform. Inside Tale-project repositories, select the appropriate shared `tsconfig` family rather than adding workspace-specific compiler options. ## Load Tailwind and YAML diff --git a/services/ui-docs/package.json b/services/ui-docs/package.json index 5616df7d2e..9b854d352a 100644 --- a/services/ui-docs/package.json +++ b/services/ui-docs/package.json @@ -7,8 +7,8 @@ "scripts": { "setup": "echo 'Dependencies managed by root workspace'", "dev": "bun --bun scripts/build-content.ts && bun --bun vite", - "build": "bun --bun scripts/build-content.ts && bun --bun vite build && bun --bun vite build --ssr app/entry-server.tsx --outDir dist-ssr && bun --bun scripts/prerender.ts && bun run seo:compile", - "build:client": "bun --bun vite build", + "build": "bun --bun scripts/build-content.ts && bun --bun ../../packages/ui/bin/build-client.ts && bun --bun vite build --ssr app/entry-server.tsx --outDir dist-ssr && bun --bun scripts/prerender.ts && bun run seo:compile", + "build:client": "bun --bun ../../packages/ui/bin/build-client.ts", "build:ssr": "bun --bun vite build --ssr app/entry-server.tsx --outDir dist-ssr", "build:content": "bun --bun scripts/build-content.ts", "prerender": "bun --bun scripts/prerender.ts", diff --git a/services/web/Dockerfile b/services/web/Dockerfile index 5d8a719c2c..fcdd50f486 100644 --- a/services/web/Dockerfile +++ b/services/web/Dockerfile @@ -1,7 +1,7 @@ # Tale Web Dockerfile — Vite SPA, no backend coupling ARG VERSION=dev -FROM oven/bun:1.3.12 AS bun-bin +FROM oven/bun:1.4.2@sha256:9114c058aeae42162ee16dd5084b95fe9473970bb6bcb5b232ab1630f0546895 AS bun-bin # ============================================================================ # Stage 1: workspace deps @@ -66,7 +66,7 @@ RUN bun --bun scripts/fetch-releases.ts --no-format \ # read legal markdown from `app/content/legal/` — neither source is available # in the runner stage, so these MUST run in the builder. (`bun run build` does # the first three; they are spelled out here to interleave seo-compile.) -RUN bun --bun vite build \ +RUN bun --bun ../../packages/ui/bin/build-client.ts \ && bun --bun vite build --ssr app/entry-server.tsx --outDir dist-ssr \ && bun --bun scripts/prerender.ts \ && bun --bun /app/packages/ui/bin/seo-compile.ts ./scripts/seo.config.ts --out dist-seo \ @@ -76,7 +76,7 @@ WORKDIR /app # ============================================================================ # Stage 3: runtime # ============================================================================ -FROM oven/bun:1.3.12-slim AS runner +FROM oven/bun:1.4.2-slim@sha256:cb3bbbb08e13a4a2ff400f24c7a2a1d5efa83f6ef8544d52d95a519631e2fc61 AS runner ARG LOCALE_COOKIE_DOMAIN= ENV NODE_ENV=production \ diff --git a/services/web/package.json b/services/web/package.json index b7b578408f..9e76334e8a 100644 --- a/services/web/package.json +++ b/services/web/package.json @@ -7,8 +7,8 @@ "scripts": { "setup": "echo 'Dependencies managed by root workspace'", "dev": "bun --bun vite", - "build": "bun run fetch-releases && bun --bun vite build && bun --bun vite build --ssr app/entry-server.tsx --outDir dist-ssr && bun --bun scripts/prerender.ts && bun run seo:compile", - "build:client": "bun --bun vite build", + "build": "bun run fetch-releases && bun --bun ../../packages/ui/bin/build-client.ts && bun --bun vite build --ssr app/entry-server.tsx --outDir dist-ssr && bun --bun scripts/prerender.ts && bun run seo:compile", + "build:client": "bun --bun ../../packages/ui/bin/build-client.ts", "build:ssr": "bun --bun vite build --ssr app/entry-server.tsx --outDir dist-ssr", "prerender": "bun --bun scripts/prerender.ts", "fetch-releases": "bun --bun scripts/fetch-releases.ts", diff --git a/services/web/playwright.config.ts b/services/web/playwright.config.ts index 8d37fa7480..bf9009a051 100644 --- a/services/web/playwright.config.ts +++ b/services/web/playwright.config.ts @@ -27,7 +27,9 @@ export default createPlaywrightConfig({ // also for SEO. The opt-in requires that output; ordinary local runs use // a client-only build, without networked release fetching in this budget. command: - (process.env.E2E_USE_BUILD === '1' ? '' : 'bun --bun vite build && ') + + (process.env.E2E_USE_BUILD === '1' + ? '' + : 'bun --bun ../../packages/ui/bin/build-client.ts && ') + `bun --bun vite preview --port ${PORT} --strictPort`, url: `http://localhost:${PORT}`, // Locally reuse an already-running `bun run dev`; in CI boot fresh. diff --git a/tools/cli/scripts/build-client.test.ts b/tools/cli/scripts/build-client.test.ts new file mode 100644 index 0000000000..54415f1f92 --- /dev/null +++ b/tools/cli/scripts/build-client.test.ts @@ -0,0 +1,80 @@ +import { describe, expect, test } from 'bun:test'; +import { spawnSync } from 'node:child_process'; +import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const helper = fileURLToPath( + new URL('../../../packages/ui/bin/build-client.ts', import.meta.url), +); +const marker = '[build-client] build resolved, exiting 0'; + +describe('client build process completion', () => { + test.each(['success', 'build failure', 'close failure'])( + '%s preserves Vite completion and exit status', + (outcome) => { + const cwd = mkdtempSync(join(tmpdir(), 'tale-client-build-')); + try { + writeFileSync( + join(cwd, 'index.html'), + '
selected service cwd
', + ); + writeFileSync( + join(cwd, 'main.js'), + 'document.getElementById("fixture").dataset.loaded = "true";', + ); + writeFileSync( + join(cwd, 'vite.config.mjs'), + ` + import { writeFile } from 'node:fs/promises'; + export default { + build: { outDir: 'service-output' }, + plugins: [{ + name: 'completion-fixture', + buildStart() { ${outcome === 'build failure' ? 'throw new Error("fixture build failure");' : ''} }, + async closeBundle() { + await new Promise(resolve => setTimeout(resolve, 100)); + ${outcome === 'close failure' ? 'throw new Error("fixture close failure");' : ''} + await writeFile('plugin-finished', 'all asynchronous output written'); + // The maintained helper must exit even when a plugin retains a handle. + setInterval(() => {}, 1000); + } + }] + }; + `, + ); + const result = spawnSync(process.execPath, ['--bun', helper], { + cwd, + encoding: 'utf8', + timeout: 15_000, + killSignal: 'SIGKILL', + maxBuffer: 1024 * 1024, + }); + expect(result.error).toBeUndefined(); + expect(result.signal).toBeNull(); + if (outcome === 'success') { + expect(result.status).toBe(0); + expect(result.stdout).toContain(marker); + expect(readFileSync(join(cwd, 'plugin-finished'), 'utf8')).toBe( + 'all asynchronous output written', + ); + expect( + readFileSync(join(cwd, 'service-output/index.html'), 'utf8'), + ).toContain('selected service cwd'); + } else { + expect(result.status).toBe(1); + expect(result.stdout).not.toContain(marker); + expect(result.stderr).toContain( + outcome === 'build failure' + ? 'fixture build failure' + : 'fixture close failure', + ); + } + } finally { + rmSync(cwd, { recursive: true, force: true }); + } + }, + 20_000, + ); +}); diff --git a/tools/cli/scripts/bun-toolchain.test.ts b/tools/cli/scripts/bun-toolchain.test.ts new file mode 100644 index 0000000000..b630a022fa --- /dev/null +++ b/tools/cli/scripts/bun-toolchain.test.ts @@ -0,0 +1,91 @@ +import { describe, expect, test } from 'bun:test'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const root = fileURLToPath(new URL('../../../', import.meta.url)); +const read = (file: string) => readFileSync(join(root, file), 'utf8'); +const version = JSON.parse(read('package.json')).packageManager.replace( + 'bun@', + '', +); +const clients = ['platform', 'web', 'docs', 'ui-docs', 'ai-gateway']; +const helper = '../../packages/ui/bin/build-client.ts'; + +describe('one pinned Bun toolchain for CI, builds and runtimes', () => { + test('every Docker consumer and generator pins the workspace version by digest', () => { + const files = [ + 'services/**/Dockerfile', + 'tools/plop/templates/**/Dockerfile.hbs', + ].flatMap((pattern) => + Array.from(new Bun.Glob(pattern).scanSync({ cwd: root })), + ); + const images = files.flatMap((file) => + [...read(file).matchAll(/^FROM\s+(oven\/bun:[^\s]+)\s/gm)].map( + (match) => ({ file, image: match[1]! }), + ), + ); + expect(new Set(images.map(({ file }) => file)).size).toBe(8); + const flavors = new Map(); + for (const { file, image } of images) { + const pin = + /^oven\/bun:(\d+\.\d+\.\d+)(-slim|-debian)?@sha256:([a-f0-9]{64})$/.exec( + image, + ); + expect(pin, `${file}: ${image}`).not.toBeNull(); + if (!pin) continue; + expect(pin[1], file).toBe(version); + const flavor = pin[2] ?? ''; + const previous = flavors.get(flavor); + if (previous !== undefined) expect(pin[3], file).toBe(previous); + flavors.set(flavor, pin[3]!); + } + expect(read('.github/actions/setup-turbo/action.yml')).toContain( + `default: '${version}'`, + ); + expect(read('.github/actions/setup-cli/action.yml')).toContain( + `bun-version: '${version}'`, + ); + }); + + test.each(clients)( + '%s production clients use the awaited helper before downstream commands', + (service) => { + const scripts = JSON.parse( + read(`services/${service}/package.json`), + ).scripts; + expect(scripts.build).toContain(`bun --bun ${helper}`); + if (scripts['build:client']) + expect(scripts['build:client']).toBe(`bun --bun ${helper}`); + const dockerfile = read(`services/${service}/Dockerfile`); + expect(dockerfile).toContain(`bun --bun ${helper}`); + expect(dockerfile).toContain('COPY packages/ui ./packages/ui'); + expect(dockerfile).toContain(`WORKDIR /app/services/${service}`); + expect(dockerfile).not.toMatch( + /bun --bun vite build(?:\s*\\?\s*(?:&&|$))/m, + ); + if (['web', 'docs', 'ui-docs'].includes(service)) { + expect(dockerfile).toContain( + 'bun --bun vite build --ssr app/entry-server.tsx --outDir dist-ssr', + ); + } + }, + ); + + test('new React services and local preview chains reuse the same helper', () => { + for (const file of ['Dockerfile.hbs', 'package.json.hbs']) + expect(read(`tools/plop/templates/service/react/${file}`)).toContain( + `bun --bun ${helper}`, + ); + for (const service of ['web', 'docs']) + expect(read(`services/${service}/playwright.config.ts`)).toContain( + `bun --bun ${helper}`, + ); + expect(read('services/platform/scripts/dev-engine.ts')).toContain( + `'${helper}'`, + ); + expect(read('services/ui-docs/playwright.config.ts')).toContain( + 'vite --strictPort', + ); + }); +}); diff --git a/tools/cli/scripts/ci-container-metadata.test.ts b/tools/cli/scripts/ci-container-metadata.test.ts index 81a81ef7eb..6f91f51989 100644 --- a/tools/cli/scripts/ci-container-metadata.test.ts +++ b/tools/cli/scripts/ci-container-metadata.test.ts @@ -10,6 +10,9 @@ const library = join( repository, 'services/platform/tests/integration/lib/docker.ts', ); +const expectedBun: string = JSON.parse( + await readFile(join(repository, 'package.json'), 'utf8'), +).packageManager.replace('bun@', ''); const temporary: string[] = []; afterEach(async () => { for (const directory of temporary.splice(0)) @@ -204,6 +207,8 @@ async function imageHarness( metadataFailure = '', gatewaySize = 255, runtimeHistory: { stdout?: string; exitCode?: number } = {}, + bunVersion = expectedBun, + bunExit = 0, ) { await writeFile( join(directory, 'docker'), @@ -231,6 +236,8 @@ elif args[:2] == ['image', 'history']: print(os.environ['RUNTIME_HISTORY']) sys.exit(int(os.environ['HISTORY_EXIT'])) elif args[0] == 'run': + if args[-2:] == ['bun', '--version']: + print(os.environ['BUN_VERSION']); sys.exit(int(os.environ['BUN_EXIT'])) if args[-2:] == ['-c', 'ls /app/system/providers | head -1; ls /app/builtin | head -1; stat -c %U /app/data']: print('provider\\nbuiltin\\napp') else: @@ -259,9 +266,39 @@ else: GATEWAY_SIZE: String(gatewaySize * 1024 * 1024), RUNTIME_HISTORY: runtimeHistory.stdout ?? '0\n1048576\n0', HISTORY_EXIT: String(runtimeHistory.exitCode ?? 0), + BUN_VERSION: bunVersion, + BUN_EXIT: String(bunExit), }); } +test.skipIf(process.platform === 'win32').each([ + ['stale binary', '1.3.12', 0], + ['missing output', '', 0], + ['failed version command', expectedBun, 7], +] as const)( + 'native image checks refuse %s', + async (_label, version, exitCode) => { + const directory = await fixture(); + const result = await imageHarness( + directory, + '', + '', + '', + '', + 255, + {}, + version, + exitCode, + ); + expect(result.exit).toBe(1); + for (const service of ['platform', 'sandbox', 'sandbox-runtime']) + expect(result.stdout).toContain( + `${service}: Bun runtime does not match ${expectedBun}`, + ); + expect(result.stdout).not.toContain('ALL IMAGE VALIDATION TESTS PASSED'); + }, +); + test.skipIf(process.platform === 'win32').each([ ['exact budget', `${6000 * 1024 * 1024}`, 0, '6000 MB ≤ 6000 MB budget'], [ @@ -397,8 +434,8 @@ test.skipIf(process.platform === 'win32').each([255, 300])( expect(result.stdout).toContain( `sandbox-llm-gateway: ${size} MB ≤ 300 MB budget`, ); - expect(result.stdout).toContain('Tests: 47'); - expect(result.stdout).toContain('Passed: 47'); + expect(result.stdout).toContain('Tests: 50'); + expect(result.stdout).toContain('Passed: 50'); for (const uid of [65534, 10001]) expect(result.stdout).toContain( `sandbox-runtime: SSH agent and HTTP CONNECT work as uid ${uid}`, @@ -430,8 +467,8 @@ test.skipIf(process.platform === 'win32').each([ expect(result.stdout).toContain( `sandbox-llm-gateway: ${sizeMb} MB ≤ 300 MB budget`, ); - expect(result.stdout).toContain('Tests: 47'); - expect(result.stdout).toContain('Passed: 47'); + expect(result.stdout).toContain('Tests: 50'); + expect(result.stdout).toContain('Passed: 50'); expect(result.stdout).toContain('Failed: 0'); expect(result.stdout).toContain('ALL IMAGE VALIDATION TESTS PASSED'); }, diff --git a/tools/cli/scripts/ci-performance.test.ts b/tools/cli/scripts/ci-performance.test.ts index 5a2941a0ee..731986d6b5 100644 --- a/tools/cli/scripts/ci-performance.test.ts +++ b/tools/cli/scripts/ci-performance.test.ts @@ -388,7 +388,7 @@ describe('static-site build reuse', () => { expect(server.command).not.toContain('build'); } else { expect(server.command).toContain( - service === 'web' ? 'vite build' : 'scripts/build-client.ts', + '../../packages/ui/bin/build-client.ts', ); if (service === 'docs') expect(server.command).toContain('scripts/build-search-index.ts'); diff --git a/tools/cli/scripts/turbo-dependencies.test.ts b/tools/cli/scripts/turbo-dependencies.test.ts index 63c9548bb8..928692f023 100644 --- a/tools/cli/scripts/turbo-dependencies.test.ts +++ b/tools/cli/scripts/turbo-dependencies.test.ts @@ -269,6 +269,40 @@ describe('dependency-aware Turbo cache', () => { tasks = new Map(repository.tasks.map((entry) => [entry.taskId, entry])); }, 60_000); + test('client builds and their regression guard hash the shared completion helper', () => { + for (const service of [ + 'platform', + 'web', + 'docs', + 'ui-docs', + 'ai-gateway', + ]) { + expect( + getTask(tasks, `@tale/${service}#build`).inputs[ + '../../packages/ui/bin/build-client.ts' + ], + service, + ).toBeDefined(); + } + const inputs = getTask(tasks, '@tale/cli#test').inputs; + for (const file of [ + 'packages/ui/bin/build-client.ts', + 'services/ui-docs/playwright.config.ts', + 'services/platform/scripts/dev-engine.ts', + 'tools/plop/templates/service/react/Dockerfile.hbs', + 'tools/plop/templates/service/react/package.json.hbs', + ]) { + expect( + inputs[ + relative(join(ROOT, 'tools/cli'), join(ROOT, file)) + .split(sep) + .join('/') + ], + file, + ).toBeDefined(); + } + }); + test('every root compiler configuration participates in the global hash', async () => { const files = (await readdir(ROOT)).filter((name) => /^tsconfig.*\.json$/.test(name), diff --git a/tools/cli/turbo.json b/tools/cli/turbo.json index f674f9b476..2305448277 100644 --- a/tools/cli/turbo.json +++ b/tools/cli/turbo.json @@ -49,6 +49,8 @@ "$TURBO_ROOT$/configs/platform/custom/skills/*/turbo.json", "$TURBO_ROOT$/services/web/playwright.config.ts", "$TURBO_ROOT$/services/docs/playwright.config.ts", + "$TURBO_ROOT$/services/ui-docs/playwright.config.ts", + "$TURBO_ROOT$/services/platform/scripts/dev-engine.ts", "$TURBO_ROOT$/services/platform/vitest.ui.config.ts", "$TURBO_ROOT$/services/platform/postcss.config.mjs", "$TURBO_ROOT$/packages/ui/src/vite/yaml.ts", @@ -130,7 +132,10 @@ "$TURBO_ROOT$/.github/actions/ci-scope/action.yml", "$TURBO_ROOT$/.github/actions/ci-ready/action.yml", "$TURBO_ROOT$/.gitattributes", - "$TURBO_ROOT$/.github/release-candidate-contract.json" + "$TURBO_ROOT$/.github/release-candidate-contract.json", + "$TURBO_ROOT$/packages/ui/bin/build-client.ts", + "$TURBO_ROOT$/tools/plop/templates/service/react/Dockerfile.hbs", + "$TURBO_ROOT$/tools/plop/templates/service/react/package.json.hbs" ], "dependsOn": ["generate", "transit"] }, diff --git a/tools/plop/templates/service/react/Dockerfile.hbs b/tools/plop/templates/service/react/Dockerfile.hbs index 66fa1822b8..d1969dc3b1 100644 --- a/tools/plop/templates/service/react/Dockerfile.hbs +++ b/tools/plop/templates/service/react/Dockerfile.hbs @@ -1,7 +1,7 @@ # Tale {{upperFirst name}} Dockerfile — Vite SPA, no backend coupling ARG VERSION=dev -FROM oven/bun:1.3.12 AS bun-bin +FROM oven/bun:1.4.2@sha256:9114c058aeae42162ee16dd5084b95fe9473970bb6bcb5b232ab1630f0546895 AS bun-bin # ============================================================================ # Stage 1: workspace deps @@ -59,14 +59,14 @@ WORKDIR /app/services/{{kebabCase name}} # stage carries no `node_modules`, so every import `server.ts` makes — # `@tale/ui/server`, the service's own modules, its dependencies — has to # be inlined here (the pattern `services/web` and `services/docs` use). -RUN bun --bun vite build \ +RUN bun --bun ../../packages/ui/bin/build-client.ts \ && bun build server.ts --target=bun --outfile=server.js --external bun WORKDIR /app # ============================================================================ # Stage 3: runtime # ============================================================================ -FROM oven/bun:1.3.12-slim AS runner +FROM oven/bun:1.4.2-slim@sha256:cb3bbbb08e13a4a2ff400f24c7a2a1d5efa83f6ef8544d52d95a519631e2fc61 AS runner ENV NODE_ENV=production \ PORT={{port}} \ diff --git a/tools/plop/templates/service/react/package.json.hbs b/tools/plop/templates/service/react/package.json.hbs index 4e043bf735..0ead8b8c9a 100644 --- a/tools/plop/templates/service/react/package.json.hbs +++ b/tools/plop/templates/service/react/package.json.hbs @@ -7,7 +7,7 @@ "scripts": { "setup": "echo 'Dependencies managed by root workspace'", "dev": "bun --bun vite", - "build": "bun --bun vite build", + "build": "bun --bun ../../packages/ui/bin/build-client.ts", "start": "bun server.ts", "lint": "bunx oxlint --type-aware", "lint:fix": "bunx oxlint --type-aware --fix", diff --git a/turbo.json b/turbo.json index 4faba03442..5ac82de2da 100644 --- a/turbo.json +++ b/turbo.json @@ -23,7 +23,11 @@ }, "build": { "dependsOn": ["^build"], - "outputs": ["dist/**"] + "outputs": ["dist/**"], + "inputs": [ + "$TURBO_DEFAULT$", + "$TURBO_ROOT$/packages/ui/bin/build-client.ts" + ] }, "@tale/db#build": { "outputs": []