Skip to content

Feature/migrate-to-bun-test#86

Merged
11gather11 merged 10 commits intomainfrom
feature/migrate-to-bun-test
Dec 22, 2025
Merged

Feature/migrate-to-bun-test#86
11gather11 merged 10 commits intomainfrom
feature/migrate-to-bun-test

Conversation

@11gather11
Copy link
Copy Markdown
Contributor

@11gather11 11gather11 commented Dec 22, 2025

fix: update worker-configuration.d.ts for workerd version and modify WorkerLoader interface
delete: remove tsconfig.build.json as it's no longer needed

Summary

Changes

Test Plan

  • Type check passed: bun run typecheck
  • Manual testing completed:

Related Issues

Notes

Summary by CodeRabbit

  • Chores
    • Enhanced CI/CD pipeline with automated test coverage reporting to Codecov
    • Improved error handling in coverage verification steps
    • Updated type definitions to support optional configuration parameters and flexible input handling

✏️ Tip: You can customize this high-level summary in your review settings.

11gather11 and others added 5 commits December 22, 2025 10:03
- Updated bunfig.toml to include preload for test setup.
- Changed test scripts in package.json to use Bun instead of Vitest.
- Removed unused env.d.ts file and adjusted imports in test files to use the new setup.
- Implemented a new D1DatabaseAdapter for in-memory SQLite testing.
- Removed vitest.config.ts and replaced it with Bun-compatible test configurations.
…oad step

fix: change database execution method in test setup from exec to run
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…imports in client.ts

fix: update worker-configuration.d.ts for workerd version and modify WorkerLoader interface
delete: remove tsconfig.build.json as it's no longer needed
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Dec 22, 2025

⚠️ No Changeset found

Latest commit: d3bbbdb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 22, 2025

Warning

Rate limit exceeded

@11gather11 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 6 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 818c498 and d3bbbdb.

📒 Files selected for processing (3)
  • .github/workflows/ci.yml
  • .github/workflows/pull_request.yml
  • src/__tests__/d1-adapter.ts

Walkthrough

This PR updates CI/CD workflows to execute tests with coverage reporting, replaces async glob with Bun's synchronous globbing API, migrates D1 adapter exec to use Bun-native batch execution, reorders client route imports, removes a TypeScript build config file, and updates worker-configuration.d.ts type signatures to accept nullable names and optional tags.

Changes

Cohort / File(s) Summary
GitHub Actions Workflows
.github/workflows/ci.yml, .github/workflows/pull_request.yml
Added test execution step with coverage reporter and Codecov upload step with fail_ci_if_error enabled; added fail_ci_if_error flag to existing Codecov upload in CI workflow.
Build & Configuration
scripts/generate-client.ts, tsconfig.build.json
Replaced async glob import with Bun.Glob for synchronous file scanning; deleted build-specific TypeScript configuration file.
Type Definitions
worker-configuration.d.ts
Updated WorkerLoader.get() to accept string | null for name parameter; changed AiOptions.tags from required to optional (string[]?).
Database Adapter
src/__tests__/d1-adapter.ts
Refactored D1DatabaseAdapter.exec to delegate multistatement handling to Bun's native run() instead of per-statement splitting.
Client Generation
src/client.ts
Reordered and remapped route import aliases; updated OpenAPIHono app initialization to register reordered route list.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Extra attention needed:
    • src/client.ts route import reordering requires verification that all mappings are correct and semantically equivalent
    • worker-configuration.d.ts public API changes (nullable name, optional tags) may impact downstream code depending on strict type checking
    • src/__tests__/d1-adapter.ts exec method delegation logic needs verification that Bun's native batch execution maintains expected behavior and return count semantics

Possibly related PRs

Suggested labels

ci-cd, database, configuration

Poem

🐰 Glob and Bun, now hand in hand,
Routes reordered across the land,
Types refined, config refined,
Coverage uploads, no test left behind!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'Feature/migrate-to-bun-test' is partially related to the changeset. While the PR does include Bun migration changes (glob, D1 adapter, workflows), the title is overly broad and uses a generic 'Feature/' prefix format, not clearly summarizing the main change. Use a more descriptive title that clearly summarizes the primary change, such as 'Migrate glob to Bun API and update CI workflows' or similar, avoiding generic prefixes.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
src/__tests__/setup.ts (1)

15-24: Add error handling for migration failures.

The migration loading and application lacks error handling. If a migration file is malformed or contains invalid SQL, the test setup will fail silently or with unclear errors.

🔎 Suggested improvement with error handling
 // Apply migrations
 const drizzleDir = path.resolve(__dirname, '../../drizzle')
 const migrationFiles = readdirSync(drizzleDir)
 	.filter((f) => f.endsWith('.sql'))
 	.sort()
 
 for (const file of migrationFiles) {
-	const sql = readFileSync(path.join(drizzleDir, file), 'utf-8')
-	db.run(sql)
+	try {
+		const sql = readFileSync(path.join(drizzleDir, file), 'utf-8')
+		db.run(sql)
+	} catch (error) {
+		throw new Error(`Failed to apply migration ${file}: ${error}`)
+	}
 }
src/__tests__/d1-adapter.ts (2)

41-54: Hardcoded metadata in all() differs from run() behavior.

The all() method hardcodes changes: 0 and last_row_id: 0, while the run() method (lines 56-68) correctly retrieves these values from the statement result. This inconsistency could cause issues if test code relies on accurate metadata from all() operations.

For D1 compatibility and consistency, consider capturing actual metadata:

🔎 Suggested fix to populate metadata
 async all<T = unknown>(): Promise<D1Result<T>> {
 	const start = performance.now()
 	const stmt = this.db.prepare(this.query)
-	const results = stmt.all(...this.params) as T[]
+	const result = stmt.run(...this.params)
+	const results = this.db.prepare(this.query).all(...this.params) as T[]
 	return {
 		results,
 		success: true,
 		meta: {
-			changes: 0,
-			last_row_id: 0,
+			changes: result.changes,
+			last_row_id: Number(result.lastInsertRowid),
 			duration: performance.now() - start,
 		},
 	}
 }

Note: This executes the statement twice (once for metadata, once for results). If this is a concern, you may need to verify whether Bun's SQLite provides metadata from .all() directly.


56-68: BigInt to Number conversion could lose precision.

Line 64 converts lastInsertRowid (BigInt) to Number. While unlikely in test scenarios with small datasets, this could theoretically lose precision for row IDs exceeding Number.MAX_SAFE_INTEGER (2^53 - 1).

For completeness, consider documenting this limitation or preserving the BigInt:

 async run(): Promise<D1Result> {
 	const start = performance.now()
 	const stmt = this.db.prepare(this.query)
 	const result = stmt.run(...this.params)
 	return {
 		success: true,
 		meta: {
 			changes: result.changes,
-			last_row_id: Number(result.lastInsertRowid),
+			last_row_id: Number(result.lastInsertRowid), // Note: precision loss possible for very large IDs
 			duration: performance.now() - start,
 		},
 	}
 }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 99aa067 and 80c93da.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (34)
  • .changeset/migrate-to-bun-test.md
  • .github/workflows/ci.yml
  • bunfig.toml
  • package.json
  • scripts/generate-client.ts
  • src/__tests__/d1-adapter.ts
  • src/__tests__/env.d.ts
  • src/__tests__/setup.ts
  • src/__tests__/test-utils.ts
  • src/client.ts
  • src/middlewares/apiKeyMiddleware.test.ts
  • src/middlewares/corsMiddleware.test.ts
  • src/routes/v1/guilds/matches/confirm.test.ts
  • src/routes/v1/guilds/matches/create.test.ts
  • src/routes/v1/guilds/matches/get.test.ts
  • src/routes/v1/guilds/matches/remove.test.ts
  • src/routes/v1/guilds/matches/vote.test.ts
  • src/routes/v1/guilds/rankings/get.test.ts
  • src/routes/v1/guilds/ratings/get.test.ts
  • src/routes/v1/guilds/ratings/upsert.test.ts
  • src/routes/v1/guilds/users/get.test.ts
  • src/routes/v1/queues/create.test.ts
  • src/routes/v1/queues/get.test.ts
  • src/routes/v1/queues/players/create.test.ts
  • src/routes/v1/queues/players/remove.test.ts
  • src/routes/v1/queues/players/update.test.ts
  • src/routes/v1/queues/remove.test.ts
  • src/routes/v1/ranks/get.test.ts
  • src/routes/v1/ranks/upsert.test.ts
  • src/utils/elo.test.ts
  • tsconfig.build.json
  • tsconfig.json
  • vitest.config.ts
  • worker-configuration.d.ts
💤 Files with no reviewable changes (3)
  • vitest.config.ts
  • tsconfig.build.json
  • src/tests/env.d.ts
🧰 Additional context used
🧬 Code graph analysis (1)
src/__tests__/setup.ts (1)
src/__tests__/d1-adapter.ts (1)
  • D1DatabaseAdapter (76-120)
🔇 Additional comments (35)
src/client.ts (1)

1-45: File is correctly auto-generated.

This file is properly marked as auto-generated and the generation script (bun run generate:client) exists in package.json. All route imports are valid, and the public API (AppType and hcWithType) follows standard Hono RPC client patterns. No issues detected.

.changeset/migrate-to-bun-test.md (1)

1-5: LGTM!

The changeset correctly documents the migration from Vitest to Bun test runner as a patch release with appropriate refactor categorization.

.github/workflows/ci.yml (1)

21-21: LGTM!

The Bun version bump to 1.3.5 aligns with the @types/bun version specified in package.json, ensuring consistency across the project.

bunfig.toml (1)

4-7: LGTM!

The test configuration is well-structured:

  • The preload ensures test setup runs before test execution
  • Coverage exclusions appropriately skip test files themselves from coverage metrics
  • Configuration aligns with the Bun-based testing infrastructure described in the PR
package.json (2)

30-32: LGTM!

The test scripts are correctly updated to use Bun's test runner with appropriate flags for each use case (standard run, watch mode, and coverage reporting). This aligns with the CI workflow configuration.


47-47: LGTM!

The @types/bun version 1.3.5 correctly matches the Bun runtime version specified in the CI workflow, ensuring type consistency.

scripts/generate-client.ts (1)

4-7: Test the glob pattern before deploying. The pattern !(*index|*test|*schemas) uses extended glob negation syntax that is not explicitly documented as supported by Bun.Glob. Standard ! negation works only at the start of a complete pattern. Consider verifying the pattern matches expected files, or switch to post-scan filtering if the pattern doesn't work as intended.

The { posix: true } removal is safe—Bun.Glob handles cross-platform paths natively. Removing the async keyword from line 4 is optional but recommended since scanSync is synchronous.

worker-configuration.d.ts (3)

3-3: workerd version header bump looks fine

Header comment reflects a newer workerd build; assuming this file was regenerated via Wrangler for that version, there’s nothing to change here. Just ensure the deployed Workers runtime and your local wrangler types generation are in sync so these declarations stay accurate.


3282-3284: WorkerLoader.get accepting string | null name matches broader API usage

Allowing name to be string | null makes the type compatible with callers that intentionally pass null for “no entrypoint name” and mirrors other APIs that treat the name as optional. This is source-compatible for normal call sites, but if you ever pass WorkerLoader["get"] as a callback typed with (name: string, ...) => ..., you may need to widen that callback’s parameter type to string | null as well.


8447-8470: Making AiOptions.tags optional removes an unnecessary requirement

Changing tags to tags?: string[] fixes the previous typing where every AiOptions consumer was forced to supply tags even when only using flags like queueRequest or gateway. The JSDoc constraints on tag content/length still apply at runtime; this type change just makes the option ergonomic and backwards-compatible for existing callers that already pass tags.

src/utils/elo.test.ts (1)

1-1: LGTM! Clean migration to Bun test runner.

The test imports have been correctly updated to use Bun's native test runner while preserving all test logic and assertions.

src/__tests__/test-utils.ts (1)

3-8: LGTM! Test utilities updated to use centralized setup.

The env import has been correctly updated to use the local setup module, which centralizes test environment configuration across all test files.

src/routes/v1/queues/get.test.ts (1)

1-4: LGTM! Consistent migration to Bun test framework.

Test imports follow the same migration pattern as other test files, maintaining consistency across the test suite.

src/routes/v1/guilds/matches/confirm.test.ts (1)

1-5: LGTM! Complex test suite migrated successfully.

The comprehensive match confirmation test suite has been migrated to Bun while preserving all test scenarios and assertions. This is critical functionality and the careful migration approach is appreciated.

src/routes/v1/queues/players/create.test.ts (1)

1-5: LGTM! Queue player tests migrated correctly.

Test imports updated consistently with the Bun migration pattern while maintaining full test coverage for queue player functionality.

src/routes/v1/guilds/users/get.test.ts (1)

1-4: LGTM! User history tests migrated successfully.

The migration follows the established pattern, maintaining comprehensive test coverage for user match history functionality.

src/routes/v1/guilds/rankings/get.test.ts (1)

1-4: LGTM! Test imports migrated to Bun with centralized setup.

The test correctly switches to Bun's test runner and imports env from the centralized setup module. The setup module properly exports env with a D1Database instance initialized with in-memory SQLite and migrations applied.

tsconfig.json (1)

16-16: LGTM! Types configuration updated for Bun migration.

@types/bun (version 1.3.5) is correctly included in devDependencies, and the types array now contains only ./worker-configuration.d.ts and @types/bun. No references to Vitest remain in the codebase.

src/routes/v1/ranks/upsert.test.ts (1)

1-5: Clean migration to Bun test runner.

The import changes correctly migrate from Vitest/Cloudflare test environment to Bun's test runner. The test logic remains unchanged, reducing migration risk.

src/routes/v1/guilds/ratings/upsert.test.ts (1)

1-4: LGTM!

Import changes correctly align with the Bun test migration. Test implementation remains intact.

src/routes/v1/queues/remove.test.ts (1)

1-5: LGTM!

Test framework migration properly applied with no changes to test logic.

src/routes/v1/queues/players/remove.test.ts (1)

1-4: LGTM!

Import updates correctly implement the Bun test runner migration.

src/routes/v1/guilds/matches/get.test.ts (1)

1-4: LGTM!

Test framework imports properly updated for Bun migration.

src/routes/v1/guilds/ratings/get.test.ts (1)

1-4: LGTM!

Import changes correctly align with the Bun test runner migration.

src/middlewares/corsMiddleware.test.ts (1)

1-3: LGTM!

Test framework migration properly applied. The comprehensive CORS test coverage remains intact.

src/routes/v1/guilds/matches/remove.test.ts (1)

1-5: Imports correctly follow Bun test migration pattern. The use of imports from bun:test including beforeEach, describe, expect, it, and other test utilities is standard and properly supported. All other imports (drizzle-orm, hono/testing, and the env module) follow correct patterns for this stack.

To complete the review, verify:

  • src/__tests__/setup.ts exists and properly exports env
  • All tests pass: bun test
  • Type checking passes: bun run typecheck
src/routes/v1/guilds/matches/create.test.ts (1)

1-1: LGTM! Test framework migration looks good.

The import changes correctly migrate from Vitest/Cloudflare test environment to Bun's test runner with centralized setup.

Also applies to: 5-5

src/routes/v1/guilds/matches/vote.test.ts (1)

1-1: LGTM! Test framework migration is consistent.

Import changes align with the Bun test migration strategy.

Also applies to: 4-4

src/routes/v1/queues/create.test.ts (1)

1-1: LGTM! Migration follows established pattern.

Test framework imports correctly updated.

Also applies to: 5-5

src/routes/v1/ranks/get.test.ts (1)

1-1: LGTM! Test migration is correct.

Import sources properly updated for Bun test runner.

Also applies to: 4-4

src/routes/v1/queues/players/update.test.ts (1)

1-1: LGTM! Consistent test framework migration.

Import changes are correct and align with the PR's migration strategy.

Also applies to: 4-4

src/middlewares/apiKeyMiddleware.test.ts (1)

1-1: LGTM! Test migration completed correctly.

Import changes properly migrate to Bun test infrastructure.

Also applies to: 3-3

src/__tests__/setup.ts (1)

27-30: LGTM! Clean test environment setup.

The in-memory database approach with D1 adapter is appropriate for testing. The type cast on Line 28 is necessary given the adapter pattern.

src/__tests__/d1-adapter.ts (2)

87-100: LGTM! Transaction handling is correct.

The batch() method properly wraps statements in a transaction with rollback on error, ensuring atomicity.


116-119: LGTM! Database serialization is correctly implemented.

The dump() method properly slices the buffer to create a clean ArrayBuffer for database serialization.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.github/workflows/pull_request.yml (1)

24-24: Align Bun version with ci.yml to ensure consistency.

This workflow uses Bun 1.3.4 while ci.yml uses 1.3.5. Version mismatches between PR and main CI workflows can lead to inconsistent test results and unexpected failures after merge.

🔎 Proposed fix
-          bun-version: 1.3.4
+          bun-version: 1.3.5
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 80c93da and 818c498.

📒 Files selected for processing (3)
  • .github/workflows/ci.yml
  • .github/workflows/pull_request.yml
  • src/__tests__/d1-adapter.ts
🔇 Additional comments (2)
.github/workflows/ci.yml (1)

38-38: LGTM! Good practice to fail CI on coverage upload errors.

Adding fail_ci_if_error: true ensures that if the coverage upload fails, the CI pipeline will fail, making coverage reporting issues visible immediately.

.github/workflows/pull_request.yml (1)

35-42: LGTM! Test and coverage steps properly configured.

The addition of test execution with coverage reporting and Codecov upload aligns with the PR's goal of migrating to Bun test. The configuration matches ci.yml (including fail_ci_if_error: true), ensuring consistent behavior across workflows.

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 22, 2025

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

@11gather11 11gather11 merged commit 30dda8f into main Dec 22, 2025
3 of 4 checks passed
@11gather11 11gather11 deleted the feature/migrate-to-bun-test branch December 22, 2025 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant