Migrate test runner from vitest to bun:test #601

Closed
opened 2026-06-02 10:47:17 +00:00 by xingyue · 0 comments
Owner

Problem

pre-push hook runs bun run test which invokes vitest run in each package. Vitest forks Node.js workers to execute tests, but @ocas/core uses bun:sqlite which is a Bun-only API. This causes 21 test suites to fail in any package that transitively imports @ocas/core.

This is not a test bug — the tests pass fine under Bun runtime. The mismatch is vitest (Node) vs bun:sqlite (Bun-only).

Solution

Migrate all 8 packages from vitest to bun:test.

Scope

  • 47 test files across 8 packages import from "vitest"
  • 44 files: only use describe/test/expect/beforeEach/afterEach — direct drop-in replacement (from "vitest"from "bun:test")
  • 3 files use vi.spyOn / vi.restoreAllMocks (all in cli-workflow):
    • setup-agent-discovery.test.ts
    • setup-complexity.test.ts
    • setup-validate.test.ts
    • → Replace with import { mock, spyOn } from "bun:test"
  • 1 file already uses bun:test: workflow-agent-builtin/__tests__/loop.test.ts

Per-package changes

  1. Replace "test": "vitest run""test": "bun test" in each package.json
  2. Delete vitest.config.ts from each package
  3. Replace from "vitest"from "bun:test" in all test files
  4. For vi.spyOnspyOn from bun:test; vi.restoreAllMocks()mock.restore()
  5. Remove vitest from root devDependencies
  6. Configure test file patterns if needed (cli-workflow tests are in src/__tests__/)

Packages affected

Package Test files Has vi.spyOn
cli-workflow 33 (3 files)
workflow-util 2
workflow-util-agent 8
workflow-protocol 2
workflow-agent-hermes 5
workflow-agent-claude-code 2
workflow-agent-builtin 3 (1 already bun:test)
workflow-dashboard 3

Verification

bun run test  # all packages pass

Notes

  • bun:test has near-identical API to vitest for basic usage
  • vi.spyOnspyOn, vi.fn()mock(), vi.restoreAllMocks()mock.restore()
  • legacy-packages/ are archived and NOT in scope
## Problem `pre-push` hook runs `bun run test` which invokes `vitest run` in each package. Vitest forks Node.js workers to execute tests, but `@ocas/core` uses `bun:sqlite` which is a Bun-only API. This causes **21 test suites to fail** in any package that transitively imports `@ocas/core`. This is not a test bug — the tests pass fine under Bun runtime. The mismatch is vitest (Node) vs bun:sqlite (Bun-only). ## Solution Migrate all 8 packages from vitest to `bun:test`. ### Scope - **47 test files** across 8 packages import from `"vitest"` - **44 files**: only use `describe/test/expect/beforeEach/afterEach` — direct drop-in replacement (`from "vitest"` → `from "bun:test"`) - **3 files** use `vi.spyOn` / `vi.restoreAllMocks` (all in `cli-workflow`): - `setup-agent-discovery.test.ts` - `setup-complexity.test.ts` - `setup-validate.test.ts` - → Replace with `import { mock, spyOn } from "bun:test"` - **1 file** already uses `bun:test`: `workflow-agent-builtin/__tests__/loop.test.ts` ### Per-package changes 1. Replace `"test": "vitest run"` → `"test": "bun test"` in each `package.json` 2. Delete `vitest.config.ts` from each package 3. Replace `from "vitest"` → `from "bun:test"` in all test files 4. For `vi.spyOn` → `spyOn` from `bun:test`; `vi.restoreAllMocks()` → `mock.restore()` 5. Remove `vitest` from root devDependencies 6. Configure test file patterns if needed (cli-workflow tests are in `src/__tests__/`) ### Packages affected | Package | Test files | Has vi.spyOn | |---------|-----------|-------------| | cli-workflow | 33 | ✅ (3 files) | | workflow-util | 2 | ❌ | | workflow-util-agent | 8 | ❌ | | workflow-protocol | 2 | ❌ | | workflow-agent-hermes | 5 | ❌ | | workflow-agent-claude-code | 2 | ❌ | | workflow-agent-builtin | 3 | ❌ (1 already bun:test) | | workflow-dashboard | 3 | ❌ | ### Verification ```bash bun run test # all packages pass ``` ### Notes - `bun:test` has near-identical API to vitest for basic usage - `vi.spyOn` → `spyOn`, `vi.fn()` → `mock()`, `vi.restoreAllMocks()` → `mock.restore()` - `legacy-packages/` are archived and NOT in scope
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#601