-
Notifications
You must be signed in to change notification settings - Fork 26
fix: altimate-dbt commands fail with hardcoded CI path in published binary
#467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
baa5dfd
fix: patch hardcoded `__dirname` in `dbt-tools` bundle so `altimate-d…
suryaiyer95 2cc41eb
fix: address PR review — add Node 18 fallback and broaden path assert…
suryaiyer95 da04c8e
fix: drop Node 18 fallback — `path` is not in scope before `__dirname…
suryaiyer95 d6c92af
fix: copy `node_python_bridge.py` in `publish.ts` so npm tarball incl…
suryaiyer95 f90f52a
fix: spread real `child_process` in `mock.module` to prevent `execFil…
suryaiyer95 66c7e6c
fix: use __require fallback for __dirname to support Node < 20.11.0
mdesmet 6764fef
style: format `dbt-cli.test.ts` and `publish.ts` with Prettier
anandgupta42 825750b
test: add adversarial tests for `__dirname` patch and build integrity
anandgupta42 9d6336f
Merge branch 'main' into fix/dbt-tools-python-bridge-dirname
anandgupta42 1e8f16b
fix: address code review — existence check, comment fix, better diagn…
anandgupta42 93eba4b
test: expand adversarial tests to 43 cases covering runtime, publish,…
anandgupta42 44b1e81
fix: eliminate flaky CI test failures in dispatcher, dbt, and tracer …
anandgupta42 8260216
fix: replace environment-coupled `runner` assertion with directory ex…
anandgupta42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,42 @@ | ||
| import { cpSync } from "fs" | ||
| import { cpSync, existsSync, readFileSync, writeFileSync } from "fs" | ||
| import { dirname, join } from "path" | ||
|
|
||
| const dist = join(import.meta.dir, "..", "dist") | ||
|
|
||
| // 1. Copy altimate_python_packages | ||
| const resolved = require.resolve("@altimateai/dbt-integration") | ||
| const source = join(dirname(resolved), "altimate_python_packages") | ||
| const target = join(import.meta.dir, "..", "dist", "altimate_python_packages") | ||
|
|
||
| cpSync(source, target, { recursive: true }) | ||
| cpSync(source, join(dist, "altimate_python_packages"), { recursive: true }) | ||
| console.log(`Copied altimate_python_packages → dist/`) | ||
|
|
||
| // 2. Copy node_python_bridge.py into dist so it lives next to index.js | ||
| // node_python_bridge.py is shipped in dbt-integration's dist | ||
| const bridgePy = join(dirname(resolved), "node_python_bridge.py") | ||
| if (!existsSync(bridgePy)) { | ||
| console.error(`ERROR: node_python_bridge.py not found at ${bridgePy}`) | ||
| console.error(` Is @altimateai/dbt-integration up to date?`) | ||
| process.exit(1) | ||
| } | ||
| cpSync(bridgePy, join(dist, "node_python_bridge.py")) | ||
| console.log(`Copied node_python_bridge.py → dist/`) | ||
|
|
||
| // 3. Fix the hardcoded __dirname that bun bakes at compile time. | ||
| // Replace it with a runtime resolution so the bridge script is found | ||
| // relative to the built index.js, not the CI runner's node_modules. | ||
| const indexPath = join(dist, "index.js") | ||
| let code = readFileSync(indexPath, "utf8") | ||
| const pattern = /var __dirname\s*=\s*"[^"]*python-bridge[^"]*"/ | ||
| if (pattern.test(code)) { | ||
| // import.meta.dirname is supported by Bun and Node >= 20.11.0. | ||
| // Fallback via __require handles older runtimes where import.meta.dirname is unavailable. | ||
| const replacement = `var __dirname = typeof import.meta.dirname === "string" ? import.meta.dirname : __require("path").dirname(__require("url").fileURLToPath(import.meta.url))` | ||
| code = code.replace(pattern, replacement) | ||
| writeFileSync(indexPath, code) | ||
| console.log(`Patched __dirname in dist/index.js`) | ||
| } else { | ||
| const found = code.match(/var __dirname[^;]*/)?.[0] ?? "(not found)" | ||
| console.error(`ERROR: could not find python-bridge __dirname to patch — the bundle format may have changed`) | ||
| console.error(` Pattern: ${pattern}`) | ||
| console.error(` Nearest match: ${found}`) | ||
| process.exit(1) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.