Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

ralph(M14-202): CLEAN: the Bun version pin asserted where ADR-016 rule 5 says it must be - .bun-version, a scripts/doctor.sh that does not currently exist at all, and a boot log line

ralph67a731daa079
diff --git a/.bun-version b/.bun-version
new file mode 100644
index 000000000..88c5fb891
--- /dev/null
+++ b/.bun-version
@@ -0,0 +1 @@
+1.4.0
diff --git a/apps/api/src/config/bun-version.test.ts b/apps/api/src/config/bun-version.test.ts
new file mode 100644
index 000000000..fd72d6b32
--- /dev/null
+++ b/apps/api/src/config/bun-version.test.ts
@@ -0,0 +1,47 @@
+import { readFileSync } from 'node:fs';
+import { join } from 'node:path';
+import { describe, expect, it } from 'bun:test';
+
+// ADR-016 rule 5 wants the Bun pin asserted in three places: .bun-version,
+// scripts/doctor.sh, and a boot log line — and all three must agree with
+// each other and with the Dockerfile's ARG BUN_VERSION. A test proving that
+// is worth more than the three edits it checks.
+const REPO_ROOT = join(import.meta.dir, '../../../..');
+
+function readBunVersionFile(): string {
+ return readFileSync(join(REPO_ROOT, '.bun-version'), 'utf8');
+}
+
+describe('the Bun pin (ADR-016 rule 5)', () => {
+ it('.bun-version is one line, no prefix', () => {
+ const raw = readBunVersionFile();
+ expect(raw.trim().split('\n')).toHaveLength(1);
+ expect(raw.trim()).toMatch(/^\d+\.\d+\.\d+$/);
+ });
+
+ it('matches the Dockerfile ARG BUN_VERSION', () => {
+ const dockerfile = readFileSync(
+ join(REPO_ROOT, 'apps/api/Dockerfile'),
+ 'utf8'
+ );
+ const match = dockerfile.match(/^ARG BUN_VERSION=(\S+)$/m);
+ expect(match?.[1]).toBe(readBunVersionFile().trim());
+ });
+
+ it('scripts/doctor.sh passes and reports the pinned version', () => {
+ // Runs the real script rather than grepping its source — the behaviour
+ // is what has to agree, not the implementation.
+ const result = Bun.spawnSync(['bash', join(REPO_ROOT, 'scripts/doctor.sh')]);
+ const pinned = readBunVersionFile().trim();
+ expect(result.exitCode).toBe(0);
+ expect(result.stdout.toString()).toContain(pinned);
+ });
+
+ it('apps/api logs the running Bun version at boot', () => {
+ const mainTs = readFileSync(
+ join(REPO_ROOT, 'apps/api/src/main.ts'),
+ 'utf8'
+ );
+ expect(mainTs).toMatch(/Bun\.version/);
+ });
+});
diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts
index f03cfdb7e..d8af2b7e2 100644
--- a/apps/api/src/main.ts
+++ b/apps/api/src/main.ts
@@ -594,7 +594,15 @@ async function main() {
: { port: config.API_PORT };
app.listen(listen, () => {
logger.info(
- { role, port: config.API_PORT, hostname: config.API_HOST ?? '0.0.0.0' },
+ {
+ role,
+ port: config.API_PORT,
+ hostname: config.API_HOST ?? '0.0.0.0',
+ // ADR-016 rule 5: the running Bun version, asserted against
+ // .bun-version by scripts/doctor.sh — logged so a wrong-runtime
+ // incident is one log line away rather than an inference.
+ bunVersion: Bun.version,
+ },
'API listening'
);
});
diff --git a/docs/TECH_DEBT.md b/docs/TECH_DEBT.md
index 4812d6b2f..67810ceb6 100644
--- a/docs/TECH_DEBT.md
+++ b/docs/TECH_DEBT.md
@@ -1622,6 +1622,12 @@ space cannot scope a version to one importer — see the recipe.
tree and `scripts/doctor.sh` has no bun check. Creating them is outside
M13-002's scope (it touches neither a manifest nor the lockfile); it belongs
with M13-003's Dockerfile work or a CLEAN task.
+ **RESOLVED by M14-202 (2026-09-08)** — `.bun-version` (`1.4.0`) and
+ `scripts/doctor.sh` both created; `apps/api/src/main.ts`'s "API listening"
+ log line gained `bunVersion: Bun.version`. All three now agree with each
+ other and with the Dockerfile `ARG`, proven by
+ `apps/api/src/config/bun-version.test.ts` rather than by inspection. See the
+ M14-202 section at the end of this file.
- **The root `package-lock.json` is still tracked.** ADR-014 says it should be
deleted in the same commit as the lockfile swap ("tracked, stale, and a trap
for any scanner or contributor running `npm ci`"). It is outside M13-002's
@@ -1736,6 +1742,8 @@ templates so a self-hoster reading the file sees it.
- **`.bun-version` still does not exist.** ADR-016 names it as Bun's declared
home alongside `ARG BUN_VERSION`; both Dockerfiles carry the ARG and nothing
carries the file. Unchanged from M13-002's note.
+ **RESOLVED by M14-202 (2026-09-08)** — see the note against the same item
+ in the M13-002 section above.
- **Both images now `COPY . .` and install the whole workspace**, which is the
shape ADR-014 Problems §4 rules for a bun-base image. The cost is that a
source edit invalidates the install layer, so neither image has a
@@ -1993,3 +2001,45 @@ With the fixtures removed the count returns to 23.
it fell outside M13-002's scope globs and survived. `lockfileVersion 2`, 359
entries, one commit ever, still listing `winston` (removed) and `[email protected]`.
Nothing reads it — `bun.lock` is the lockfile.
+
+## 2026-09-08 — M14-202, the Bun pin asserted at all three ADR-016 rule 5 places
+
+Ran by: ralph (M14-202 implement task), on this box, 2026-09-08.
+
+Before this task: `.bun-version` did not exist, `scripts/doctor.sh` did not
+exist at all (not merely "no bun check", as the M13-002 note understated it),
+and only `apps/api/Dockerfile:4`'s `ARG BUN_VERSION=1.4.0` carried the pin.
+`package.json`'s `devEngines.packageManager` (`bun >=1.4.0`, `onFail: warn`)
+is a range with a warning, not an asserted exact pin, so it was left as is —
+not deleted, not duplicated — per the task's own note that it must simply
+agree with the three new places.
+
+**What landed:**
+
+- `.bun-version` — one line, `1.4.0`, no prefix.
+- `scripts/doctor.sh` — a developer preflight, in the style of
+ `tooling/gates/p13-drift.sh` and `apps/api/e2e/boot-proof.sh`: reads
+ `.bun-version`, compares it against `bun --version`, exits non-zero naming
+ both versions on a mismatch. It is **not** referenced from `verification/`
+ or any gate — ADR-016 rule 5 asks for a preflight, not a gate.
+- `apps/api/src/main.ts` — the existing "API listening" boot log (the one
+ line that already carried `role`) gained a `bunVersion: Bun.version` field.
+ No other behaviour change.
+- `apps/api/src/config/bun-version.test.ts` — the "worth more than the three
+ edits" check ADR-016 asked for: asserts `.bun-version` is one line matching
+ `\d+\.\d+\.\d+`, that it equals the Dockerfile's `ARG BUN_VERSION`, that
+ running `scripts/doctor.sh` actually exits 0 and reports the pinned version
+ (spawned for real, not grepped), and that `main.ts` logs `Bun.version`.
+
+**Verification run on this box, 2026-09-08:**
+
+- `bash scripts/doctor.sh` → `OK: bun 1.4.0 matches the pinned version
+ (1.4.0)`, exit 0.
+- `bash -c 'grep -q "$(cat .bun-version)" apps/api/Dockerfile'` → match.
+- `bun run typecheck` (root) → `typecheck: 17/17 passed`.
+- `cd packages/core && bun test` → `1475 pass, 12 skip, 0 fail` (1487 tests,
+ 154 files).
+- `cd apps/api && bun test --isolate` → `17 pass, 0 fail` (2 files), including
+ the new `bun-version.test.ts`.
+
+No ClickHouse SQL touched; no lockfile or manifest changed.
diff --git a/scripts/doctor.sh b/scripts/doctor.sh
new file mode 100755
index 000000000..438e0c098
--- /dev/null
+++ b/scripts/doctor.sh
@@ -0,0 +1,58 @@
+#!/usr/bin/env bash
+# Developer preflight (ADR-016 rule 5) — checks the Bun actually running on
+# this machine against the version this repo pins, and fails loudly rather
+# than silently drifting the way `bootstrap.sh`'s unversioned install could.
+#
+# NOT a gate: nothing under verification/ calls this script, and it must stay
+# that way (ADR-016 rule 5 asserts the pin at three places — this is one of
+# them, not the mechanism that enforces the other two).
+#
+# Run from anywhere: `bash scripts/doctor.sh`.
+
+set -uo pipefail
+
+REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+cd "$REPO_ROOT" || exit 1
+
+FAILURES=0
+
+pass() { echo "OK: $1"; }
+fail() {
+ echo "FAIL: $1"
+ FAILURES=$((FAILURES + 1))
+}
+
+check_bun_version() {
+ if [[ ! -f .bun-version ]]; then
+ fail ".bun-version is missing — ADR-016 rule 5 requires it as the pin's home"
+ return
+ fi
+
+ local pinned
+ pinned="$(<.bun-version)"
+ pinned="${pinned//$'\n'/}"
+
+ if ! command -v bun >/dev/null 2>&1; then
+ fail "no bun on PATH — this repo pins bun $pinned (ADR-016)"
+ return
+ fi
+
+ local actual
+ actual="$(bun --version)"
+ if [[ "$actual" == "$pinned" ]]; then
+ pass "bun $actual matches the pinned version ($pinned)"
+ else
+ fail "bun $actual does not match the pinned version $pinned (ADR-016) — install $pinned, or bump .bun-version deliberately alongside apps/api/Dockerfile's ARG BUN_VERSION"
+ fi
+}
+
+check_bun_version
+
+echo
+if [[ "$FAILURES" -eq 0 ]]; then
+ echo "doctor.sh: all checks passed"
+ exit 0
+else
+ echo "doctor.sh: $FAILURES failure(s)"
+ exit 1
+fi