1616 * So this is a MATRIX: the same read paths, asserted across both adapters, against a
1717 * REAL Postgres. Adding a third adapter should mean adding a row here, not a new file.
1818 *
19+ * It is also a matrix over ENTRY POINTS, which matters more than it looks. This package's
20+ * `exports` map carries a `"bun"` condition pointing at `./src/**.ts` while everything else
21+ * resolves `./dist/**.js` — so **Bun executes the TypeScript source and Node executes the
22+ * build**. A fix applied to one tree and not the other reaches only half the adopters, and a
23+ * suite importing just one tree cannot tell. (Confirmed live: immediately after fixing `src`,
24+ * `dist/hono/index.js` still contained the broken calls until a rebuild.) Every row below
25+ * therefore runs against both resolved entry points.
26+ *
1927 * Gated on METAOBJECTS_TEST_PG_URL (CI's ts-slow lane supplies a Postgres sidecar);
2028 * skips loudly-but-harmlessly when absent, and the sentinel below fails if a lane
2129 * claims it intends Postgres and then does not provide it.
2230 */
2331
2432import { describe , test , expect , beforeAll , afterAll } from "bun:test" ;
33+ import { existsSync } from "node:fs" ;
34+ import { join } from "node:path" ;
2535import { Hono } from "hono" ;
2636import Fastify , { type FastifyInstance } from "fastify" ;
2737import { Pool } from "pg" ;
@@ -69,11 +79,29 @@ describe("#286 — CRUD helpers on real Postgres, both adapters", () => {
6979 return ;
7080 }
7181
82+ // biome-ignore lint/suspicious/noExplicitAny: mount option bags are structurally typed
83+ type HonoMount = ( o : any ) => void ;
84+ // biome-ignore lint/suspicious/noExplicitAny: mount option bags are structurally typed
85+ type FastifyMount = ( o : any ) => void ;
86+
7287 let pool : Pool ;
7388 // biome-ignore lint/suspicious/noExplicitAny: drizzle db handle, structurally typed by the mounts
7489 let db : any ;
75- let hono : Hono ;
76- let fastify : FastifyInstance ;
90+ const fastifies : FastifyInstance [ ] = [ ] ;
91+ /** True when dist/ was absent — surfaced as a failing test rather than a silent half-matrix. */
92+ let builtTreeMissing = false ;
93+
94+ /** Every (adapter x entry-point) combination under test. Filled in beforeAll. */
95+ const adapters : Array < { name : string ; get : ( url : string ) => Promise < { status : number ; body : unknown } > } > = [ ] ;
96+
97+ // describe() bodies register BEFORE beforeAll fills `adapters`, so the rows are named
98+ // statically and resolved lazily inside each test.
99+ const ADAPTER_NAMES = [ "hono (src)" , "fastify (src)" , "hono (dist)" , "fastify (dist)" ] as const ;
100+ const use = ( name : string ) => {
101+ const a = adapters . find ( ( x ) => x . name === name ) ;
102+ if ( ! a ) throw new Error ( `adapter row [${ name } ] was never mounted — the matrix is incomplete` ) ;
103+ return a ;
104+ } ;
77105
78106 beforeAll ( async ( ) => {
79107 pool = new Pool ( { connectionString : PG_URL } ) ;
@@ -92,95 +120,116 @@ describe("#286 — CRUD helpers on real Postgres, both adapters", () => {
92120 VALUES ('alice@x.com','Alice',true), ('bob@x.com','Bob',false), ('carol@y.com','Carol',true)` ,
93121 ) ;
94122
95- hono = new Hono ( ) ;
96- mountHono ( {
97- app : hono , path : "/subscribers" , db, table : subscribers ,
98- insertSchema : InsertSchema , updateSchema : UpdateSchema ,
99- filterAllowlist, sortAllowlist, dialect : "postgres" ,
100- } ) ;
123+ // src/** is what Bun runs (the `bun` export condition); dist/** is what Node runs.
124+ // Exercise both — a fix in one tree only would otherwise pass here.
125+ const entries : Array < { tree : string ; hono : HonoMount ; fastify : FastifyMount } > = [
126+ { tree : "src" , hono : mountHono , fastify : mountFastify } ,
127+ ] ;
128+ if ( existsSync ( join ( import . meta. dir , ".." , "dist" , "hono" , "index.js" ) ) ) {
129+ const dh = await import ( "../dist/hono/index.js" ) ;
130+ const df = await import ( "../dist/drizzle-fastify/index.js" ) ;
131+ entries . push ( { tree : "dist" , hono : dh . mountCrudRoutes , fastify : df . mountCrudRoutes } ) ;
132+ } else {
133+ builtTreeMissing = true ;
134+ }
101135
102- fastify = Fastify ( ) ;
103- mountFastify ( {
104- fastify, path : "/subscribers" , db, table : subscribers ,
105- insertSchema : InsertSchema , updateSchema : UpdateSchema ,
106- filterAllowlist, sortAllowlist, dialect : "postgres" ,
107- } ) ;
108- await fastify . ready ( ) ;
136+ for ( const e of entries ) {
137+ const h = new Hono ( ) ;
138+ e . hono ( {
139+ app : h , path : "/subscribers" , db, table : subscribers ,
140+ insertSchema : InsertSchema , updateSchema : UpdateSchema ,
141+ filterAllowlist, sortAllowlist, dialect : "postgres" ,
142+ } ) ;
143+ const f = Fastify ( ) ;
144+ e . fastify ( {
145+ fastify : f , path : "/subscribers" , db, table : subscribers ,
146+ insertSchema : InsertSchema , updateSchema : UpdateSchema ,
147+ filterAllowlist, sortAllowlist, dialect : "postgres" ,
148+ } ) ;
149+ await f . ready ( ) ;
150+ fastifies . push ( f ) ;
151+ adapters . push (
152+ {
153+ name : `hono (${ e . tree } )` ,
154+ get : async ( url ) => {
155+ const res = await h . request ( url ) ;
156+ return { status : res . status , body : res . status === 204 ? null : await res . json ( ) } ;
157+ } ,
158+ } ,
159+ {
160+ name : `fastify (${ e . tree } )` ,
161+ get : async ( url ) => {
162+ const res = await f . inject ( { method : "GET" , url } ) ;
163+ return { status : res . statusCode , body : res . statusCode === 204 ? null : res . json ( ) } ;
164+ } ,
165+ } ,
166+ ) ;
167+ }
109168 } ) ;
110169
111170 afterAll ( async ( ) => {
112- await fastify ? .close ( ) ;
171+ for ( const f of fastifies ) await f . close ( ) ;
113172 await pool . query ( `DROP TABLE IF EXISTS mo286_subscribers` ) ;
114173 await pool . end ( ) ;
115174 } ) ;
116175
117- /** Uniform request surface so the same assertions run against both adapters. */
118- const adapters : Array < { name : string ; get : ( url : string ) => Promise < { status : number ; body : unknown } > } > = [
119- {
120- name : "hono" ,
121- get : async ( url ) => {
122- const res = await hono . request ( url ) ;
123- return { status : res . status , body : res . status === 204 ? null : await res . json ( ) } ;
124- } ,
125- } ,
126- {
127- name : "fastify" ,
128- get : async ( url ) => {
129- const res = await fastify . inject ( { method : "GET" , url } ) ;
130- return { status : res . statusCode , body : res . statusCode === 204 ? null : res . json ( ) } ;
131- } ,
132- } ,
133- ] ;
134-
135- for ( const a of adapters ) {
136- describe ( a . name , ( ) => {
176+ test ( "the BUILT tree is present, so Node's entry point is actually covered" , ( ) => {
177+ // dist/ is what `exports.default` resolves to. If it is missing the matrix silently
178+ // halves, which is the failure mode this whole file exists to prevent — so say so.
179+ expect ( builtTreeMissing ) . toBe ( false ) ;
180+ expect ( adapters . map ( ( a ) => a . name ) . sort ( ) ) . toEqual ( [
181+ "fastify (dist)" , "fastify (src)" , "hono (dist)" , "hono (src)" ,
182+ ] ) ;
183+ } ) ;
184+
185+ for ( const a of ADAPTER_NAMES ) {
186+ describe ( a , ( ) => {
137187 test ( "list returns rows (the exact call that threw `q.all is not a function`)" , async ( ) => {
138- const { status, body } = await a . get ( "/subscribers" ) ;
188+ const { status, body } = await use ( a ) . get ( "/subscribers" ) ;
139189 expect ( status ) . toBe ( 200 ) ;
140190 expect ( Array . isArray ( body ) ) . toBe ( true ) ;
141191 expect ( ( body as unknown [ ] ) . length ) . toBe ( 3 ) ;
142192 } ) ;
143193
144194 test ( "get-by-id returns one row (the `.get()` path)" , async ( ) => {
145- const list = ( await a . get ( "/subscribers" ) ) . body as Array < { id : number ; email : string } > ;
195+ const list = ( await use ( a ) . get ( "/subscribers" ) ) . body as Array < { id : number ; email : string } > ;
146196 const target = list . find ( ( r ) => r . email === "bob@x.com" ) ;
147197 expect ( target ) . toBeDefined ( ) ;
148- const { status, body } = await a . get ( `/subscribers/${ target ?. id } ` ) ;
198+ const { status, body } = await use ( a ) . get ( `/subscribers/${ target ?. id } ` ) ;
149199 expect ( status ) . toBe ( 200 ) ;
150200 expect ( ( body as { email : string } ) . email ) . toBe ( "bob@x.com" ) ;
151201 } ) ;
152202
153203 test ( "get-by-id 404s for a missing row rather than throwing" , async ( ) => {
154- const { status } = await a . get ( "/subscribers/99999" ) ;
204+ const { status } = await use ( a ) . get ( "/subscribers/99999" ) ;
155205 expect ( status ) . toBe ( 404 ) ;
156206 } ) ;
157207
158208 test ( "withCount returns the {rows,total} envelope (the count-query `.all()` path)" , async ( ) => {
159- const { status, body } = await a . get ( "/subscribers?withCount=1" ) ;
209+ const { status, body } = await use ( a ) . get ( "/subscribers?withCount=1" ) ;
160210 expect ( status ) . toBe ( 200 ) ;
161211 const env = body as { rows : unknown [ ] ; total : number } ;
162212 expect ( Array . isArray ( env . rows ) ) . toBe ( true ) ;
163213 expect ( env . total ) . toBe ( 3 ) ;
164214 } ) ;
165215
166216 test ( "filter + sort execute on Postgres" , async ( ) => {
167- const { status, body } = await a . get ( "/subscribers?filter[subscribed]=true&sort=email:desc" ) ;
217+ const { status, body } = await use ( a ) . get ( "/subscribers?filter[subscribed]=true&sort=email:desc" ) ;
168218 expect ( status ) . toBe ( 200 ) ;
169219 const rows = body as Array < { email : string } > ;
170220 expect ( rows . map ( ( r ) => r . email ) ) . toEqual ( [ "carol@y.com" , "alice@x.com" ] ) ;
171221 } ) ;
172222 } ) ;
173223 }
174224
175- test ( "both adapters return the SAME list payload — the matrix's whole point" , async ( ) => {
176- const [ h , f ] = await Promise . all ( [
177- a0 ( ) . get ( "/subscribers?sort=email:asc" ) ,
178- a1 ( ) . get ( "/subscribers?sort=email:asc" ) ,
179- ] ) ;
180- expect ( h . status ) . toBe ( f . status ) ;
181- expect ( h . body ) . toEqual ( f . body ) ;
225+ test ( "every adapter x entry-point returns the SAME payload — the matrix's whole point" , async ( ) => {
226+ const results = await Promise . all (
227+ ADAPTER_NAMES . map ( async ( n ) => ( { n, r : await use ( n ) . get ( "/subscribers?sort=email:asc" ) } ) ) ,
228+ ) ;
229+ const [ first , ...rest ] = results ;
230+ for ( const other of rest ) {
231+ expect ( `${ other . n } :${ other . r . status } ` ) . toBe ( `${ other . n } :${ first ! . r . status } ` ) ;
232+ expect ( other . r . body ) . toEqual ( first ! . r . body ) ;
233+ }
182234 } ) ;
183-
184- function a0 ( ) { return adapters [ 0 ] ! ; }
185- function a1 ( ) { return adapters [ 1 ] ! ; }
186235} ) ;
0 commit comments