@@ -2,36 +2,46 @@ import { describe, test, expect } from "bun:test"
22import { mkdirSync , mkdtempSync , rmSync , writeFileSync } from "fs"
33import { tmpdir } from "os"
44import { dirname , join } from "path"
5- import { create } from "../src/adapter "
5+ import { $ } from "bun "
66import { standInPython } from "./stand-in-python"
77
8+ const pkg = join ( import . meta. dir , ".." )
9+
810// The published-package tests run the bundle under Node. The TUI and the compiled
911// binary run the adapter under Bun, the runtime the bridge used to fail on, so this
10- // starts it there.
12+ // runs the CLI from source under Bun. HOME is a temp dir from the start, so no
13+ // ~/.dbt/dbt_cloud.yml on this machine picks dbt Cloud mode's variant.
1114describe . skipIf ( process . platform === "win32" ) ( "the adapter under Bun" , ( ) => {
1215 const script = join ( dirname ( require . resolve ( "@altimateai/dbt-integration" ) ) , "node_python_bridge.py" )
1316
14- // The stand-in fails the bridge run. The dbt Core modes then reject with the bridge's
15- // report of that exit, and dbt Cloud mode resolves anyway. A failure before the
16- // spawn rejects with its own message.
17+ // The stand-in fails the bridge run. The dbt Core modes then exit 1 with the bridge's
18+ // report of that exit; `info` in dbt Cloud mode still answers from the project. A
19+ // failure before the spawn shows its own message in the comparison .
1720 test . each ( [
18- [ "core" , "rejects" ] ,
19- [ "corecommand" , "rejects" ] ,
20- [ "cloud" , "starts" ] ,
21- ] ) ( "%s mode spawns the bridge script and %s " , async ( dbtIntegration , outcome ) => {
21+ [ "core" , { exitCode : 1 , output : expect . stringContaining ( "Python process closed with exit code 3" ) } ] ,
22+ [ "corecommand" , { exitCode : 1 , output : expect . stringContaining ( "Python process closed with exit code 3" ) } ] ,
23+ [ "cloud" , { exitCode : 0 } ] ,
24+ ] ) ( "%s mode spawns the bridge script" , async ( dbtIntegration , expected ) => {
2225 const root = mkdtempSync ( join ( tmpdir ( ) , "dbt-tools-bun-" ) )
2326 try {
2427 const { python, runs } = standInPython ( root )
2528 const project = join ( root , "project" )
2629 mkdirSync ( project )
2730 writeFileSync ( join ( project , "dbt_project.yml" ) , "name: p\nversion: '1.0'\nprofile: p\n" )
31+ const home = join ( root , "home" )
32+ mkdirSync ( join ( home , ".altimate-code" ) , { recursive : true } )
33+ writeFileSync (
34+ join ( home , ".altimate-code" , "dbt.json" ) ,
35+ JSON . stringify ( { projectRoot : project , pythonPath : python , dbtIntegration, queryLimit : 500 } ) ,
36+ )
37+
38+ const cli = await $ `${ process . execPath } ${ join ( pkg , "src/index.ts" ) } info`
39+ . cwd ( root )
40+ . env ( { ...process . env , HOME : home } )
41+ . quiet ( )
42+ . nothrow ( )
2843
29- const started = create ( { projectRoot : project , pythonPath : python , dbtIntegration, queryLimit : 500 } )
30- if ( outcome === "rejects" ) {
31- await expect ( started ) . rejects . toThrow ( "Python process closed with exit code 3" )
32- } else {
33- await ( await started ) . dispose ( )
34- }
44+ expect ( { exitCode : cli . exitCode , output : cli . stdout . toString ( ) } ) . toMatchObject ( expected )
3545 expect ( runs ( ) ) . toContain ( script )
3646 } finally {
3747 rmSync ( root , { recursive : true , force : true } )
0 commit comments