Skip to content

fix(Bun.SQL) fix timers test and disable describeWithContainer on macos - #22382

Merged
Jarred-Sumner merged 5 commits into
mainfrom
claude/fix-postgres-time-type
Sep 4, 2025
Merged

Jarred-Sumner merged 5 commits into
mainfrom
claude/fix-postgres-time-type

Conversation

@cirospaciari

@cirospaciari cirospaciari commented Sep 3, 2025 •

Copy link
Copy Markdown
Member

What does this PR do?

Actually run the Timer/TimerZ tests in CI and disable describeWithContainer in macos

How did you verify your code works?

CI

Claude Bot and others added 3 commits September 3, 2025 06:08
Previously, when PostgreSQL returned TIME or TIMETZ columns in binary format,
Bun.sql would not properly convert them from their binary representation
(microseconds since midnight) to readable time strings. This resulted in
garbled output with null bytes instead of proper time values.

This fix:
- Adds proper binary format handling for TIME (8 bytes) and TIMETZ (12 bytes) types
- Uses C++ helper functions following WebKit's pattern with snprintf for formatting
- Converts microseconds to HH:MM:SS.ffffff format with proper formatting
- Handles timezone offsets correctly for TIMETZ type (PostgreSQL uses negative for positive UTC)
- Trims trailing zeros from fractional seconds for cleaner output
- Adds comprehensive tests for both types and their array variants

The C++ formatting functions follow WebKit's established pattern of using
snprintf for date/time formatting as seen in their toISOString implementation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@robobun

robobun commented Sep 3, 2025 •

Copy link
Copy Markdown
Collaborator
Updated 4:53 PM PT - Sep 3rd, 2025

❌ @cirospaciari, your commit a6c628c has 2 failures in Build #24935:


🧪   To try this PR locally:

bunx bun-pr 22382

That installs a local version of the PR into your bun-22382 executable, so you can run:

bun-22382 --bun

@coderabbitai

coderabbitai Bot commented Sep 3, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds macOS to container-skip logic in test harness. Removes Postgres TIME/TIMETZ tests from test/js/bun/sql/postgres-time.test.ts and introduces an equivalent Time/TimeZ suite under test/js/sql/sql.test.ts that runs only with Docker-based Postgres.

Changes

Cohort / File(s) Summary of changes
Test harness platform gating
test/harness.ts
Updated describeWithContainer to skip on darwin and win32 (alongside existing arch check); rest of container lifecycle unchanged.
Postgres TIME/TIMETZ test relocation
test/js/bun/sql/postgres-time.test.ts, test/js/sql/sql.test.ts
Deleted legacy Postgres TIME/TIMETZ tests; added new Time/TimeZ suite (including arrays and JSONB) under sql.test.ts with setup/teardown and Docker-availability gating.

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/fix-postgres-time-type

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (4)
test/harness.ts (2)

909-912: Use isMacOS and make the skip reason accurate

Prefer the existing isMacOS helper and adjust the message to reflect an intentional disable (not “unsupported”).

-    if ((archs && !archs?.includes(arch)) || platform === "win32" || platform === "darwin") {
-      test.skip(`docker image is not supported on ${platform}/${arch}, skipped: ${image}`, () => {});
+    if ((archs && !archs?.includes(arch)) || platform === "win32" || isMacOS) {
+      test.skip(`container tests disabled on ${platform}/${arch}, skipped: ${image}`, () => {});
       return false;
     }

909-912: Optional: allow local macOS opt-in while keeping CI disabled

Gate the darwin block behind an env override so contributors with Docker Desktop/Podman can run these locally.

-    if ((archs && !archs?.includes(arch)) || platform === "win32" || isMacOS) {
+    const allowDarwinContainers = process.env.BUN_TEST_CONTAINER_ON_DARWIN === "1";
+    if ((archs && !archs?.includes(arch)) || platform === "win32" || (isMacOS && !allowDarwinContainers)) {
       test.skip(`container tests disabled on ${platform}/${arch}, skipped: ${image}`, () => {});
       return false;
     }
test/js/sql/sql.test.ts (2)

318-323: Make table cleanup resilient (run in finally and use IF EXISTS).

If assertions throw before cleanup, tables can be left behind. Move DROP TABLE into finally with IF EXISTS.

Apply this diff in each test’s cleanup:

-        // Clean up
-        await db`DROP TABLE bun_time_test`;
-      } finally {
-        await db.end();
-      }
+      } finally {
+        try { await db`DROP TABLE IF EXISTS bun_time_test`; } catch {}
+        await db.end();
+      }

Repeat similarly for bun_time_array_test and bun_time_json_test.

Also applies to: 386-391, 429-434


256-256: Optional: use await using for connection lifecycle.

await using db = postgres(options) auto-closes on scope exit and reduces boilerplate try/finally.

Example:

-      const db = postgres(options);
+      await using db = postgres(options);

Also applies to: 326-326, 394-394

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e1de756 and a6c628c.

📒 Files selected for processing (3)
  • test/harness.ts (1 hunks)
  • test/js/bun/sql/postgres-time.test.ts (0 hunks)
  • test/js/sql/sql.test.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • test/js/bun/sql/postgres-time.test.ts
🧰 Additional context used
📓 Path-based instructions (7)
test/**

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

Place all tests under the test/ directory

Files:

  • test/harness.ts
  • test/js/sql/sql.test.ts
test/**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

test/**/*.{js,ts}: Write tests in JavaScript or TypeScript using Bun’s Jest-style APIs (test, describe, expect) and run with bun test
Prefer data-driven tests (e.g., test.each) to reduce boilerplate
Use shared utilities from test/harness.ts where applicable

Files:

  • test/harness.ts
  • test/js/sql/sql.test.ts
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (CLAUDE.md)

Run Prettier to format JS/TS files (bun run prettier)

Files:

  • test/harness.ts
  • test/js/sql/sql.test.ts
test/js/**/*.{js,ts}

📄 CodeRabbit inference engine (.cursor/rules/writing-tests.mdc)

Place JavaScript and TypeScript tests under test/js/

Files:

  • test/js/sql/sql.test.ts
test/**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

test/**/*.test.{ts,tsx}: Tests must be named with the suffix .test.ts or .test.tsx and live under the test/ directory
In tests, always use port: 0 and never hardcode ports or use custom random-port utilities
Prefer snapshot tests using normalizeBunSnapshot(...) over direct string equality on stdout/stderr
Do not write tests that assert absence of 'panic', 'uncaught exception', or similar strings in output
Avoid shelling out to tools like find or grep in tests; use Bun.Glob and built-in utilities

Files:

  • test/js/sql/sql.test.ts
test/**/*.test.ts

📄 CodeRabbit inference engine (test/CLAUDE.md)

test/**/*.test.ts: Name test files *.test.ts and use bun:test
Do not write flaky tests: never wait for arbitrary time; wait for conditions instead
Never hardcode port numbers in tests; use port: 0 to get a random port
When spawning Bun in tests, use bunExe() and bunEnv from harness
Prefer async/await in tests; for a single callback, use Promise.withResolvers()
Do not set explicit test timeouts; rely on Bun’s built-in timeouts
Use tempDir/tempDirWithFiles from harness for temporary files and directories in tests
For large/repetitive strings in tests, prefer Buffer.alloc(count, fill).toString() over "A".repeat(count)
Import common test utilities from harness (e.g., bunExe, bunEnv, tempDirWithFiles, tmpdirSync, platform checks, GC helpers)
In error tests, assert non-zero exit codes for failing processes and use toThrow for synchronous errors
Use describe blocks for grouping, describe.each for parameterized tests, snapshots with toMatchSnapshot, and lifecycle hooks (beforeAll, beforeEach, afterEach); track resources for cleanup in afterEach
Use using/await using with Bun resources (e.g., Bun.listen/connect/spawn/serve) to ensure cleanup in tests

Files:

  • test/js/sql/sql.test.ts
test/js/**

📄 CodeRabbit inference engine (test/CLAUDE.md)

Organize unit tests for specific features under test/js/ by module

Files:

  • test/js/sql/sql.test.ts
🧠 Learnings (1)
📚 Learning: 2025-09-03T17:10:13.460Z
Learnt from: CR
PR: oven-sh/bun#0
File: test/CLAUDE.md:0-0
Timestamp: 2025-09-03T17:10:13.460Z
Learning: Applies to test/**/*.test.ts : Do not set explicit test timeouts; rely on Bun’s built-in timeouts

Applied to files:

  • test/js/sql/sql.test.ts
🧬 Code graph analysis (1)
test/harness.ts (3)
scripts/runner.node.mjs (2)
  • arch (331-331)
  • platform (1979-1979)
scripts/utils.mjs (2)
  • arch (1618-1618)
  • arch (1677-1677)
test/js/node/process/process.test.js (2)
  • arch (142-142)
  • platform (141-141)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Format

Comment thread test/js/sql/sql.test.ts
Comment thread test/js/sql/sql.test.ts
@Jarred-Sumner
Jarred-Sumner merged commit 60ab798 into main Sep 4, 2025
60 of 63 checks passed
@Jarred-Sumner
Jarred-Sumner deleted the claude/fix-postgres-time-type branch September 4, 2025 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants