Repository navigation
Conversation
Propagate statically known bash variable base directories (`bash_var_bases`) from loading scripts to sourced libraries that reference `$VAR/x` or `$(dirname "$VAR")/x` without reassigning `VAR`, resolving both `imports_from` (INFERRED, 0.85 confidence) and downstream cross-file `calls` edges via a cycle-safe fixed-point pass while staying fail-closed on conflicting loader values or out-of-root paths. Bump AST cache schema to 59 so cached bash extractions re-run portably across roots. Fixes Graphify-Labs#5563 Co-Authored-By: Gemini <[email protected]>
|
Thanks for the pull request, @m3lonxd. 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 
12 possible issues to check · High impact
The change tracks Bash variable-directory assignments and snapshots their values at source sites.
12 possible issues we couldn't confirm
- Functions with the same name in one file silently overwrite each other, so a call can resolve to the wrong function ·
graphify/symbol_resolution.py:714 - Guessed script-directory fallbacks can pass variable values to other scripts, which can create edges based on a guess ·
graphify/symbol_resolution.py:864 - Script-dir variables drop the path after
dirname(e.g./lib), sosourcelookups bind to the wrong file ·graphify/extractors/bash.py:161 - +9 more in Graphify
They don't change the score.
What this review covered
- A changed file's diff was too long to show in full, so the review may not have seen every changed line in it.
- 6 of 6 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 4571 functions depend on this change
- 5 functions became more coupled. Largest:
extract()(1424 callers),extract_bash()(52 callers),resolve_bash_source_edges()(17 callers). - 63 of 652 test files are affected by this change.
- Gate, test list and every flagged function: in the Graphify check.
Reviewed 7f61d7e · 13 earlier findings not re-checked
| for _stmt in root.children: | ||
| if _stmt.type == "variable_assignment": |
There was a problem hiding this comment.
Later variable assignments can misresolve earlier sourced scripts
A loader that changes a path variable after sourcing a library can make the library's import point to the wrong file.
Capture tracked path-variable values when each source runs in bash.py.
Evidence · checked against the code
Expected: Resolve the library's source using the variable's value when the loader sourced the library.
Actually: Resolve it using the loader's later tracked assignment, which can select a different file and produce incorrect import and sourced-call edges.
- Independent source review: Checked the source handling for tracked and untracked variables and the resolver's local-variable and blocked-variable checks. They do not preserve assignment state at each source location: a local tracked base is used directly, while a library without a local assignment receives the loader's precomputed base. The inspected tests cover tracked paths and resolver robustness, but not this before-source/after-source ordering case.
- This concerns statically tracked top-level assignments and source paths; dynamic shell control flow can create additional ordering cases.
- Some lookups asked for files or lines that do not exist; the review was told and carried on.
Prompt to fix with AI
In graphify/extractors/bash.py, _record_top_level_assignment (lines 746-747):
Problem: Later variable assignments can misresolve earlier sourced scripts
Expected: Resolve the library's source using the variable's value when the loader sourced the library.
Actually: Resolve it using the loader's later tracked assignment, which can select a different file and produce incorrect import and sourced-call edges.
Fix it at the cause, and add a test that fails without the fix.
Graphify · Checked against the code · View in Graphify
Track top-level bash variable assignments in source order during walk() so each top-level `source`/`.` statement resolves using and captures the `var_bases` and `assigned_unknown_vars` snapshot active at that exact line, while deferring function-body `source` resolution until top-level assignments finish and guarding tracked-variable `source` probes with `_safe_to_probe`. Propagate per-source-site snapshots through `resolve_bash_source_edges()` so earlier sourced libraries receive the variable bases active when they were sourced rather than later reassignments in the same loader, and add regression, cache-portability, and UNC probe-guard tests. Fixes P2 review finding on Graphify-Labs#5592 (for Graphify-Labs#5563). Co-Authored-By: Gemini <[email protected]>
|
Thanks @m3lonxd — the caller-defined-variable-base resolution (issue #5563) is a real gap and your implementation is well-tested in isolation (15 tests pass). We went a different way for v0.9.123, though: #5597 (tracked-dir invocation) and #5589 (cross-library sibling-sourced calls) landed as surgical fixes, and this PR is a ~1500-line rewrite that hard-conflicts with those plus #5568/#5570/#5578 and duplicates the schema bump. Could you bring the distinct cross-file caller-var feature back as a smaller PR rebased on top of #5589's resolver? Closing this form, but #5563 stays open — the feature is wanted, just in a smaller shape. |
…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)
Closes #5563
What does this PR do?
Propagates statically tracked Bash directory variables (
bash_var_bases) from loading scripts to sourced scripts (directly or transitively) so. "$ROOT/lib/beta.sh"andsource "$(dirname "$VAR")/lib/x.sh"resolve against the caller's variable binding when the sourced script does not defineVARitself, restoring bothimports_fromand downstreamcallsedges.Changes
graphify/extractors/bash.py:_bash_assignment_baseto resolve leading tracked$VAR/subassignments whenVARis already invar_bases.export/declare/readonlydeclaration_commandnodes) into portable in-rootbash_var_bases, tracked explicit unmodeled overwrites inbash_assigned_unknown_vars(preserving self-default fallbacks like${ROOT:-...}), and recorded deferred variable-basedsourceentries intobash_var_sources(alongside optionalfallback_target_pathwhen a script-dir guess existed).graphify/symbol_resolution.py:resolve_bash_source_edgesusing_safe_bash_base_identityand_resolve_bash_var_source_targetto resolve inherited$VAR/xand$(dirname "$VAR")/xsources (INFERRED,0.85confidence), feed resolved targets intosourced_filesfor downstreamcalls, and supersede wrong script-dir fallback decoys when a loader definesVAR.graphify/cache.py:_AST_CACHE_SCHEMA(58 -> 59) so stale cached bash payloads re-extract cleanly and anchorbash_var_basesportably via$graphify-root$.tests/test_extract.py,tests/test_symbol_resolution.py:test_extract_bash_sourced_file_resolves_caller_var_5563(proven failing on pre-fixv8) plus tests covering transitive loader propagation,export ROOT=..., Form 3$(dirname "$VAR"), Form 4$VAR/../lib, conflicting-loader fail-closed behavior, local overrides and dynamic overwrite guards, decoy superseding, standalone fallback preservation, out-of-tree/UNC traversal guards, cycles, malformed inputs, and relocated AST cache portability.Type of change
Verification & Invariants
VARvalues across multiple loaders emit nothing; dynamic local overwrites block caller inheritance; out-of-tree,..ceiling escapes, and UNC paths never probe or resolve.INFERRED(confidence_score=0.85), keeping extracted facts distinct from dynamic-variable inference.How was this tested?
uv run --frozen pytest tests/test_extract.py -k '5563 or bash' -q(71 passed, 309 deselected)uv run --frozen pytest tests/test_symbol_resolution.py tests/test_cache.py tests/test_node_id_canonical.py tests/test_affected_cli.py tests/test_extractors_registry.py -q(157 passed, 1 skipped Windows-only test)uv run --frozen ruff check .(passed)uv run --frozen pyright graphify/extractors/bash.py tests/test_symbol_resolution.py(0 errors)uv run --frozen python -m tools.skillgen --check(134 artifacts OK)uv run --frozen bandit -r graphify/extractors/bash.py graphify/symbol_resolution.py graphify/cache.py -ll -q(0 issues)Graphify-specific checklist
_AST_CACHE_SCHEMAbumped cleanly (58 -> 59)Co-Authored-Bytrailer included