Skip to content

fix(discover): detect extensionless scripts by shebang#1203

Open
ibaldr89 wants to merge 1 commit into
DeusData:mainfrom
ibaldr89:fix/extensionless-shebang-language
Open

fix(discover): detect extensionless scripts by shebang#1203
ibaldr89 wants to merge 1 commit into
DeusData:mainfrom
ibaldr89:fix/extensionless-shebang-language

Conversation

@ibaldr89

@ibaldr89 ibaldr89 commented Jul 21, 2026

Copy link
Copy Markdown

Summary

  • fall back to a bounded first-line shebang probe when filename/special-filename/extension detection returns unknown
  • recognize direct interpreter paths plus /usr/bin/env and env -S for common supported scripting languages
  • preserve filename/extension precedence and fail closed on malformed, NUL-containing, truncated, or unreadable first lines
  • add production-discovery regressions for valid, conflicting, malformed, binary, env-assignment, and boundary cases

Fixes #1199

Why

Executable source scripts commonly omit a filename extension. Before this change, files such as:

#!/usr/bin/env python3

def extensionless_probe():
    return 42

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() returns CBM_LANG_COUNT.

Supported interpreter basenames:

  • Python: python, python2, python3, dotted numeric versions such as python3.12
  • shell: sh, bash, dash, ksh, zsh
  • JavaScript: node, nodejs
  • ruby, perl, php, lua

The probe reads at most 255 bytes plus one EOF/truncation probe byte, rejects embedded NUL, read errors, overlong first lines, unsupported env option/assignment shapes, and arbitrary prefix matches such as python-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

  • New tests added
  • Focused discovery suite: 107 passed under ASan/UBSan
  • CI lint stack: clang-format 20 + cppcheck 2.20 + NOLINT policy passed
  • GitHub Actions full matrix: 20/20 checks passed, including Linux x86/ARM, macOS, Windows, TSan, CodeQL, DCO, and lint
  • Real-repository regression: 7/7 extensionless entrypoints indexed versus 0/7 before; expected function and call graph became queryable
  • Independent exact-tree review: approved for commit

Full suite comparison in the same isolated Docker environment:

  • candidate: 6198 passed, 0 failed
  • clean main: 6180 passed, 0 failed
  • both runs exit non-zero on the same pre-existing 61-byte LeakSanitizer finding in tests/test_httpd.c:358; no candidate-only failure was introduced

Signed-off-by: ibaldr89 <163388887+ibaldr89@users.noreply.github.com>
@ibaldr89
ibaldr89 requested a review from DeusData as a code owner July 21, 2026 23:42
@DeusData DeusData added the bug Something isn't working label Jul 22, 2026
@DeusData DeusData added this to the 0.9.1-rc milestone Jul 22, 2026
@DeusData DeusData added parsing/quality Graph extraction bugs, false positives, missing edges ux/behavior Display bugs, docs, adoption UX priority/high Needs near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker. labels Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working parsing/quality Graph extraction bugs, false positives, missing edges priority/high Needs near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker. ux/behavior Display bugs, docs, adoption UX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(discover): extensionless scripts with valid shebangs are silently skipped

2 participants