Skip to content

test(postgres): run binary NUMERIC sub-1e-8 test against the real server#31508

Open
robobun wants to merge 1 commit into
mainfrom
farm/b82bdf6a/postgres-numeric-real-server
Open

test(postgres): run binary NUMERIC sub-1e-8 test against the real server#31508
robobun wants to merge 1 commit into
mainfrom
farm/b82bdf6a/postgres-numeric-real-server

Conversation

@robobun

@robobun robobun commented May 28, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #31211 (requested on that PR): swap the mock-Postgres server in postgres-binary-numeric.test.ts for the real postgres_plain docker-compose service.

What changed

  • test/js/sql/postgres-binary-numeric.test.ts drops the hand-rolled net-based mock server (which faked format=1 in the RowDescription to reach the binary decoder) and instead connects to the real postgres_plain service via describeWithContainer / isDockerEnabled(), the same infra sql.test.ts and sql-prepare-false.test.ts use.
  • test/docker/coordinator.ts gets a js/sql/postgres-binary-numeric -> postgres_plain entry in the prestart map so CI pre-starts the container for that shard. (This was originally an entry in warmup-ci.ts; rebased after ci: serialize docker service startup through a per-shard coordinator #32033 replaced that file with the coordinator, so the entry moved to the coordinator's equivalent map.)

Why a real server hits the buggy path

#31211 fixed the binary NUMERIC decoder for sub-1e-8 values. Against a real server, a plain tagged-template query (sqlselect ${v}::numeric``) uses the extended protocol, so Bun requests the result column in binary and decodes it with the binary NUMERIC decoder, no mock needed to force format=1. Each value is also cross-checked against the `.simple()` (text) result, which was always correct and pins the expected canonical rendering.

Verification

Confirmed against a real Postgres server that the test fails before the fix and passes after. Running the same matrix through the test runner:

  • Debug build (has the postgres: emit full leading-zero groups when binary-decoding sub-1e-8 NUMERIC #31211 fix): 13/13 pass (re-verified after the rebase onto current main).
  • Release build without the fix: the 6 sub-1e-8 cases fail on the binary assertion (e.g. 1e-9 decodes as 0.000010000), while the text-protocol assertion passes and the 7 boundary/always-correct cases pass, i.e. the test exercises exactly the decoder path the fix touched.

The docker-gated suite runs on Linux x64 CI (where docker is available); it skips elsewhere, same as the other postgres docker tests.

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 64780735-fc88-4488-a6e5-40b3c6814f46

📥 Commits

Reviewing files that changed from the base of the PR and between 2ad4199 and 85db71d.

📒 Files selected for processing (2)
  • test/docker/coordinator.ts
  • test/js/sql/postgres-binary-numeric.test.ts

Walkthrough

Mock-based Postgres binary numeric test is replaced with real Docker-backed integration test. Test coordinator is updated to prestart postgres_plain service when the test path is present. Test file refactored to use Docker container harness, test data covering sub-1e-8 and boundary cases, and assertions comparing binary and text protocol query results.

Changes

Docker-backed postgres binary numeric test

Layer / File(s) Summary
Docker service prestart configuration
test/docker/coordinator.ts
Test coordinator prestartMap entry added to prestart postgres_plain service when js/sql/postgres-binary-numeric test path is present in shard argv.
Docker-backed integration test implementation
test/js/sql/postgres-binary-numeric.test.ts
Test imports updated to use Bun test runner and Docker container harness helpers. New literals array provides test data for previously-corrupted sub-1e-8 weight values and boundary cases. Mock-server implementation removed; test now opens real SQL connection in beforeAll, compares binary-decoded and text ::numeric results for each literal, and closes connection in afterAll.

Possibly related PRs

  • oven-sh/bun#32033: Updates the same coordinator prestartMap mechanism for test service startup serialization.
  • oven-sh/bun#31211: Implements the parse_binary_numeric fix for correct leading-zero group emission when weight <= -3, which these integration tests verify.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: replacing a mock server with a real Postgres server for the binary NUMERIC test.
Description check ✅ Passed The description comprehensively covers the template sections and provides detailed context about the changes, rationale, and verification.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

@robobun

robobun commented May 28, 2026

Copy link
Copy Markdown
Collaborator Author
Updated 8:43 AM PT - Jun 10th, 2026

@robobun, your commit 85db71d has 6 failures in Build #61752 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 31508

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

bun-31508 --bun

@claude claude 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.

LGTM — test-only refactor swapping a mock for the real postgres_plain container using established harness patterns.

Extended reasoning...

Overview

This PR touches two test-infrastructure files only. test/js/sql/postgres-binary-numeric.test.ts is rewritten to drop a hand-rolled net-based mock Postgres server in favor of the real postgres_plain docker-compose service via describeWithContainer / isDockerEnabled(). test/docker/warmup-ci.ts gains a one-line entry mapping js/sql/postgres-binary-numericpostgres_plain so CI pre-starts the container.

Security risks

None. No production/runtime code is modified. The sql.unsafe(literal) call inlines hardcoded numeric string constants from the test file itself (necessary because .simple() cannot bind params), not external input. The connection URL targets a local test container.

Level of scrutiny

Low. This is test-only code following patterns already established in the repo: the describeWithContainer(..., { image: "postgres_plain" }, ...) + await container.ready + postgres://bun_sql_test@host:port/bun_sql_test shape matches test/regression/issue/21311.test.ts exactly, and the warmup-ci map entry is identical in form to the neighboring sql.test / sql-prepare-false entries. The suite is gated behind isDockerEnabled() so it skips where docker is unavailable, same as other postgres docker tests.

Other factors

The PR description documents that the new test was verified to fail before the #31211 fix and pass after, confirming it exercises the intended binary NUMERIC decoder path. The bug-hunting system found no issues. The change actually simplifies the test (removes ~80 lines of wire-protocol mocking) while increasing fidelity by testing against a real server.

@claude claude 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.

LGTM — test-only refactor following the established describeWithContainer / postgres_plain pattern.

Extended reasoning...

Overview

This PR touches two test-infrastructure files only: test/js/sql/postgres-binary-numeric.test.ts is rewritten to drop a hand-rolled mock Postgres server in favor of the real postgres_plain docker-compose service, and test/docker/warmup-ci.ts gets a one-line map entry so CI pre-warms that container for the shard. No production/runtime code is changed.

Security risks

None. The only "unsafe" construct is sql.unsafe(literal) inside .simple(), but the literals are a hardcoded array of numeric string constants in the test file itself — there is no user-controlled input. The connection URL and container setup are copied verbatim from existing tests.

Level of scrutiny

Low. This is a test refactor that follows established patterns line-for-line: isDockerEnabled() + describeWithContainer(..., { image: "postgres_plain" }, ...) with await container.ready in beforeAll and the postgres://bun_sql_test@${host}:${port}/bun_sql_test URL match test/js/sql/sql.test.ts and test/regression/issue/21311.test.ts exactly. The warmup-ci.ts addition is a mechanical one-liner identical in shape to its neighbors, and per that file's own header comment a missing entry would only make the test slower, not incorrect.

Other factors

The bug-hunting system found no issues. The describeWithContainer signature in test/harness.ts confirms the { image } option shape and the container.{host,port,ready} descriptor are used correctly. The harness already handles the no-docker case via describe.todo, so the outer isDockerEnabled() guard is redundant but harmless. The PR description documents that the new test was verified to fail pre-fix and pass post-fix, which is exactly what you want when replacing a mock with real infra.

Replace the minimal mock-Postgres server in postgres-binary-numeric.test.ts
with the real postgres_plain docker-compose service, matching how sql.test.ts
and sql-prepare-false.test.ts connect. A plain tagged-template query
(select $1::numeric) goes through the extended protocol, so Bun requests the
result column in binary and decodes it with the binary NUMERIC decoder, the
path the sub-1e-8 fix touched. Each value is cross-checked against the
simple-protocol (text) result, which was always correct.

Add the file to the coordinator.ts prestart map so CI pre-starts
postgres_plain for the shard.
@robobun robobun force-pushed the farm/b82bdf6a/postgres-numeric-real-server branch from 0851158 to 85db71d Compare June 10, 2026 10:11
@robobun

robobun commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator Author

CI note on build 61752 (concluded): all hard failures are unrelated to this diff.

  • debian-13-x64-asan: test/regression/issue/30205.test.ts napi flake, same failure on unrelated branches (61700, 61709, 61717, 61724, 61733).
  • darwin-14-x64: test/js/bun/terminal/terminal.test.ts PTY timeouts, also flaking on 61700 and 61724.
  • darwin-14-aarch64: a cold docker agent (mysql2/s3/local-sql all failed while building images and waiting for services; init.test.ts also failed there and on 61700). The coordinator prestart entry this PR adds is gated isCI && isLinux in runner.node.mjs, so it cannot run on macOS lanes at all.

The postgres test added here passed on every lane; its only blemish was one retry-recovered container-startup race on alpine x64-baseline, the same class the existing postgres docker tests share. Diff is test-only and ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant