Skip to content

refactor(pwsh): share Test-InteractiveShell via 05-lib; gate daily update check on it#75

Merged
Gerrrt merged 1 commit into
mainfrom
refactor/share-interactive-shell-guard
Jul 1, 2026
Merged

refactor(pwsh): share Test-InteractiveShell via 05-lib; gate daily update check on it#75
Gerrrt merged 1 commit into
mainfrom
refactor/share-interactive-shell-guard

Conversation

@Gerrrt

@Gerrrt Gerrrt commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

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-InteractiveShell was defined privately in os/30-windows.ps1 (psmux auto-attach guard), but core/15-update.ps1's once-daily scoop/winget background check had no interactivity guard — so every pwsh -Command/-File load (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 pure Test-DotNonInteractiveArg (arg classifier) + ambient Test-InteractiveShell wrapper, 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 on Test-InteractiveShell. Interactive shells and psmux splits are unaffected (a split is a real ConsoleHost); the once/day throttle already made splits free.
  • os/30-windows.ps1 — drop the local Test-InteractiveShell copy, call the shared one. Also align $InMux markers with the verified pair (TMUX + PSMUX_SESSION) used by 33-psmux-pill.ps1, closing a nested-session risk (the old list checked PSMUX/PSMUX_PANE, which psmux doesn't export).
  • core/00-aliases.ps1 — memoize Test-Cmd so repeated top-level PATH probes (e.g. psmux, checked from three os/ fragments) collapse to one lookup per tool. Cache resets on reload.
  • tests/Lib.Tests.ps1 — 14 cases for the pure classifier (prefix edges: -noni→non-interactive, -non→interactive, -c/-f prefixes, -NoLogo/-NoProfile→interactive).
  • tests/Module.Tests.ps1 — document the two new exports.

Verification

  • Pre-commit validation suite passed (70 scripts parse clean; manifests/JSON/editorconfig OK).
  • Manifest validates (Test-ModuleManifest); classifier 13/13 behavioral cases pass.
  • Replicated the strict LoadContract requires:-vs-AST computation for all three touched fragments → exact match. Test-InteractiveShell is a module export, so it's in providersBefore from the start and both 15-update and 30-windows may require it despite load order.
  • Full Pester v5 suite not run locally (only in-box Pester 3.4 present) — will run on the Windows CI runner.

🤖 Generated with Claude Code

…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>
Copilot AI review requested due to automatic review settings July 1, 2026 22:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and Test-InteractiveShell (ambient wrapper) to core/05-lib.ps1, and exports them from the Dotfiles module.
  • Gates the startup update probe in core/15-update.ps1 on Test-InteractiveShell, and switches os/30-windows.ps1 to the shared helper while correcting psmux in-pane markers.
  • Memoizes Test-Cmd in core/00-aliases.ps1 and 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.

@Gerrrt Gerrrt merged commit 39fbe6f into main Jul 1, 2026
7 checks passed
@Gerrrt Gerrrt deleted the refactor/share-interactive-shell-guard branch July 1, 2026 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants