diff --git a/.bun-version b/.bun-version new file mode 100644 index 0000000000..1c99cf0e80 --- /dev/null +++ b/.bun-version @@ -0,0 +1 @@ +1.4.4 diff --git a/.github/workflows/backend-review.yml b/.github/workflows/backend-review.yml index ce4c2a5c11..9d11d37419 100644 --- a/.github/workflows/backend-review.yml +++ b/.github/workflows/backend-review.yml @@ -12,6 +12,7 @@ on: - 'packages/**' - 'package.json' - 'package-lock.json' + - '.bun-version' - 'config/circular-deps.mjs' - '.github/workflows/backend-review.yml' - '!**.md' @@ -21,6 +22,7 @@ on: - 'packages/**' - 'package.json' - 'package-lock.json' + - '.bun-version' - 'config/circular-deps.mjs' - '.github/workflows/backend-review.yml' - '!**.md' @@ -301,10 +303,10 @@ jobs: name: build-api path: packages/api/dist - - name: Use Bun 1.4.3 + - name: Use pinned Bun uses: oven-sh/setup-bun@v2 with: - bun-version: '1.4.3' + bun-version-file: .bun-version - name: Type check data-provider run: bun check -p packages/data-provider/tsconfig.json diff --git a/.github/workflows/frontend-review.yml b/.github/workflows/frontend-review.yml index d8218e0d0b..aab06be1aa 100644 --- a/.github/workflows/frontend-review.yml +++ b/.github/workflows/frontend-review.yml @@ -11,6 +11,7 @@ on: - 'scripts/typecheck.mts' - 'package.json' - 'package-lock.json' + - '.bun-version' - '.github/workflows/frontend-review.yml' - '!**.md' # Post-merge safety net and full-run baseline for gated selection (same rationale as @@ -27,6 +28,7 @@ on: - 'scripts/typecheck.mts' - 'package.json' - 'package-lock.json' + - '.bun-version' - '.github/workflows/frontend-review.yml' # Promotion requires full CI at the exact dev SHA, including path-filtered commits. workflow_dispatch: @@ -286,10 +288,10 @@ jobs: name: build-chat-package path: packages/chat/dist - - name: Use Bun 1.4.3 + - name: Use pinned Bun uses: oven-sh/setup-bun@v2 with: - bun-version: '1.4.3' + bun-version-file: .bun-version - name: Type check client run: npm run typecheck @@ -337,10 +339,10 @@ jobs: name: build-client-package path: packages/client/dist - - name: Use Bun 1.4.3 + - name: Use pinned Bun uses: oven-sh/setup-bun@v2 with: - bun-version: '1.4.3' + bun-version-file: .bun-version - name: Type check run: npm run typecheck diff --git a/e2e/specs/mock/scenarios/typecheck.spec.ts b/e2e/specs/mock/scenarios/typecheck.spec.ts index 02412d3083..2ce5e9e471 100644 --- a/e2e/specs/mock/scenarios/typecheck.spec.ts +++ b/e2e/specs/mock/scenarios/typecheck.spec.ts @@ -5,11 +5,13 @@ import { mkdirSync, mkdtempSync, readFileSync, + readdirSync, rmSync, writeFileSync, } from 'node:fs'; import { dirname, join, resolve } from 'node:path'; import { tmpdir } from 'node:os'; +import yaml from 'js-yaml'; import { expect, test } from '@playwright/test'; import { inOneProject, repoRoot, staticChecks } from './lint.helpers'; @@ -52,7 +54,7 @@ function fakeBun(bin: string, log: string, helpStatus: number, checkStatus: numb path, [ '#!/bin/sh', - `echo "$@" >> '${log}'`, + `printf '%s: %s\\n' "$PWD" "$*" >> '${log}'`, `if [ "$2" = "--help" ]; then exit ${helpStatus}; fi`, `exit ${checkStatus}`, '', @@ -101,6 +103,9 @@ test.describe('the shared type checker', () => { try { const failing = typecheck(broken.bin, broken.project); expect(failing.output).toContain('falling back to tsc'); + expect(failing.output).toContain( + `install Bun ${readFileSync(join(repoRoot, '.bun-version'), 'utf8').trim()}`, + ); expect(failing.output).toContain('TS2322'); expect(failing.status, 'the fallback hid a type error').not.toBe(0); @@ -130,6 +135,75 @@ test.describe('the shared type checker', () => { } }); + test('the root command checks every TypeScript workspace and the chat test project @scenario:root-typecheck-covers-all-workspaces', () => { + const { dir, bin } = scratch('export const value: number = 1;\n'); + const log = join(dir, 'bun.log'); + try { + fakeBun(bin, log, 0, 0); + const run = () => + spawnSync('npm', ['run', 'typecheck', '--silent'], { + cwd: repoRoot, + encoding: 'utf8', + env: { ...process.env, PATH: `${bin}:${dirname(process.execPath)}:/usr/bin:/bin` }, + }); + const passing = run(); + expect(passing.status, `${passing.stdout}${passing.stderr}`).toBe(0); + + const projects = [ + 'client', + ...readdirSync(join(repoRoot, 'packages')).map((name) => `packages/${name}`), + ].filter((path) => existsSync(join(repoRoot, path, 'tsconfig.json'))); + const checked = logged(log) + .trim() + .split('\n') + .filter((line) => line.includes(': check') && !line.includes('--help')); + expect(checked.sort()).toEqual( + [ + ...projects.map((path) => `${join(repoRoot, path)}: check`), + `${join(repoRoot, 'packages/chat')}: check -p test/tsconfig.json`, + ].sort(), + ); + + fakeBun(bin, log, 0, 1); + const failing = run(); + expect(failing.status, 'the root command hid a workspace type error').not.toBe(0); + expect(`${failing.stdout}${failing.stderr}`).not.toContain('falling back to tsc'); + } finally { + rmSync(dir, { force: true, recursive: true }); + } + }); + + test('CI and local tooling share the Bun 1.4.4 pin @scenario:typecheck-shares-bun-version-pin', () => { + expect(readFileSync(join(repoRoot, '.bun-version'), 'utf8').trim()).toBe('1.4.4'); + const workflows = readdirSync(join(repoRoot, '.github/workflows')).filter((file) => + /\.ya?ml$/.test(file), + ); + let setupCount = 0; + for (const file of workflows) { + const workflow = yaml.load( + readFileSync(join(repoRoot, '.github/workflows', file), 'utf8'), + ) as { + on: Record; + jobs: Record }[] }>; + }; + const setups = Object.values(workflow.jobs).flatMap((job) => + (job.steps ?? []).filter((step) => step.uses?.startsWith('oven-sh/setup-bun@')), + ); + if (setups.length === 0) continue; + setupCount += setups.length; + for (const setup of setups) { + expect(setup.with?.['bun-version-file'], file).toBe('.bun-version'); + expect(setup.with?.['bun-version'], file).toBeUndefined(); + } + for (const event of ['push', 'pull_request']) { + expect(workflow.on[event].paths, `${file}: ${event}`).toContain('.bun-version'); + } + } + expect(setupCount).toBe(3); + const listed = staticChecks(['.bun-version', '--list', '--full']); + expect(listed.output).toMatch(/TypeScript \(typecheck\)\s+would run/); + }); + test('a change to the shared checker alone selects the TypeScript gate @scenario:a-checker-only-change-selects-the-typecheck-gate', () => { const listed = staticChecks(['scripts/typecheck.mts', '--list', '--full']); expect(listed.output).toMatch(/TypeScript \(typecheck\)\s+would run/); diff --git a/package.json b/package.json index 13d8f07c3c..b0f8f6ee3f 100644 --- a/package.json +++ b/package.json @@ -124,6 +124,7 @@ "sort-imports:check": "node scripts/sort-imports.mts --check", "static-checks": "node scripts/static-checks.mts", "static-checks:full": "node scripts/static-checks.mts --full", + "typecheck": "npm run typecheck --workspaces --if-present", "format": "npx prettier --write \"{,!(node_modules|venv)/**/}*.{js,jsx,ts,tsx}\"", "b:api": "NODE_ENV=production bun run api/server/index.js", "b:api-inspect": "NODE_ENV=production bun --inspect run api/server/index.js", diff --git a/packages/api/package.json b/packages/api/package.json index 1eb36c2405..c111872310 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -30,6 +30,7 @@ "build": "npm run clean && tsdown && npm run openapi:copy", "build:dev": "npm run clean && tsdown && npm run openapi:copy", "build:watch": "npm run openapi:copy && tsdown --watch", + "typecheck": "node ../../scripts/typecheck.mts", "build:watch:prod": "npm run openapi:copy && tsdown --watch", "openapi:copy": "node -e \"const fs=require('fs');fs.mkdirSync('dist',{recursive:true});fs.copyFileSync('openapi/agents.openapi.json','dist/agents.openapi.json')\"", "test": "jest --coverage --watch --testPathIgnorePatterns=\"\\.*integration\\.|\\.*helper\\.|__tests__/helpers/|\\.*manual\\.spec\\.\"", diff --git a/packages/client/package.json b/packages/client/package.json index 66e4395aff..d62e2ada98 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -37,6 +37,7 @@ "build:dev": "npm run clean && NODE_ENV=development tsdown", "b:build": "bun run b:clean && bun run tsdown", "build:watch": "tsdown --watch", + "typecheck": "node ../../scripts/typecheck.mts", "dev": "tsdown --watch", "test": "jest", "test:ci": "jest --ci" diff --git a/packages/data-provider/package.json b/packages/data-provider/package.json index 110fda4cb3..e2e3863865 100644 --- a/packages/data-provider/package.json +++ b/packages/data-provider/package.json @@ -25,6 +25,7 @@ "clean": "rimraf dist", "build": "npm run clean && tsdown && tsc -p tsconfig.build.json", "build:watch": "tsdown --watch", + "typecheck": "node ../../scripts/typecheck.mts", "test": "jest --coverage --watch", "test:ci": "jest --coverage --ci --logHeapUsage", "verify": "npm run test:ci", diff --git a/packages/data-schemas/package.json b/packages/data-schemas/package.json index 675f79120a..9d4f4dd44b 100644 --- a/packages/data-schemas/package.json +++ b/packages/data-schemas/package.json @@ -36,6 +36,7 @@ "clean": "rimraf dist", "build": "npm run clean && tsdown", "build:watch": "tsdown --watch", + "typecheck": "node ../../scripts/typecheck.mts", "test": "jest --coverage --watch", "test:ci": "jest --coverage --ci", "verify": "npm run test:ci", diff --git a/scripts/static-checks.mts b/scripts/static-checks.mts index 6591a664db..e1a2a5d7a2 100644 --- a/scripts/static-checks.mts +++ b/scripts/static-checks.mts @@ -151,6 +151,7 @@ const FILTERS = { 'packages/**', 'package.json', 'package-lock.json', + '.bun-version', 'config/circular-deps.mjs', '.github/workflows/backend-review.yml', '!**.md', @@ -161,6 +162,7 @@ const FILTERS = { 'client/**', 'packages/**', 'scripts/typecheck.mts', + '.bun-version', 'package.json', 'package-lock.json', '.github/workflows/backend-review.yml', @@ -1856,6 +1858,7 @@ const ROOT_MANIFESTS = ['package.json', 'package-lock.json']; /** The checker every project runs through, so a change to it rechecks them all. */ const TYPECHECK_SCRIPT = 'scripts/typecheck.mts'; +const BUN_VERSION_FILE = '.bun-version'; /** Each imported gate reruns in CI when its owning workflow changes. */ const BACKEND_REVIEW = '.github/workflows/backend-review.yml'; @@ -1868,6 +1871,7 @@ const TYPECHECK_PROJECTS = [ 'packages/data-provider/**', ...ROOT_MANIFESTS, TYPECHECK_SCRIPT, + BUN_VERSION_FILE, BACKEND_REVIEW, '!**.md', ], @@ -1880,6 +1884,7 @@ const TYPECHECK_PROJECTS = [ 'packages/data-schemas/**', ...ROOT_MANIFESTS, TYPECHECK_SCRIPT, + BUN_VERSION_FILE, BACKEND_REVIEW, '!**.md', ], @@ -1893,6 +1898,7 @@ const TYPECHECK_PROJECTS = [ 'packages/api/**', ...ROOT_MANIFESTS, TYPECHECK_SCRIPT, + BUN_VERSION_FILE, BACKEND_REVIEW, '!**.md', ], @@ -1905,6 +1911,7 @@ const TYPECHECK_PROJECTS = [ 'packages/client/**', ...ROOT_MANIFESTS, TYPECHECK_SCRIPT, + BUN_VERSION_FILE, BACKEND_REVIEW, '!**.md', ], @@ -1918,6 +1925,7 @@ const TYPECHECK_PROJECTS = [ 'packages/chat/**', ...ROOT_MANIFESTS, TYPECHECK_SCRIPT, + BUN_VERSION_FILE, FRONTEND_REVIEW, '!**.md', ], @@ -1932,6 +1940,7 @@ const TYPECHECK_PROJECTS = [ 'packages/chat/**', ...ROOT_MANIFESTS, TYPECHECK_SCRIPT, + BUN_VERSION_FILE, FRONTEND_REVIEW, '!**.md', ], diff --git a/scripts/typecheck.mts b/scripts/typecheck.mts index 09e0ef9a0c..4ec895222a 100644 --- a/scripts/typecheck.mts +++ b/scripts/typecheck.mts @@ -44,7 +44,9 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) { process.exit(1); } if (typecheck.checker === 'tsc') { - console.error('typecheck: `bun check` is unavailable, falling back to tsc'); + console.error( + 'typecheck: `bun check` is unavailable, falling back to tsc; install Bun 1.4.4 for faster checks', + ); } const result = spawnSync(typecheck.command, [...typecheck.args, ...process.argv.slice(2)], { stdio: 'inherit',