Repository navigation
Merged
Conversation
…c-dispatch detector `_DYNAMIC_CALL_RE` matched `&& "$name"` even when `"$name"` was a test operand inside `[[ ... ]]`/`[ ... ]`, not a real call through a variable -- `[[ ]]`/`[ ]` cannot invoke an arbitrary command, so there was no call to miss. This false positive forced tree-shaking off for the whole hook file with no visible symptom besides the compiled size, exactly as #906 describes from #899's work on scripts/lib-lock.sh. Added `_mask_bracket_tests`, applied to each masked line before the dynamic-dispatch scan, to blank test-expression spans (bracket-counted so a glob char-class like `*[!0-9]*` does not prematurely close the span). Also made `tree_shake`'s report name the triggering physical line, and `compile_hooks.py --apply` now prints the reason to stderr whenever tree-shaking is disabled instead of staying silent. Co-Authored-By: Claude Sonnet 5 <[email protected]>
… lines Self-review (Explore + oss:auditor) on the first cut found the same gap independently: `_mask_bracket_tests` only masked a bracket-test span that opened and closed on one physical line. Bash continues a `[[ ... ]]`/ `[ ... ]` test onto the next line not only after an explicit trailing backslash but whenever a line simply ends on `&&`/`||`/`|` with no backslash at all (this repo's own scripts/run-consolidation.sh:301 wraps exactly that way) -- so a test split that way still false-positived as dynamic dispatch, the exact bug class #906 was filed against. _mask_bracket_tests now threads a (depth, double) carry across physical lines, the same way _scan_line_braces already threads brace/quote/heredoc state, and tree_shake's masking loop passes it through. Test added: test_tree_shake_a_test_operand_split_across_lines_by_implicit_continuation_is_not_dynamic_dispatch. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #906
compile_hooks.py's_DYNAMIC_CALL_REdynamic-dispatch detector matched&& "$name"even when"$name"was a test operand inside[[ ... ]]/[ ... ], not a real call through a variable. This false-positived and silently disabled tree-shaking for the whole hook file -- the only symptom was the compiled file's byte size, which is exactly what happened during #899 (session-start-hook.sh grew from ~122 KB to 135,889 B).What changed
_mask_bracket_testsblanks out every[[ ... ]]/[ ... ]test-expression span in an already-masked line before the dynamic-dispatch regex ever sees it. Brackets are counted, not matched on the first], so a glob char-class inside the test (*[!0-9]*) does not prematurely close the span.carry_depth/carry_double), the same way_scan_line_bracesalready threads brace/quote/heredoc state -- bash continues a[[ ... ]]/[ ... ]test onto the next line not only after an explicit trailing backslash but also whenever a line simply ends on&&/||/|with no backslash at all. This repo's ownscripts/run-consolidation.sh:301line-wraps exactly that way, and a review pass on the first cut reproduced the original false positive through exactly this gap before it was fixed.tree_shake's report now names the triggering physical line when dynamic dispatch disables shaking, andcompile_hooks.py's CLI prints that reason to stderr for every build whenever shaking is disabled -- unconditionally, not only under--apply. (Note: this pull request's first commit message describes the print as--apply-specific; that line was wrong, the code has always printed unconditionally, which is the safer direction and was left as-is on review rather than amended.)Adjacent (not filed)
_mask_bracket_tests's boundary check also matches a single-bracket glob likels [abc]*, masking it as a test; checked whether this could hide a real dynamic-dispatch match and could not construct one, so this is judged cosmetic/unreachable only and is not filed as an issue.Tests
6 new tests in
tests/test_compile_hooks_900.py: a double-bracket false positive, a single-bracket false positive, confirmation that a real dynamic call after a test still bails, confirmation that the bail reason names the triggering line, and a multi-line bracket span split by bash's implicit line continuation. All watched red before their corresponding implementation, then green (70 passed in the full targeted file). Also re-ran the repo-wide scannertests/test_locale_ranges_695.py(5 passed) and a Python-3.9 AST-compatibility parse check against the changed module, since it has scanner/cross-version exposure beyond its own test file.Review
Two reviewers (Explore and oss:auditor) found the same correctness gap independently -- the multi-line bracket span above -- which is fixed in this pull request's second commit. A second finding (one new test would still pass against a no-op stub of the fix) was argued down: that test's job is the required positive control pairing the false-positive tests, per this repo's own CLAUDE.md rule pairing every must-not-fire case with a must-fire case, and it does guard against the fix accidentally blinding a real trailing call even though this particular fixture's call happens to sit outside the masked span regardless.
🤖 Generated with Claude Code
[AI-generated]