11import { describe , test , expect , beforeAll } from "bun:test"
22import {
3- chmodSync ,
43 cpSync ,
54 existsSync ,
65 mkdirSync ,
@@ -13,6 +12,7 @@ import {
1312import { tmpdir } from "os"
1413import { dirname , join } from "path"
1514import { $ } from "bun"
15+ import { standInPython } from "./stand-in-python"
1616
1717const pkg = join ( import . meta. dir , ".." )
1818const dist = join ( pkg , "dist" )
@@ -65,9 +65,8 @@ describe("build integrity", () => {
6565 } )
6666
6767 // The published package (see opencode/script/publish.ts copyAssets) is run by
68- // Node from wherever npm installed it. A stand-in `python` records what it is
69- // asked to run and answers the CLI's prerequisite checks, so this follows the
70- // real startup as far as spawning the bridge, without Python or dbt installed.
68+ // Node from wherever npm installed it. With the stand-in `python`, this follows
69+ // the real startup as far as spawning the bridge, without Python or dbt installed.
7170 async function startPublished ( root : string , dbtIntegration : string ) {
7271 const installed = join ( root , "install" , "dbt-tools" )
7372 mkdirSync ( join ( installed , "bin" ) , { recursive : true } )
@@ -77,21 +76,7 @@ describe("build integrity", () => {
7776 cpSync ( join ( dist , "node_python_bridge.py" ) , join ( installed , "dist/node_python_bridge.py" ) )
7877 writeFileSync ( join ( installed , "package.json" ) , JSON . stringify ( { type : "module" } ) )
7978
80- const argvLog = join ( root , "argv.log" )
81- const python = join ( root , "python" )
82- writeFileSync (
83- python ,
84- [
85- "#!/bin/sh" ,
86- `printf '%s\\n' "$*" >> '${ argvLog } '` ,
87- 'case "$1" in' ,
88- ' --version) echo "Python 3.11.9"; exit 0 ;;' ,
89- ' -c) echo "1.10.0"; exit 0 ;;' ,
90- "esac" ,
91- "exit 3" ,
92- ] . join ( "\n" ) + "\n" ,
93- )
94- chmodSync ( python , 0o755 )
79+ const { python, runs } = standInPython ( root )
9580 const project = join ( root , "project" )
9681 mkdirSync ( project )
9782 writeFileSync ( join ( project , "dbt_project.yml" ) , "name: p\nversion: '1.0'\nprofile: p\n" )
@@ -103,38 +88,49 @@ describe("build integrity", () => {
10388 JSON . stringify ( { projectRoot : project , pythonPath : python , dbtIntegration, queryLimit : 500 } ) ,
10489 )
10590
106- await $ `node ${ join ( installed , "bin/altimate-dbt" ) } info`
91+ const cli = await $ `node ${ join ( installed , "bin/altimate-dbt" ) } info`
10792 . cwd ( root )
10893 . env ( { ...process . env , HOME : home } )
10994 . quiet ( )
11095 . nothrow ( )
11196
11297 // Node loads the bundle by its real path; on macOS `tmpdir()` is under the `/var` symlink.
11398 const script = join ( realpathSync ( installed ) , "dist" , "node_python_bridge.py" )
114- return { script, runs : readFileSync ( argvLog , "utf8" ) . split ( "\n" ) }
99+ return { script, runs : runs ( ) , exitCode : cli . exitCode , output : cli . stdout . toString ( ) }
115100 }
116101
102+ // The stand-in `python` is a `#!/bin/sh` script.
103+ const posixOnly = test . skipIf ( process . platform === "win32" )
104+
117105 // A dbt Cloud variant other than fusion-stable, here an unknown one, runs on a dbt Core
118106 // command engine, which starts the bridge. Without that engine's dependencies it throws first.
119- test . skipIf ( process . platform === "win32" ) (
107+ posixOnly (
120108 "the published package starts dbt Cloud mode's dbt Core command engine" ,
121109 async ( ) => {
122110 const root = mkdtempSync ( join ( tmpdir ( ) , "dbt-tools-cloud-" ) )
123111 try {
124- const { script, runs } = await startPublished ( root , "cloud" )
112+ const { script, runs, exitCode, output } = await startPublished ( root , "cloud" )
113+ // `info` answers from the project once the engine's bridge has failed. A failure
114+ // before the spawn exits 1, and the comparison shows the CLI's message.
115+ expect ( { exitCode, output } ) . toMatchObject ( { exitCode : 0 } )
125116 expect ( runs ) . toContain ( script )
126117 } finally {
127118 rmSync ( root , { recursive : true , force : true } )
128119 }
129120 } ,
130121 )
131122
132- test . skipIf ( process . platform === "win32" ) (
123+ posixOnly (
133124 "the published package starts the bridge script next to its own bundle, from any directory" ,
134125 async ( ) => {
135126 const root = mkdtempSync ( join ( tmpdir ( ) , "dbt-tools-published-" ) )
136127 try {
137- const { script, runs } = await startPublished ( root , "corecommand" )
128+ const { script, runs, exitCode, output } = await startPublished ( root , "corecommand" )
129+ // The CLI fails on the stand-in's exit, so after the spawn.
130+ expect ( { exitCode, output } ) . toMatchObject ( {
131+ exitCode : 1 ,
132+ output : expect . stringContaining ( "Python process closed with exit code 3" ) ,
133+ } )
138134 expect ( runs ) . toContain ( script )
139135 expect ( existsSync ( script ) ) . toBe ( true )
140136 } finally {
0 commit comments