Skip to content

test: raw-query golden harness for @prisma/adapter-pg (TRI-13039 spike) - #4535

Closed
ericallam wants to merge 1 commit into
mainfrom
feature/tri-13039-spike-raw-query-golden-test-harness-for-prismaadapter-pg
Closed

test: raw-query golden harness for @prisma/adapter-pg (TRI-13039 spike)#4535
ericallam wants to merge 1 commit into
mainfrom
feature/tri-13039-spike-raw-query-golden-test-harness-for-prismaadapter-pg

Conversation

@ericallam

Copy link
Copy Markdown
Member

What this is

Timeboxed spike for TRI-13039. Evidence, not a migration: a golden test harness that answers whether @prisma/adapter-pg at Prisma 6.14 (a) preserves engine tracing and (b) returns byte-identical raw-query results vs the current Rust engine. Nothing here is meant to merge; it enables the driverAdapters preview flag on both schemas (regen required, not committed) and adds three test files under internal-packages/testcontainers/src/.

Run it:

cd internal-packages/testcontainers
pnpm exec vitest run src/adapterGolden.test.ts src/adapterTracing.test.ts

Deliverable A — does tracing survive the adapter? PASS

In-memory OTel span exporter + PrismaInstrumentation, same SELECT through both clients.

  • GATE PASSES: prisma:client:operation AND prisma:engine:db_query both present under the adapter. driverAdapters alone keeps the Rust query engine, as predicted.
  • prisma:engine:connection SURVIVES: the pool-wait monitors keep reading a real span (it now measures node-postgres pool acquisition; same name/shape).
  • Adapter ADDS three prisma:engine:js:query:* spans (the node-postgres wire path), and DROPS two one-time Rust-binary bootstrap spans (detect_platform, load_engine) that no monitor reads.

Deliverable B — raw-result equivalence matrix: 10/11 identical

# shape upstream result
1 text[] param with explicit cast (= ANY($1::text[])) #24338 IDENTICAL
2 array results (array_agg, text[] column) #27823 IDENTICAL
3 bigint from COUNT(*) #23926 IDENTICAL
4 bigint ns timestamp (keyset) IDENTICAL
5 NUMERIC -> Prisma.Decimal IDENTICAL
6 enum cast IDENTICAL
7 jsonb with cast params (to_jsonb($1::text/::int)) #24338 IDENTICAL
8 timestamptz round-trip (Date param) #28629 IDENTICAL
9 IN with varying arity #21803 IDENTICAL
10 unqualified SQL relying on search_path / {schema} #28128 DIVERGES (see below)
11 nulls, empty result set, zero-row RETURNING IDENTICAL

bigint stays bigint, NUMERIC stays Prisma.Decimal, text[] stays a JS array, timestamptz stays a Date. The four feared upstream bugs (#24338, #27823, #23926, #28629) did NOT reproduce at 6.14: result deserialization is still done by the Rust engine, so the adapter changes the wire, not the JS types.

Shape 10 (the one divergence, #28128)

The adapter's {schema} option does not set a session search_path for raw SQL:

  • {schema:"s1"} + unqualified SELECT ... FROM t (non-public): FAILS P2010 / 42P01 relation "t" does not exist
  • {schema:"public"} + unqualified select: OK
  • qualified s1.t under {schema:"s1"}: OK

Both prod connection strings use ?schema=public, and public is always on the default search_path, so the many unqualified raw queries resolve fine under the adapter. Real divergence, inert for current usage; would only bite a non-public schema, of which there are none.

Revised effort estimate (replaces 4-6 weeks)

The 4-6 week estimate priced the 64 raw-SQL call sites as the risk. They are not: every wire type is unchanged and the feared bugs did not reproduce, so the raw-SQL surface is close to a no-op. The genuine work is adapter-inherent and non-query: $metrics removal (Prometheus route + 16 db.pool.connections.* OTel instruments need a new source, the largest item), error-code remapping (P1001/P1017 -> ECONNREFUSED/ENOTFOUND; 40P01 no longer -> P2034, so deadlocks stop retrying, #29716; P2024 gone; eager $connect() no-op, #28959), the load-bearing pg pin (<8.17, #29035), and RBAC/SSO plugin clients outside this repo.

Grounded estimate: roughly 1.5-2.5 weeks, dominated by the pool-observability replacement, not query rewrites.

Go / no-go

GO. The mechanism holds under test: engine spans (incl. engine:connection) survive, and raw results are byte-identical on 10/11 shapes with the one divergence provably inert for the public-schema DBs. The rejection was priced on a raw-SQL risk the evidence does not support; adoption is an observability + error-handling change, not a query-rewrite change.

Not in scope

No adoption, no schema changes merged, no prod/staging config, no rollout. The regenerated Prisma clients are gitignored and not committed; adoption would enable driverAdapters and regenerate.

refs TRI-13039

Spike evidence only, not for merge. Adds a testcontainers harness that runs the same
raw queries through the current Rust-engine Prisma client and an @prisma/adapter-pg
client against the same Postgres, plus a tracing gate.

- Deliverable A: engine spans (prisma:client:operation, prisma:engine:db_query,
  prisma:engine:connection) survive the adapter under driverAdapters-alone.
- Deliverable B: 10/11 raw-result shapes byte-identical; only unqualified SQL on a
  non-public schema diverges (#28128), inert for the public-schema prod DBs.

Enables the driverAdapters preview flag on both schemas (regen required, not committed).
@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 707dff7

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

@ericallam ericallam closed this Aug 7, 2026
@ericallam
ericallam deleted the feature/tri-13039-spike-raw-query-golden-test-harness-for-prismaadapter-pg branch August 7, 2026 22:22
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d9231f27-b6a6-4d80-bc5d-92ab866a5e59

📥 Commits

Reviewing files that changed from the base of the PR and between c526528 and 707dff7.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • internal-packages/database/prisma/schema.prisma
  • internal-packages/run-ops-database/prisma/schema.prisma
  • internal-packages/testcontainers/package.json
  • internal-packages/testcontainers/src/adapterGolden.test.ts
  • internal-packages/testcontainers/src/adapterGolden.ts
  • internal-packages/testcontainers/src/adapterTracing.test.ts

Walkthrough

Prisma generators now enable the driverAdapters preview feature. The testcontainers package adds PostgreSQL adapter, OpenTelemetry, tracing, and pg dependencies. New utilities create Rust and adapter-backed Prisma clients, serialize results, and compare query outcomes. Integration tests cover PostgreSQL result shapes, schema resolution, and OpenTelemetry spans.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/tri-13039-spike-raw-query-golden-test-harness-for-prismaadapter-pg

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.

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.

1 participant