fix: detect sourced shell integration configs#1312
fix: detect sourced shell integration configs#1312yash27-lab wants to merge 2 commits intomax-sixty:mainfrom
Conversation
Follow simple source/dot directives when checking shell integration so wt config show and shell setup checks work when the init line lives in a sourced file instead of directly in .zshrc or .bashrc.\n\nAlso return the actual sourced file path in config output and add unit and integration coverage for the sourced-file case.
worktrunk-bot
left a comment
There was a problem hiding this comment.
Nice work — the recursive source-following approach is well-structured with cycle detection and clean separation of concerns.
Two observations:
-
file_tree_has_exact_lineis unused outside its own test. It's exported publicly and re-exported inmod.rs, but no production code calls it — onlyfind_exact_line_in_file_treeandfile_tree_has_integrationare used. See inline suggestion. -
Unit test coverage for parsing helpers is thin.
extract_shell_word,split_shell_segments,expand_shell_path, andparse_source_segmentcontain non-trivial parsing logic. The integration test covers the happy path ($HOMEexpansion + source following), but edge cases like quoted source paths (source "dir/file.zsh"), multi-statement lines ([[ -f x ]] && source x), and skip conditions (source <(cmd)) aren't directly tested. A handful of unit tests for these would catch regressions if the parsing is later modified.
Remove the unused public exact-line wrapper and add focused unit tests for shell source parsing, path expansion, multi-statement splitting, and dynamic-source skip cases.
|
Good catch. I pushed a follow-up that removes the unused public helper and adds targeted unit coverage for the parsing helpers and skip cases. |
|
Looks great — the follow-up commit covers exactly the cases I had in mind. The test matrix for |
|
thanks @yash27-lab the existing state seems not great, admittedly but I worry this is fairly finicky — am I right that it's parsing the shell to find files that have been sourced, and then reading those files? presumably there is lots that could still slip through? @worktrunk-bot could you a survey of what will get caught vs missed in the existing vs proposed approach? |
|
You're right that this is parsing shell syntax to follow Before this PR (main)Detection only looks at the literal lines of
This is the gap the PR addresses — users who organize their shell config into sourced files see After this PRThe parser follows one level (recursively) of static Caught (source path is resolvable at parse time):
Intentionally skipped (dynamic/unparseable — correctly returns "not found"):
Still missed (not handled by the parser):
Practical assessmentThe "caught" cases cover the most common real-world pattern: users who split their The finickiness risk is real but bounded: the parser is conservative (skips anything dynamic rather than guessing), uses cycle detection, and only reads files that already exist. It won't produce false positives — the worst case is a false negative, which is the same as the current behavior on |
|
I would appreciate the 'niche' |
|
@worktrunk-bot are there alternative simpler approaches here? or dependencies which can help? I'm quite skeptical about maintaining a few hundred lines of code which attempt to implement the equivalent of a mini-zsh-parser-slash-walker... We could do something like:
|
|
Good question — there are a couple of simpler alternatives worth considering: Alternative 1: Suppress the warning when running under shell integrationThe shell wrapper sets
This eliminates the false negative that motivated this PR without any shell parsing. The downside: Alternative 2: Run the actual shellFor zsh -ic 'type wt' 2>/dev/nullIf the shell function Downsides: adds ~100-200ms latency per shell, won't work if the user's AssessmentAlternative 1 is the lowest-risk option — it's a few lines of code, no new parsing, and fixes the user-facing symptom. Alternative 2 is the most accurate but has edge cases with shell startup. The current PR's approach (mini shell parser) sits in between: more accurate than Alt 1 for the If the main goal is "don't show a misleading warning to users whose shell integration works," Alt 1 seems like the clear winner. If showing the exact file path in |
Follow simple source/dot directives when checking shell integration so wt config show and shell setup checks work when the init line lives in a sourced file instead of directly in .zshrc or .bashrc.\n\nAlso return the actual sourced file path in config output and add unit and integration coverage for the sourced-file case.