Skip to content

Commit 9631118

Browse files
fix(dbt-tools): give dbt Cloud mode its dbt Core command engine
In 0.3.x every dbt Cloud variant but fusion-stable runs on a dbt Core command engine, which needs the Python strategy, configuration and client; without them every command failed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VEmKQtZqePG8x1GSELVNdE
1 parent ada3263 commit 9631118

2 files changed

Lines changed: 65 additions & 54 deletions

File tree

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ export async function create(cfg: Config): Promise<DBTProjectIntegrationAdapter>
143143
defer,
144144
changed,
145145
cloudVariantDetector,
146+
// Every variant but fusion-stable runs on a dbt Core command engine, which needs these.
147+
{ pythonDBTCommandExecutionStrategy: python, dbtConfiguration: config, dbtIntegrationClient: client },
146148
)
147149

148150
const command = (
@@ -172,18 +174,7 @@ export async function create(cfg: Config): Promise<DBTProjectIntegrationAdapter>
172174
defer: DeferConfig,
173175
changed: () => void,
174176
): DBTProjectIntegration =>
175-
new DBTFusionCommandProjectIntegration(
176-
infra,
177-
factory,
178-
cli,
179-
runtime,
180-
provider,
181-
term,
182-
root,
183-
diag,
184-
defer,
185-
changed,
186-
)
177+
new DBTFusionCommandProjectIntegration(infra, factory, cli, runtime, provider, term, root, diag, defer, changed)
187178

188179
const adapter = new DBTProjectIntegrationAdapter(
189180
config,

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

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -68,53 +68,73 @@ describe("build integrity", () => {
6868
// Node from wherever npm installed it. A stand-in `python` records what it is
6969
// asked to run and answers the CLI's prerequisite checks, so this follows the
7070
// real startup as far as spawning the bridge, without Python or dbt installed.
71+
async function startPublished(root: string, dbtIntegration: string) {
72+
const installed = join(root, "install", "dbt-tools")
73+
mkdirSync(join(installed, "bin"), { recursive: true })
74+
mkdirSync(join(installed, "dist"), { recursive: true })
75+
cpSync(join(pkg, "bin/altimate-dbt"), join(installed, "bin/altimate-dbt"))
76+
cpSync(join(dist, "index.js"), join(installed, "dist/index.js"))
77+
cpSync(join(dist, "node_python_bridge.py"), join(installed, "dist/node_python_bridge.py"))
78+
writeFileSync(join(installed, "package.json"), JSON.stringify({ type: "module" }))
79+
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)
95+
const project = join(root, "project")
96+
mkdirSync(project)
97+
writeFileSync(join(project, "dbt_project.yml"), "name: p\nversion: '1.0'\nprofile: p\n")
98+
// Under Node, HOME is the home directory, so there is no ~/.dbt/dbt_cloud.yml either.
99+
const home = join(root, "home")
100+
mkdirSync(join(home, ".altimate-code"), { recursive: true })
101+
writeFileSync(
102+
join(home, ".altimate-code", "dbt.json"),
103+
JSON.stringify({ projectRoot: project, pythonPath: python, dbtIntegration, queryLimit: 500 }),
104+
)
105+
106+
await $`node ${join(installed, "bin/altimate-dbt")} info`
107+
.cwd(root)
108+
.env({ ...process.env, HOME: home })
109+
.quiet()
110+
.nothrow()
111+
112+
// Node loads the bundle by its real path; on macOS `tmpdir()` is under the `/var` symlink.
113+
const script = join(realpathSync(installed), "dist", "node_python_bridge.py")
114+
return { script, runs: readFileSync(argvLog, "utf8").split("\n") }
115+
}
116+
117+
// A dbt Cloud variant other than fusion-stable, here an unknown one, runs on a dbt Core
118+
// command engine, which starts the bridge. Without that engine's dependencies it throws first.
119+
test.skipIf(process.platform === "win32")(
120+
"the published package starts dbt Cloud mode's dbt Core command engine",
121+
async () => {
122+
const root = mkdtempSync(join(tmpdir(), "dbt-tools-cloud-"))
123+
try {
124+
const { script, runs } = await startPublished(root, "cloud")
125+
expect(runs).toContain(script)
126+
} finally {
127+
rmSync(root, { recursive: true, force: true })
128+
}
129+
},
130+
)
131+
71132
test.skipIf(process.platform === "win32")(
72133
"the published package starts the bridge script next to its own bundle, from any directory",
73134
async () => {
74135
const root = mkdtempSync(join(tmpdir(), "dbt-tools-published-"))
75136
try {
76-
const installed = join(root, "install", "dbt-tools")
77-
mkdirSync(join(installed, "bin"), { recursive: true })
78-
mkdirSync(join(installed, "dist"), { recursive: true })
79-
cpSync(join(pkg, "bin/altimate-dbt"), join(installed, "bin/altimate-dbt"))
80-
cpSync(join(dist, "index.js"), join(installed, "dist/index.js"))
81-
cpSync(join(dist, "node_python_bridge.py"), join(installed, "dist/node_python_bridge.py"))
82-
writeFileSync(join(installed, "package.json"), JSON.stringify({ type: "module" }))
83-
84-
const argvLog = join(root, "argv.log")
85-
const python = join(root, "python")
86-
writeFileSync(
87-
python,
88-
[
89-
"#!/bin/sh",
90-
`printf '%s\\n' "$*" >> '${argvLog}'`,
91-
'case "$1" in',
92-
' --version) echo "Python 3.11.9"; exit 0 ;;',
93-
' -c) echo "1.10.0"; exit 0 ;;',
94-
"esac",
95-
"exit 3",
96-
].join("\n") + "\n",
97-
)
98-
chmodSync(python, 0o755)
99-
const project = join(root, "project")
100-
mkdirSync(project)
101-
writeFileSync(join(project, "dbt_project.yml"), "name: p\nversion: '1.0'\nprofile: p\n")
102-
const home = join(root, "home")
103-
mkdirSync(join(home, ".altimate-code"), { recursive: true })
104-
writeFileSync(
105-
join(home, ".altimate-code", "dbt.json"),
106-
JSON.stringify({ projectRoot: project, pythonPath: python, dbtIntegration: "corecommand", queryLimit: 500 }),
107-
)
108-
109-
await $`node ${join(installed, "bin/altimate-dbt")} info`
110-
.cwd(root)
111-
.env({ ...process.env, HOME: home })
112-
.quiet()
113-
.nothrow()
114-
115-
// Node loads the bundle by its real path; on macOS `tmpdir()` is under the `/var` symlink.
116-
const script = join(realpathSync(installed), "dist", "node_python_bridge.py")
117-
const runs = readFileSync(argvLog, "utf8").split("\n")
137+
const { script, runs } = await startPublished(root, "corecommand")
118138
expect(runs).toContain(script)
119139
expect(existsSync(script)).toBe(true)
120140
} finally {

0 commit comments

Comments
 (0)