Limit template update checks to once a day for winapp new - #757
Limit template update checks to once a day for winapp new#757Zach Teutsch (zateutsch) wants to merge 4 commits into
Conversation
The 'new' command ran 'dotnet new update --check-only' (a NuGet feed round-trip) on every invocation, adding latency to each run. Introduce TemplateUpdateCheckThrottle, mirroring UpdateNotificationService's .update-check pattern, so the staleness check runs at most once per day and reuses the cached result otherwise. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 314ff851-0510-4289-b605-a545cfb453a2
M1 (correctness): GetLatestAvailableVersionAsync now reports whether the feed check actually succeeded, and NewCommand only records the throttle result on success. A transient 'dotnet new update --check-only' failure is no longer cached as 'up-to-date', so the next run retries instead of suppressing update detection for 24h. L1 (dedup): route the throttle's cache write through a new AtomicFile.WriteAllText helper instead of a hand-rolled fixed-'.tmp' temp+move, removing duplicated atomic-write logic and the shared-temp collision risk. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 314ff851-0510-4289-b605-a545cfb453a2
Build Metrics ReportBinary Sizes
Test Results✅ 4586 passed, 5 skipped out of 4591 tests in 618.9s (+10 tests, +5.0s vs. baseline) Test Coverage✅ 89.1% line coverage, 82.4% branch coverage · ✅ no change vs. baseline CLI Startup Time52ms median (x64, Try This BuildInstalls the MSIX for your architecture, replacing any previously installed build. Needs the GitHub CLI — the command offers to install it and sign you in if it is missing. & ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) 757Switching between builds often?Put the tool on your PATH once: & ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) -AddToPathThen this build is just: winapp-pr 757Run Updated 2026-08-14 21:36:59 UTC · commit |
There was a problem hiding this comment.
Pull request overview
Throttles winapp new template update checks with a version-aware, daily cache.
Changes:
- Adds and registers a file-backed update-check throttle.
- Integrates cached results into template resolution.
- Adds atomic text writing and related tests.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
TemplateUpdateCheckThrottle.cs |
Implements cache persistence and expiry. |
ITemplateUpdateCheckThrottle.cs |
Defines the throttle contract. |
HostBuilderExtensions.cs |
Registers the service. |
AtomicFile.cs |
Adds atomic text writes. |
NewCommand.cs |
Reuses cached update results. |
TemplateUpdateCheckThrottleTests.cs |
Tests cache behavior. |
NewCommandHandlerTests.cs |
Tests handler integration and failures. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…ow catches Copilot: ParseUpdateCheck returned (null, null) both for an up-to-date pack and for output it couldn't parse, so an exit-0 run with a changed/truncated `dotnet new update` format was cached as "up-to-date" and suppressed retries for a day. It now returns an UpdateCheckOutcome (UpdateAvailable / UpToDate / Unrecognized); GetLatestAvailableVersionAsync reports failure for Unrecognized so it isn't recorded. Code quality: replace generic catch (Exception) blocks in TemplateUpdateCheckThrottle (and the test cleanup) with filtered catches over expected filesystem/parse exceptions, and switch Path.Combine to Path.Join so a rooted second segment can't silently drop the directory. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 314ff851-0510-4289-b605-a545cfb453a2
Summary
winapp newran the WinUI template-pack staleness check (dotnet new update --check-only, a NuGet feed round-trip) on every invocation, adding a few seconds of latency each time. Listing templates and then immediately scaffolding paid that cost twice.This throttles the feed check to at most once a day, following the same pattern
UpdateNotificationServicealready uses for the CLI self-update notice. Between checks, the last result is reused, so back-to-backnewruns are fast.What changed
TemplateUpdateCheckThrottleservice (ITemplateUpdateCheckThrottle+ impl) that persists a hidden.template-update-checkfile in the global winapp directory (timestamp, installed pack version, last-seen latest version).NewCommand(Default version mode) now reuses a cached result when a check ran within the last 24h against the same installed pack version; otherwise it performs the feed check and records the result. Update prompts for a stale pack still fire — only the redundant network latency is removed.Behavior notes
--template-version lateststill forces the newest pack immediately, bypassing the throttle.--verbose/--quiet/--jsonoutput is unaffected.Testing
NewCommandhandler tests: recent cache skips the feed check (while still offering an available update), up-to-date cache skips both check and install, and a failed check is not cached.dotnet buildclean; template/handler tests (67) andAtomicFiletests (5) all pass.Review follow-ups (already applied)
AtomicFile.WriteAllTexthelper instead of a hand-rolled temp+move, removing duplicated atomic-write logic and a shared-temp-name collision risk.