Repository navigation
Conversation
…ource paths (Graphify-Labs#2596) Form 3: Recognise $(dirname "$VAR") in source arguments — the dominant broken form (22 of 36 dropped statements in the reporter's repo). Treat $(dirname "$VAR") as var_bases[VAR].parent (or script_dir.parent when untracked), then resolve the literal suffix against it. Mirrors the existing _BASH_DIRNAME_IDIOM handler on assignment lines. Form 4: Allow .. in the literal suffix when the base comes from a tracked var_bases entry (a known directory). Keep the .. rejection on the script-dir-guess path where the base is uncertain. Adds 4 regression tests: dirname with tracked var, dirname with untracked var, dotdot suffix with tracked var, and dotdot suffix still rejected on the script-dir-guess path.
There was a problem hiding this comment.
Graphify reviewed this change.
Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).
Formal verification. 1 change(s) tested, no difference found (not proven).
Graphify review — findings
This PR modifies the Bash extractor's source statement resolution to handle two additional forms of variable-built source arguments. It adds support for the $(dirname "$VAR") command-substitution idiom appearing directly in a source argument (resolving it via tracked variable bases or a script-dir fallback), and threads an allow_dotdot parameter through _bash_source_suffix so .. traversal segments are permitted only when the base comes from a known tracked variable. The change also adds several new test cases in tests/test_extract.py covering these dirname/command-substitution and ..-suffix scenarios (tracked and untracked variable cases). The large number of listed changed test symbols suggests line-shift or renumbering effects across the test file's rationale entries.
No blocking issues surfaced. 6 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 328 functions depend on the 328 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
extract_bash()— 38 callers, 10 callees - worse:
walk()— 1 callers, 9 callees
Verification — 328 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 328 function(s) in the blast radius were not formally verified this run
Formal verification
No difference found (not proven): No behavior difference found in \_bash\_source\_suffix (not a proof).
The verifier ran both versions of \_bash\_source\_suffix on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.
Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.
Note: An input the sampler did not try could still differ.
Could not verify: Could not verify extract\_bash.
The verifier did not have enough to check extract\_bash, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set
· 2 more finding(s) on lines outside this diff (see the check run).
The #2690 form-3 (`$(dirname …)`) branch had no `..` guard and the tracked form-4 branch let `..` walk past the base to an arbitrary host path, so a hostile corpus could make the extractor stat and record an out-of-tree file (source "$(dirname "$VAR")/../../../../etc/passwd") — a corpus-side info leak, since resolve_bash_source_edges only filters *resolved* cross-file edges, not the extractor's own edge/probe. Adds a lexical _within_tree gate: form 3 rejects `..` outright (its base is a guess), and a tracked form-4 base may reach a sibling via $VAR/../lib but cannot escape past base.parent. Adds two traversal-rejection tests. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
For the record: this shipped in v0.9.44 (on PyPI), cherry-picked onto |
Summary
Fixes two of the four broken
sourcepath forms reported in #2596:Form 3 (highest-impact — 22 of 36 dropped statements in the reporter's repo):
source "$(dirname "$VAR")/lib/x.sh"— command substitution in thesourceargument. The new_BASH_SOURCE_DIRNAMEregex recognises the$(dirname "$VAR")idiom on the source line, the same way_BASH_DIRNAME_IDIOMalready recognises it on assignment lines. It resolves tovar_bases[VAR].parent(falling back toscript_dir.parentwhen VAR is untracked), then resolves the literal suffix against it.Form 4:
source "$VAR/../lib/y.sh"—..in the literal suffix. When the base comes from a trackedvar_basesentry (a known directory),..is safe and is resolved viaos.path.normpath. The..rejection is kept on the script-dir-guess path where the base is uncertain.Forms 1 (second-level variable assignment) and 2 (assignment inside
ifblocks) are left for a follow-up — they require deeper changes tovar_basesconstruction and are lower frequency.How to Test
uv run --frozen pytest tests/test_extract.py -k "dirname_cmdsubst or dotdot_suffix" -q --tb=short— 4 new tests, all passuv run --frozen pytest tests/test_extract.py -k "bash" -q --tb=short— all 46 bash tests pass (no regressions)uv run --frozen pytest tests/ -q --tb=short— 4323 passed (12 pre-existing skillgen/labeling failures on clean v8, unrelated to this change)RED→GREEN proof: with the fix reverted (clean v8), the 3 new resolution tests fail (0 edges produced). With the fix applied, all 4 pass (2 import edges produced + guard test verifying
..is still rejected for untracked vars).Type
Fixes #2596