Skip to content

fix(get-winapp-path): fall back to global cache when local missing (#475)#485

Merged
nmetulev merged 4 commits intomainfrom
fix/issue-475-local-path-fallback
Apr 21, 2026
Merged

fix(get-winapp-path): fall back to global cache when local missing (#475)#485
nmetulev merged 4 commits intomainfrom
fix/issue-475-local-path-fallback

Conversation

@nmetulev
Copy link
Copy Markdown
Member

Summary

Fixes #475.

Previously, winapp get-winapp-path (without --global) would print <cwd>\.winapp even when no local .winapp directory existed anywhere up the directory tree. Build scripts that consumed the output ended up pointing at non-existent folders, since installed packages had actually landed in the global cache.

Behavior change

When the resolved local .winapp directory does not exist, the command now:

  1. Emits a warning (WinappDirectoryService + UiSymbols.Warning) explaining that no local .winapp was found.
  2. Falls back to the global cache path (%USERPROFILE%\.winapp by default).
  3. Returns exit code 0 and prints the global path on stdout, so scripts continue to work.

When --global is explicitly requested but the global directory is missing, behavior is unchanged: the command still returns a non-zero exit code with an error.

Repro (before fix)

PS> cd (New-Item -ItemType Directory ""C:\Users\nikolame\AppData\Local\Temp\repro-475-$([guid]::NewGuid())"")
PS> winapp get-winapp-path
C:\Users\me\AppData\Local\Temp\repro-475-...\\.winapp     # <-- non-existent

After fix

PS> winapp get-winapp-path
WARN  No local .winapp directory found; falling back to the global cache at C:\Users\me\.winapp.
C:\Users\me\.winapp

Implementation notes

  • Switched the path emission in GetWinappPathCommand from logger.LogInformation to IAnsiConsole.WriteLine so the path is the only thing on stdout and is cleanly captured by tests via TestAnsiConsole. (Non-error log levels in TextWriterLogger use the static AnsiConsole, which bypasses both the injected writer and the DI IAnsiConsole, so they aren't visible to test assertions.)
  • Added GetWinappPathCommandTests with three cases: local exists, local missing -> global fallback, --global missing -> error.

Validation

  • New tests: 3 passing.
  • Full suite: 767/767 passing.
  • Manual repro: empty temp dir prints warning + global path, exit 0.

Closes #475

)

Previously 'winapp get-winapp-path' (without --global) would print

<cwd>\.winapp even when no local .winapp existed anywhere up the

directory tree, causing scripts to point at non-existent folders.

Now when no local .winapp is found, the command warns and falls back

to the global cache path (which is also where 'winapp install' would

place packages without a local .winapp). The path is now emitted via

IAnsiConsole so it is captured cleanly by the test infrastructure.

Closes #475

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 20, 2026 23:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes winapp get-winapp-path so that when no existing local .winapp directory can be found, the command warns and falls back to the global cache path instead of returning a non-existent local path (addressing #475).

Changes:

  • Add fallback logic: if the resolved local .winapp path doesn’t exist, switch to the global cache path and emit a warning.
  • Change path emission to use IAnsiConsole.WriteLine so the resolved path is printed plainly (better for script consumption and test capture).
  • Add new command tests covering: local exists, local missing → global fallback, and --global missing → error.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/winapp-CLI/WinApp.Cli/Commands/GetWinappPathCommand.cs Implements local-missing fallback to global and prints path via IAnsiConsole.
src/winapp-CLI/WinApp.Cli.Tests/GetWinappPathCommandTests.cs Adds coverage for the new fallback behavior and existing --global error behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/winapp-CLI/WinApp.Cli/Commands/GetWinappPathCommand.cs Outdated
Comment thread src/winapp-CLI/WinApp.Cli.Tests/GetWinappPathCommandTests.cs
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 20, 2026

Build Metrics Report

Binary Sizes

Artifact Baseline Current Delta
CLI (ARM64) 30.66 MB 30.66 MB ✅ 0.0 KB (0.00%)
CLI (x64) 31.02 MB 31.02 MB ✅ 0.0 KB (0.00%)
MSIX (ARM64) 12.94 MB 12.94 MB 📈 +0.3 KB (+0.00%)
MSIX (x64) 13.74 MB 13.74 MB 📈 +0.2 KB (+0.00%)
NPM Package 26.90 MB 26.90 MB 📈 +0.3 KB (+0.00%)
NuGet Package 26.98 MB 26.98 MB 📈 +0.3 KB (+0.00%)
VS Code Extension 19.72 MB 19.72 MB 📈 +0.7 KB (+0.00%)

Test Results

783 passed, 1 skipped out of 784 tests in 402.1s (-1.4s vs. baseline)

Test Coverage

21.4% line coverage, 36.6% branch coverage · ✅ no change vs. baseline

CLI Startup Time

37ms median (x64, winapp --version) · ✅ no change vs. baseline


Updated 2026-04-21 18:10:54 UTC · commit 3851319 · workflow run

Address PR #485 review feedback:

- Warning previously went through ILogger.LogWarning which TextWriterLogger

  routes via static AnsiConsole.WriteLine -> stdout, polluting the

  script-consumable path output. Switch to writing the warning directly to

  parseResult.InvocationConfiguration.Error so stdout contains only the

  resolved path and \path = $(winapp get-winapp-path)\ works cleanly.

- Update LocalDirectoryMissing test to actually assert the warning text

  is on stderr (matching the test name) and that it does NOT appear on

  stdout.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread src/winapp-CLI/WinApp.Cli/Commands/GetWinappPathCommand.cs Outdated
nmetulev and others added 2 commits April 21, 2026 17:54
@nmetulev nmetulev merged commit 1e2d1bb into main Apr 21, 2026
9 checks passed
@nmetulev nmetulev deleted the fix/issue-475-local-path-fallback branch April 21, 2026 17:55
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.

[Bug]: Get local Win App path returns path to directory that doesn't exist

3 participants