fix(discover): detect extensionless scripts by shebang - #1203
Conversation
Signed-off-by: ibaldr89 <163388887+ibaldr89@users.noreply.github.com>
|
Thanks — acknowledged here too, and I have replied in detail on #1199 confirming the underlying bug on current Short version of that confirmation: Queued for review. The branch is CONFLICTING against |
|
Thank you — the implementation here is careful, and I want to say what I checked before raising anything: the probe is bounded and read-only, it uses Two things before it can land. 1. It needs a rebase — it currently conflicts with 2. One behavioural question I would like your view on. The description says extension detection stays authoritative, but the fallback fires whenever There is a cost attached to that breadth: in FULL mode every unknown file gets an open and a read. Either resolution is fine by me: gate the probe to genuinely extensionless basenames, or keep the breadth and say explicitly in the description why unknown extensions should participate and why the discovery I/O is acceptable at scale. I would just rather that be a decision than a side effect. Worth noting for transparency: #1199 was filed by you a day before this PR, so the direction has not been through maintainer triage — but the fit is good. Finding code the graph currently misses is exactly the kind of coverage gap we want closed. |
|
This is the best-engineered contribution I have reviewed in this backlog sweep, and I want to be specific about why rather than just saying so. It needs one rebase and then I would like to merge it. I measured the cost concern empirically rather than estimating it, because "open and read every candidate file" is exactly the kind of change that quietly costs real time at scale. On the actual 94,851-file Linux kernel checkout:
And the over-inclusion question came out equally clean: 301 candidates have a shebang, ~294 newly indexed — 196 The fail-closed discipline throughout is exemplary. Every ambiguous input declines rather than guessing:
You used The tests are what this repo actually asks for. Eighteen of them, running end-to-end through the production What is needed: a rebase. The branch conflicts with main, but the conflict is mechanical — one call-site line plus a self-contained function, and the early-return branch it hooks into is unchanged. The One thing to look at after rebasing, which is new since you branched: main gained One optional follow-up, not for this PR: the interpreter table is conservative and misses several languages we already support — Rebase and ping me; I will re-diff and merge. |
Summary
/usr/bin/envandenv -Sfor common supported scripting languagesFixes #1199
Why
Executable source scripts commonly omit a filename extension. Before this change, files such as:
were silently absent from the graph even though Python is supported. Full indexing did not change that because language detection was filename-only.
Behavior
Existing detection remains authoritative. Shebang detection runs only when
cbm_language_for_filename()returnsCBM_LANG_COUNT.Supported interpreter basenames:
python,python2,python3, dotted numeric versions such aspython3.12sh,bash,dash,ksh,zshnode,nodejsruby,perl,php,luaThe probe reads at most 255 bytes plus one EOF/truncation probe byte, rejects embedded NUL, read errors, overlong first lines, unsupported
envoption/assignment shapes, and arbitrary prefix matches such aspython-wrapper.Related work checked
No existing issue or PR found in the checked open/closed history implements shebang-based language fallback for extensionless source files.
Testing
Full suite comparison in the same isolated Docker environment:
main: 6180 passed, 0 failedtests/test_httpd.c:358; no candidate-only failure was introduced