refactor(pwsh): share Test-InteractiveShell via 05-lib; gate daily update check on it#75
Merged
Merged
Conversation
…date check Hoist the interactive-shell detection out of os/30-windows.ps1 into the pure helper layer (core/05-lib.ps1) so the "is this a real ConsoleHost session?" rule lives in one place instead of two hand-synced copies. Split it into a pure, unit-tested arg classifier (Test-DotNonInteractiveArg) and a thin ambient wrapper (Test-InteractiveShell), both exported from the Dotfiles module. Gate core/15-update.ps1's once-daily scoop/winget background probe (and its nudge) on Test-InteractiveShell so `pwsh -Command`/`-File` loads — VS Code tasks, git hooks, scheduled scripts — no longer spawn a network check. Interactive shells and psmux splits are unaffected. Also memoize Test-Cmd (core/00-aliases.ps1) so repeated top-level PATH probes collapse to one lookup per tool, and align os/30-windows.ps1's $InMux markers (TMUX + PSMUX_SESSION) with the verified pair used by the psmux pill, closing a nested-session risk. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR centralizes “interactive shell” detection into a shared helper and uses it to prevent interactive-only startup work (psmux auto-attach and the once-daily scoop/winget update probe) from running during non-interactive pwsh -Command / -File profile loads, while also reducing repeated PATH scans via a memoized Test-Cmd.
Changes:
- Adds
Test-DotNonInteractiveArg(pure) andTest-InteractiveShell(ambient wrapper) tocore/05-lib.ps1, and exports them from the Dotfiles module. - Gates the startup update probe in
core/15-update.ps1onTest-InteractiveShell, and switchesos/30-windows.ps1to the shared helper while correcting psmux in-pane markers. - Memoizes
Test-Cmdincore/00-aliases.ps1and adds unit/manifest coverage for the new helpers.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Module.Tests.ps1 | Extends module export-surface assertions to include the two new helpers. |
| tests/Lib.Tests.ps1 | Adds unit tests for the pure non-interactive argument classifier. |
| powershell/os/30-windows.ps1 | Uses shared Test-InteractiveShell for psmux auto-attach gating; aligns mux marker detection with PSMUX_SESSION. |
| powershell/Dotfiles/Dotfiles.psd1 | Exports Test-DotNonInteractiveArg and Test-InteractiveShell from the module manifest. |
| powershell/core/15-update.ps1 | Prevents daily update probe/nudge from running on non-interactive profile loads. |
| powershell/core/05-lib.ps1 | Introduces the shared pure+ambient interactive-shell detection helpers. |
| powershell/core/00-aliases.ps1 | Memoizes Test-Cmd to avoid repeated PATH scans across fragments. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
What
Consolidates interactive-shell detection into one shared, unit-tested helper and uses it to keep the daily package-update probe off non-interactive profile loads. Also folds in two smaller fixes surfaced during a startup-latency audit.
Why
Test-InteractiveShellwas defined privately inos/30-windows.ps1(psmux auto-attach guard), butcore/15-update.ps1's once-daily scoop/winget background check had no interactivity guard — so everypwsh -Command/-Fileload (VS Code tasks, git hooks, scheduled scripts) could spawn a network update probe and print a nudge. The rule belongs in one place.Changes
core/05-lib.ps1— new pureTest-DotNonInteractiveArg(arg classifier) + ambientTest-InteractiveShellwrapper, mirroring the existing pure/ambient split (Test-DotEmailish,Get-DotToolNudge).Dotfiles.psd1— export both helpers.core/15-update.ps1— gate the daily background check + nudge onTest-InteractiveShell. Interactive shells and psmux splits are unaffected (a split is a realConsoleHost); the once/day throttle already made splits free.os/30-windows.ps1— drop the localTest-InteractiveShellcopy, call the shared one. Also align$InMuxmarkers with the verified pair (TMUX+PSMUX_SESSION) used by33-psmux-pill.ps1, closing a nested-session risk (the old list checkedPSMUX/PSMUX_PANE, which psmux doesn't export).core/00-aliases.ps1— memoizeTest-Cmdso repeated top-level PATH probes (e.g.psmux, checked from three os/ fragments) collapse to one lookup per tool. Cache resets onreload.tests/Lib.Tests.ps1— 14 cases for the pure classifier (prefix edges:-noni→non-interactive,-non→interactive,-c/-fprefixes,-NoLogo/-NoProfile→interactive).tests/Module.Tests.ps1— document the two new exports.Verification
Test-ModuleManifest); classifier 13/13 behavioral cases pass.LoadContractrequires:-vs-AST computation for all three touched fragments → exact match.Test-InteractiveShellis a module export, so it's inprovidersBeforefrom the start and both15-updateand30-windowsmay require it despite load order.🤖 Generated with Claude Code