Repository navigation
fix(bash): resolve script calls through tracked directory variables - #5597
azizur100389 wants to merge 2 commits into
Conversation
Refs Graphify-Labs#5566. Co-Authored-By: Codex <[email protected]>
|
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. |
There was a problem hiding this comment.
Graphify review 
1 bug · 3 possible issues to check · High impact
Bash script-invocation edges now resolve literal paths through earlier tracked directory assignments.
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
__entrysuffix on their call edge, unlike.shinvocations, 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, whileinvocation_basestreats them as unknown ·graphify/extractors/bash.py:700 - New test expects
./helperto resolve tobin/helperbut expectsbash helpernot 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
| def invoked_script(operand, runner: bool) -> Path | None: | ||
| raw = literal(operand) | ||
| word = text(operand) | ||
| base = path.parent |
There was a problem hiding this comment.
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 helperpath. Existing tests coverbash ./helpers.shand other explicit paths, not a same-named local file conflicting with a PATH target. - The actual runtime
PATHis 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
Co-Authored-By: Codex <[email protected]>
| _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) |
There was a problem hiding this comment.
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
$0directory 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
|
Shipped in v0.9.123, landed via authorship-preserving cherry-pick so your commits keep your name. Thanks @azizur100389! |
…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)
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
v8ata7295bca, 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.pytest tests/test_extract.py tests/test_cache.pyreported 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.