ReviewOS

home-lang/home

Port pg-gateway PGlite protocol bridge into Bun.SQL

#288
Closed chris opened this 10 days ago ·
10 days ago

Context

Bun corpus position 4040, js/third_party/pg-gateway/pglite.test.ts, currently stops at unsupported mixed type/value module syntax. The upstream test creates a PGlite database, serves its PostgreSQL protocol through pg-gateway/node, and queries it through Bun.SQL using prepared, parameterized, simple, and unsafe paths.

Required contract

  • Rewrite the mixed node:net import without retaining the type-only AddressInfo binding.
  • Provide pg-gateway/node.fromNodeSocket with trust-auth startup/message lifecycle behavior.
  • Extend the PGlite bootstrap adapter with initialization, DDL/insert state, and protocol-query behavior.
  • Route Bun.SQL tagged, bound, .simple(), and .unsafe() queries through the in-memory gateway.
  • Preserve SQL option fields and async disposal.
  • Wrap gateway startup/query failures with stable code, operation/phase, sanitized endpoint/database context, original cause, and operation stack frames.

Acceptance

  • Position 4040 passes 1/1 with the real copied upstream source.
  • Permanent coverage checks all four query paths and structured/redacted gateway diagnostics.
  • The focused and cumulative results are recorded in #66.
10 days ago

Completed in 2b92fa4c0.

The bootstrap runtime now carries a real in-memory bridge across the copied upstream layers:

  • The mixed value/type node:net import is lowered without retaining the type-only binding.
  • PGlite exposes waitReady, stateful DDL/inserts, queries, protocol dispatch, and cleanup.
  • pg-gateway/node.fromNodeSocket performs trust-auth startup and authenticated message delivery.
  • Bun.SQL routes tagged literal, tagged bound, .simple(), and parameterized .unsafe() queries through the gateway while preserving connection options and async disposal.
  • Gateway failures retain ERR_PG_GATEWAY, operation/phase, sanitized endpoint and database context, the original cause, and an explicit operation stack frame.

Verification:

  • position 4040: 1 passed, 0 failed/todo/unsupported/allowed-empty
  • positions 4039–4040: 2 files, 1 passed, 1 intentional secret-gated todo, 0 failed/unsupported/allowed-empty
  • permanent gRPC stack, SQL adapter, and third-party diagnostic mini-suites: passing

The external SMTP/TLS path at position 4039 remains tracked in #287. Overall tracking continues in #66 at position 4041.

Sign in to comment on this issue.