Skip to content

Commit c0f6a99

Browse files
test(dbt-tools): start the adapter under Bun in CI and tighten the release check
A Bun test starts the adapter in each mode with a stand-in python; it fails on 0.2.14. The dbt-first test stops skipping the old python-bridge error, the release smoke check greps for the bridge name and the checkout path, and stale comments are updated. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VEmKQtZqePG8x1GSELVNdE
1 parent 9631118 commit c0f6a99

7 files changed

Lines changed: 105 additions & 60 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,16 @@ jobs:
291291
echo "::error::dbt-tools bundle lacks fileURLToPath(import.meta.url), which the bridge path is built from"
292292
exit 1
293293
fi
294+
# ...joined with the bare script name, not a literal path ending in it
295+
if ! grep -qF '"node_python_bridge.py"' packages/dbt-tools/dist/index.js; then
296+
echo "::error::dbt-tools bundle lacks the \"node_python_bridge.py\" name the bridge path is joined from"
297+
exit 1
298+
fi
299+
# No path from this checkout baked into the bundle
300+
if [ -z "$GITHUB_WORKSPACE" ] || grep -qF "$GITHUB_WORKSPACE" packages/dbt-tools/dist/index.js; then
301+
echo "::error::dbt-tools bundle contains the build checkout path, or GITHUB_WORKSPACE is unset"
302+
exit 1
303+
fi
294304
echo "dbt-tools smoke test passed"
295305
296306
- name: Free disk space for artifact download + npm publish

‎packages/dbt-tools/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"scripts": {
1010
"build": "bun build src/index.ts --outdir dist --target node --format esm && bun run script/copy-python.ts",
1111
"typecheck": "tsc --noEmit",
12-
"test": "bun test test/cli.test.ts test/config.test.ts test/dbt-cli.test.ts test/dbt-resolve.test.ts test/build-integrity.test.ts --timeout 30000",
12+
"test": "bun test test/cli.test.ts test/config.test.ts test/dbt-cli.test.ts test/dbt-resolve.test.ts test/adapter-bun.test.ts test/build-integrity.test.ts --timeout 30000",
1313
"test:e2e": "bun test test/e2e/ --timeout 300000"
1414
},
1515
"dependencies": {

‎packages/dbt-tools/src/index.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function diagnose(err: Error): { error: string; fix?: string } {
3939
const msg = err.message || String(err)
4040
if (msg.includes("private field") || msg.includes("#stdin") || msg.includes("#stdout")) {
4141
return {
42-
error: "Internal error: Bun runtime incompatibility with python-bridge. Please report this issue.",
42+
error: "Internal error: Bun runtime incompatibility in the dbt adapter. Please report this issue.",
4343
fix: "Try updating: bun install, or file a bug at https://github.com/AltimateAI/altimate-code/issues",
4444
}
4545
}
@@ -109,7 +109,7 @@ function bail(err: unknown): never {
109109
process.exit(1)
110110
}
111111

112-
// Catch unhandled rejections (bluebird throws outside normal promise chains)
112+
// An error that escapes main() still ends as a JSON error on stdout
113113
process.on("unhandledRejection", bail)
114114
process.on("uncaughtException", bail)
115115

@@ -142,7 +142,7 @@ async function main() {
142142
const { configure } = await import("./dbt-cli")
143143
configure({ pythonPath: cfg.pythonPath, projectRoot: cfg.projectRoot })
144144

145-
// Lazy import to avoid loading python-bridge until needed
145+
// Lazy import: the adapter loads dbt-integration, which commands above don't need
146146
let adapter
147147
try {
148148
const { create } = await import("./adapter")
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { describe, test, expect } from "bun:test"
2+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "fs"
3+
import { tmpdir } from "os"
4+
import { dirname, join } from "path"
5+
import { create } from "../src/adapter"
6+
import { standInPython } from "./stand-in-python"
7+
8+
// The published-package tests run the bundle under Node. The TUI and the compiled
9+
// binary run the adapter under Bun, the runtime the bridge used to fail on, so this
10+
// starts it there.
11+
describe.skipIf(process.platform === "win32")("the adapter under Bun", () => {
12+
const script = join(dirname(require.resolve("@altimateai/dbt-integration")), "node_python_bridge.py")
13+
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+
test.each([
18+
["core", "rejects"],
19+
["corecommand", "rejects"],
20+
["cloud", "starts"],
21+
])("%s mode spawns the bridge script and %s", async (dbtIntegration, outcome) => {
22+
const root = mkdtempSync(join(tmpdir(), "dbt-tools-bun-"))
23+
try {
24+
const { python, runs } = standInPython(root)
25+
const project = join(root, "project")
26+
mkdirSync(project)
27+
writeFileSync(join(project, "dbt_project.yml"), "name: p\nversion: '1.0'\nprofile: p\n")
28+
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+
}
35+
expect(runs()).toContain(script)
36+
} finally {
37+
rmSync(root, { recursive: true, force: true })
38+
}
39+
})
40+
})

‎packages/dbt-tools/test/build-integrity.test.ts‎

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { describe, test, expect, beforeAll } from "bun:test"
22
import {
3-
chmodSync,
43
cpSync,
54
existsSync,
65
mkdirSync,
@@ -13,6 +12,7 @@ import {
1312
import { tmpdir } from "os"
1413
import { dirname, join } from "path"
1514
import { $ } from "bun"
15+
import { standInPython } from "./stand-in-python"
1616

1717
const pkg = join(import.meta.dir, "..")
1818
const 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 {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { chmodSync, existsSync, readFileSync, writeFileSync } from "fs"
2+
import { join } from "path"
3+
4+
/**
5+
* A stand-in `python` in `root` that records what it is asked to run and answers
6+
* the CLI's prerequisite checks. Every other run, the bridge's included, exits 3,
7+
* so a test follows startup as far as spawning the bridge without Python or dbt
8+
* installed. It is a `#!/bin/sh` script, so the tests that use it skip Windows.
9+
*/
10+
export function standInPython(root: string) {
11+
const argvLog = join(root, "argv.log")
12+
const python = join(root, "python")
13+
writeFileSync(
14+
python,
15+
[
16+
"#!/bin/sh",
17+
`printf '%s\\n' "$*" >> '${argvLog}'`,
18+
'case "$1" in',
19+
' --version) echo "Python 3.11.9"; exit 0 ;;',
20+
' -c) echo "1.10.0"; exit 0 ;;',
21+
"esac",
22+
"exit 3",
23+
].join("\n") + "\n",
24+
)
25+
chmodSync(python, 0o755)
26+
const runs = () => (existsSync(argvLog) ? readFileSync(argvLog, "utf8").split("\n") : [])
27+
return { python, runs }
28+
}

‎packages/opencode/test/altimate/dbt-first-execution.test.ts‎

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -179,37 +179,8 @@ describe.skipIf(!HAS_DBT)("dbt-First SQL Execution E2E", () => {
179179
return
180180
}
181181

182-
// altimate_change: importing the adapter pulls in python-bridge, whose
183-
// bluebird `promisifyAll` over child_process throws under the Bun runtime
184-
// (private-field `#stdin` access) at MODULE LOAD — see dbt-tools/src/index.ts
185-
// diagnose(). That is an environment/dependency limitation, not a logic
186-
// regression, and only surfaces locally where a real dbt config is present
187-
// (CI has none and skips above). Skip rather than weaken; the assertion still
188-
// runs wherever python-bridge loads cleanly.
189-
const isPyBridgeIncompat = (e: unknown) => {
190-
const msg = (e as Error)?.message ?? String(e)
191-
return msg.includes("#stdin") || msg.includes("#stdout") || msg.includes("private field")
192-
}
193-
let create: (typeof import("../../../dbt-tools/src/adapter"))["create"]
194-
try {
195-
;({ create } = await import("../../../dbt-tools/src/adapter"))
196-
} catch (e) {
197-
if (isPyBridgeIncompat(e)) {
198-
console.log(" python-bridge/Bun incompatibility at import — skipping adapter assertion:", (e as Error).message)
199-
return
200-
}
201-
throw e
202-
}
203-
let adapter
204-
try {
205-
adapter = await create(cfg)
206-
} catch (e) {
207-
if (isPyBridgeIncompat(e)) {
208-
console.log(" python-bridge/Bun incompatibility — skipping adapter creation assertion:", (e as Error).message)
209-
return
210-
}
211-
throw e
212-
}
182+
const { create } = await import("../../../dbt-tools/src/adapter")
183+
const adapter = await create(cfg)
213184
expect(adapter).toBeTruthy()
214185
expect(adapter.immediatelyExecuteSQL).toBeInstanceOf(Function)
215186
}, 30000)

0 commit comments

Comments
 (0)