Skip to content

fix(bash): resolve script calls through tracked directory variables - #5597

Closed
azizur100389 wants to merge 2 commits into
Graphify-Labs:v8from
azizur100389:codex/bash-tracked-script-invocations
Closed

azizur100389 wants to merge 2 commits into
Graphify-Labs:v8from
azizur100389:codex/bash-tracked-script-invocations

Conversation

@azizur100389

@azizur100389 azizur100389 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5566.

A Bash script can invoke a sibling through a tracked directory variable, directly or through a shell runner. The extractor now resolves that path before selecting the target entrypoint. An extensionless target needs a Bash or sh shebang. A bare command still uses shell PATH semantics.

Verification

  • On clean v8 at a7295bca, the regression returned zero of the three expected call edges. It now finds the runner call, the variable-built helper call, and the literal helper call. It also checks a non-shell helper, a bare command, a bare shell-runner operand, and a single-quoted variable.
  • Windows: pytest tests/test_extract.py tests/test_cache.py reported 449 passed, 12 skipped, and one expected failure. Ruff and pre-commit passed. Project-wide Pyright reported 806 errors, the same count as clean v8. No diagnostics were reported for the Bash extractor.
  • Full upstream CI passed on Python 3.11, 3.12, 3.13 and 3.14. All seven workflow jobs passed.

@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @azizur100389. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 28, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify review View in Graphify

Review before merging · Merge confidence 4/5

1 bug · 3 possible issues to check · High impact

Bash script-invocation edges now resolve literal paths through earlier tracked directory assignments.

P2  Calls before a reassignment lose their script edge · bash.py:700

3 possible issues we couldn't confirm
  • Extensionless scripts invoked from shell get a __entry suffix on their call edge, unlike .sh invocations, so the edge may point at a nod · graphify/extractors/bash.py:599
  • Reassigned variables are still tracked with the earlier base in var_bases, while invocation_bases treats them as unknown · graphify/extractors/bash.py:700
  • New test expects ./helper to resolve to bin/helper but expects bash helper not to, though both depend on the working directory · tests/test_extract.py:4140

They don't change the score.

What this review covered
  • We didn't review 1 file that isn't source code, such as docs, config, images, or generated or third-party code.
  • A changed file's diff was too long to show in full, so the review may not have seen every changed line in it.
  • Part of a file with a line too long to show was not read.
  • 3 of 3 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 4429 functions depend on this change
  • 4 functions became more coupled. Largest: extract() (1417 callers), extract_bash() (52 callers), walk() (1 callers).
  • 652 of 652 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed c4d3081 · 5 earlier findings not re-checked

Comment on lines +297 to +300
def invoked_script(operand, runner: bool) -> Path | None:
raw = literal(operand)
word = text(operand)
base = path.parent

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2  bash helper can link to a local file Bash does not run

When a script runs bash helper, the graph can point to a same-named shell script beside the caller even when Bash finds a different helper through PATH.

Resolve extensionless operands through Bash’s PATH, or omit the edge when the target is unknown.

Evidence · checked against the code

Expected: The graph should identify the runtime target, or omit the edge when that target cannot be established.
Actually: The extractor resolves the adjacent file and emits a script-invocation edge to it without resolving Bash’s PATH target.

  • Independent source review: The caller skips this branch if the runner name is a locally defined function, which bounds that case but does not prevent the ordinary bash helper path. Existing tests cover bash ./helpers.sh and other explicit paths, not a same-named local file conflicting with a PATH target.
  • The actual runtime PATH is not available to the extractor, so the specific target may be unknowable statically.
Prompt to fix with AI
In graphify/extractors/bash.py, invoked_script (lines 297-300):
Problem: `bash helper` can link to a local file Bash does not run
Expected: The graph should identify the runtime target, or omit the edge when that target cannot be established.
Actually: The extractor resolves the adjacent file and emits a script-invocation edge to it without resolving Bash’s `PATH` target.
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

Comment on lines +697 to +700
_base = (_bash_assignment_base(_read_text(_value_node, source), path.parent)
if _value_node is not None else None)
# Multiple assignments make the runtime base uncertain.
invocation_bases[_name] = (_assign.end_byte, None if _name in invocation_bases else _base)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2  Calls before a reassignment lose their script edge

A top-level variable assigned more than once stops resolving script invocations, including invocations made before the reassignment.

Track top-level assignments by offset in invoked_script.

Evidence · checked against the code

Expected: The earlier invocation resolves using the base assigned before that invocation and emits a script-invocation edge.
Actually: The pre-pass marks the variable's tracked base unknown because it sees a later assignment; the resolver rejects the earlier use and emits no edge.

  • Independent source review: Checked the script-directory assignment idiom and the existing variable-built invocation tests. Those tests cover single assignments and dynamic or missing targets, not a later reassignment. The supplied proposal uses the recognized $0 directory idiom, invokes an existing sibling, then assigns the variable again; its assertion exercises the missing edge directly.
  • Also reported as: Earlier script calls disappear when a variable is reassigned later
Prompt to fix with AI
In graphify/extractors/bash.py, invoked_script (lines 697-700):
Problem: Calls before a reassignment lose their script edge
Expected: The earlier invocation resolves using the base assigned before that invocation and emits a script-invocation edge.
Actually: The pre-pass marks the variable's tracked base unknown because it sees a later assignment; the resolver rejects the earlier use and emits no edge.
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.123, landed via authorship-preserving cherry-pick so your commits keep your name. Thanks @azizur100389!

@safishamsi safishamsi closed this Nov 28, 2026
safishamsi pushed a commit that referenced this pull request Nov 30, 2026
…5563)

Surgical resubmission of #5592 layered directly on #5589 cross-library
sibling-sourced resolution and #5597 variable tracking.

- Tracks caller assignments in source order at program level
- Propagates caller-defined variable bases across sourcing chains
- Fails closed on UNC, out-of-root, cycles, and multi-caller conflicts
- Supersedes local fallback decoy edges

Fixes #5563

(cherry picked from commit cb00f8a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bash extractor: bash "$ROOT/lib/x.sh" and "$ROOT/bin/tool" (ROOT the script-dir idiom with ..; extensionless bash target) get no edge

2 participants