Repository navigation
Commit 59a9874
fix(drivers): keep our command line out of a driver's own resolution
`@mapbox/node-pre-gyp`, which packages several native modules including DuckDB,
resolves a module's manifest by parsing the **host application's**
`process.argv`. `find()` passes `argv: process.argv` into its own `Run`, `nopt`
abbreviation-matches whatever it finds against node-pre-gyp's option list, and
`node-pre-gyp.js:164` then does:
package_json_path = path.join(this.opts.directory, package_json_path)
`path.join`, not `path.resolve` — so an absolute manifest path is not
discarded. Our `--dir` abbreviates to node-pre-gyp's `--directory`, so
`altimate-code run --dir <project>` made the driver look for its manifest at
`<project>` concatenated with the manifest's own absolute path, and the load
failed with an ENOENT naming a path that had never existed.
That the failing path also looked cwd-prefixed was a coincidence: `--dir` is
what sets the working directory, so the two values were always equal.
Driver loads now run with `process.argv` trimmed to `[argv[0], argv[1]]`.
Swapping a global is safe here in a way `process.chdir()` would not be: the
load is a synchronous `require`, JavaScript is single-threaded, and there is no
`await` between the swap and the restore, so no concurrent work can observe it.
The asynchronous ESM fallback is deliberately left alone for that reason.
Considered and rejected: renaming `--dir`. The collision is real, but the flag
is public, renaming breaks every existing invocation, and it would fix only the
one option name that happens to collide today rather than the mechanism.
Not specific to us, to DuckDB, or to a compiled binary — any CLI embedding a
node-pre-gyp-packaged module and accepting a flag that abbreviates to
`--directory` is exposed. A long argv in a compiled binary only made it
visible. Of the drivers installed here, only `duckdb` pulls in node-pre-gyp
today; the fix is applied to every driver load rather than to DuckDB, because
the exposure is a property of the packaging tool, not of the driver.
The regression test reproduces the arithmetic of the one line that broke: a
fixture that reads `--dir` out of `process.argv` and joins it onto its own
absolute manifest path. With the neutralisation reverted it fails, reporting
the flag as seen. Two further tests pin that the command line is restored
afterwards, including when the load throws.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VqnuBDGkh1ZT65Ti7e6DHZ1 parent 6ba55f3 commit 59a9874
2 files changed
Lines changed: 151 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
519 | 519 | | |
520 | 520 | | |
521 | 521 | | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
522 | 563 | | |
523 | 564 | | |
524 | | - | |
| 565 | + | |
525 | 566 | | |
526 | 567 | | |
527 | 568 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
0 commit comments