@@ -7,6 +7,11 @@ import { join } from "node:path";
77 * cannot be imported by tests. Guard its Windows-critical invariants at the source level.
88 */
99const source = readFileSync ( join ( import . meta. dir , ".." , "bin" , "ocx.mjs" ) , "utf8" ) ;
10+ const runtimeSource = readFileSync ( join ( import . meta. dir , ".." , "src" , "lib" , "bun-runtime.ts" ) , "utf8" ) ;
11+ const validatorSource = readFileSync (
12+ join ( import . meta. dir , ".." , "src" , "lib" , "bun-binary-validator.mjs" ) ,
13+ "utf8" ,
14+ ) ;
1015
1116describe ( "ocx.mjs npm launcher (source invariants)" , ( ) => {
1217 test ( "Windows npm spawns use the trusted absolute invocation without shell lookup" , ( ) => {
@@ -51,14 +56,16 @@ describe("ocx.mjs npm launcher (source invariants)", () => {
5156 } ) ;
5257
5358 test ( "invalid Bun overrides warn safely and fall back without throwing" , ( ) => {
54- expect ( source ) . toContain ( "function isRealBunBinary(path) {" ) ;
55- expect ( source ) . toMatch ( / f u n c t i o n i s R e a l B u n B i n a r y \( p a t h \) \{ [ \s \S ] * ?t r y \{ [ \s \S ] * ?s t a t S y n c \( p a t h \) [ \s \S ] * ?c a t c h \{ [ \s \S ] * ?r e t u r n f a l s e ; / ) ;
59+ expect ( source ) . toContain ( 'import { isRealBunBinary } from "../src/lib/bun-binary-validator.mjs";' ) ;
5660 expect ( source ) . toContain ( "is missing, unreadable, or not a complete Bun binary; falling back to the bundled runtime." ) ;
5761 expect ( source ) . not . toContain ( '${override} is missing, unreadable' ) ;
5862 } ) ;
5963
60- test ( "documents why the Node launcher keeps a synchronized validator copy" , ( ) => {
61- expect ( source ) . toContain ( "this Node-safe copy aligned with src/lib/bun-runtime.ts" ) ;
62- expect ( source ) . toContain ( "cannot\n// import Bun-native TypeScript until after it has resolved a Bun executable" ) ;
64+ test ( "shares the Node-safe Bun binary validator across both runtime paths" , ( ) => {
65+ expect ( source ) . toContain ( 'import { isRealBunBinary } from "../src/lib/bun-binary-validator.mjs";' ) ;
66+ expect ( runtimeSource ) . toContain ( 'import { isRealBunBinary } from "./bun-binary-validator.mjs";' ) ;
67+ expect ( runtimeSource ) . toContain ( "export { isRealBunBinary };" ) ;
68+ expect ( validatorSource ) . toContain ( "export const REAL_BUN_MIN_BYTES = 1_000_000;" ) ;
69+ expect ( validatorSource ) . toMatch ( / e x p o r t f u n c t i o n i s R e a l B u n B i n a r y \( p a t h \) \{ [ \s \S ] * ?t r y \{ [ \s \S ] * ?s t a t S y n c \( p a t h \) [ \s \S ] * ?c a t c h \{ [ \s \S ] * ?r e t u r n f a l s e ; / ) ;
6370 } ) ;
6471} ) ;
0 commit comments