Skip to content

Commit 5018286

Browse files
test(dbt-tools): run the Bun case as the CLI with a temp HOME
The in-process case read this machine's ~/.dbt/dbt_cloud.yml: Bun's os.homedir() ignores a runtime HOME change. The stand-in quotes an apostrophe in its log path, and diagnose() loses the python-bridge branch nothing can reach now. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VEmKQtZqePG8x1GSELVNdE
1 parent c0f6a99 commit 5018286

3 files changed

Lines changed: 26 additions & 22 deletions

File tree

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ function flag(args: string[], name: string): string | undefined {
3737

3838
function diagnose(err: Error): { error: string; fix?: string } {
3939
const msg = err.message || String(err)
40-
if (msg.includes("private field") || msg.includes("#stdin") || msg.includes("#stdout")) {
41-
return {
42-
error: "Internal error: Bun runtime incompatibility in the dbt adapter. Please report this issue.",
43-
fix: "Try updating: bun install, or file a bug at https://github.com/AltimateAI/altimate-code/issues",
44-
}
45-
}
4640
if (msg.includes("IPC channel") || msg.includes("ERR_IPC_CHANNEL_CLOSED")) {
4741
return {
4842
error: "Failed to start Python bridge. The dbt Python process exited unexpectedly.",

‎packages/dbt-tools/test/adapter-bun.test.ts‎

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,46 @@ import { describe, test, expect } from "bun:test"
22
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "fs"
33
import { tmpdir } from "os"
44
import { dirname, join } from "path"
5-
import { create } from "../src/adapter"
5+
import { $ } from "bun"
66
import { 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.
1114
describe.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 })

‎packages/dbt-tools/test/stand-in-python.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function standInPython(root: string) {
1414
python,
1515
[
1616
"#!/bin/sh",
17-
`printf '%s\\n' "$*" >> '${argvLog}'`,
17+
`printf '%s\\n' "$*" >> '${argvLog.replaceAll("'", "'\\''")}'`,
1818
'case "$1" in',
1919
' --version) echo "Python 3.11.9"; exit 0 ;;',
2020
' -c) echo "1.10.0"; exit 0 ;;',

0 commit comments

Comments
 (0)