Skip to content

Add WinApp: Create WinUI App command for winapp new - #245

Merged
Chiara Mooney (chiaramooney) merged 38 commits into
mainfrom
chiaramooney-winapp-new-scaffold-support
Sep 29, 2026
Merged

Chiara Mooney (chiaramooney) merged 38 commits into
mainfrom
chiaramooney-winapp-new-scaffold-support

Conversation

@chiaramooney

Copy link
Copy Markdown
Contributor

Adds extension support for winapp new (winappcli v0.6.0+), scaffolding a WinUI app from an official Windows App SDK template.

This is the missing entry point to the extension's funnel. Until now the earliest command was winapp init, which assumes a project already exists — there was no palette path from "nothing" to "a WinUI app."

Command surface

WinApp: Create WinUI App (winapp.new), activated by onCommand:winapp.new.

Unlike almost every other command, this one does not require an open workspace. Scaffolding usually happens when no folder is open, or targets a folder outside the current workspace, so it deliberately skips the usual getWorkspacePath() bail — following the precedent set by winapp.certInfo.

Flow

  1. Template QuickPick driven by winapp new --list --json, with descriptions, cached per window.
  2. Name — validated against the CLI's real constraints (max length 255 − 7, invalid characters).
  3. Output directory — defaults to ./<name>; a non-empty target offers --force.
  4. Scaffold, then offer to open the folder (new window / same window / add to workspace).

CLI behaviors this had to work around

These are non-obvious and cost real investigation time, so they're recorded here:

  • --json implies --use-defaults inside the CLI, and --use-defaults means "keep installed templates." A naive JSON caller would silently pin its template pack forever. This is why the extension asks about the pack version rather than detecting it.
  • EnsureAvailableName auto-numbering only applies to CLI-defaulted or prompted names. An explicit --name — which the extension always passes — is honoured verbatim and hard-fails on collision (exit 2, not 5). So the extension owns collision handling itself. An existing-but-empty directory proceeds silently.
  • Pack-resolution failure is exit 4 with a populated Error field; missing SDK is exit 3. Both are surfaced with actionable messages, preferring the CLI's own parsed Error text.
  • Minimum .NET SDK is 8.0.100.

Performance

Listing pins --template-version installed, keeping the unpinned path as the first-run fallback.

VersionMode.Default runs dotnet new update --check-only, a package-feed round-trip on every listing. Pinning avoids it: 8.2s → 1.6s measured.

To be precise about the reason, since an earlier note of mine got this wrong: --check-only does honor the machine's configured feed (it returns exit 0 with nuget.org disabled). This change is for latency, not feed policy. No --source or --registry is ever passed.

.NET dependency, clarified in the README

Worth stating because the obvious answer is wrong: the shipped CLI is Native AOT with zero .NET dependency — winappcli-x64.zip contains only winapp.exe, libSkiaSharp.dll, and a .pdb; no winapp.dll, no runtimeconfig.json. (The dev build on PATH is framework-dependent on .NET 10 and is not representative — answering from it produces the opposite conclusion.)

Only winapp new requires the .NET SDK, because it delegates to dotnet new. winapp run has two modes: project mode invokes dotnet build and needs the SDK, but the extension's pickBuildOutputFolder only surfaces directories containing an .exe, so project mode is unreachable from the palette. Other dotnet-touching services degrade gracefully.

Tests

  • src/test/new-command-utils.test.ts — 40 tests, all logic in a VS Code-free module.
  • src/test/e2e/new-command-quickpick.spec.ts — 3 Playwright specs.

Also makes test:e2e run npm run compile first. The extension's main is ./dist/extension.js, but pretest only builds out/ — so a stale or missing dist/ made every failure look like a product bug. #244 carries the identical one-line fix; the edits are byte-identical, so the merge is clean in either order.

Verification

  • tsc --noEmit exit 0
  • lint 0 errors (12 pre-existing warnings, baseline unchanged)
  • unit tests 40/40 pass
  • npm run compile succeeds; dist/extension.js confirmed to contain the new code paths
  • the 3 new E2E specs pass

Full-suite E2E on this branch: 186 passed / 5 failed / 8 flaky. None of the failures are from this PR — they're the pre-existing sign-quickpick and semantic-diagnostics specs that #244 fixes.

Follow-ups (deliberately not in scope)

Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com

@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

VSIX Build

Artifact Baseline Current Delta
VS Code Extension (VSIX) 39.29 MB 39.29 MB 📈 +2.2 KB (+0.01%)

Updated 2026-09-29 22:11:54 UTC · commit a259a0f · workflow run

@zateutsch

Copy link
Copy Markdown
Contributor

PR Review — chiaramooney-winapp-new-scaffold-support vs main

36 commits · 10 files · +1355 / −15 lines

Summary

Critical High Medium Low
0 0 7 2

Coverage

Dimension Result
security ⚠ 1 finding (merged into M7)
correctness ⚠ 1 finding (merged into M7)
extension-ux ⚠ 1 finding
alternative-solution ⚠ 3 findings
test-coverage ⚠ 4 findings
docs-and-samples ✓ clean
packaging ✓ clean
multi-model ✓ 1 high reviewed → downgraded to medium; no new critical/high

Findings

ID Location Domain Summary
M1 src/extension.ts:873-1580 alternative-solution winapp.new flow bloats extension.ts instead of a focused module
M2 src/extension.ts:906-943 test-coverage First-run "no template pack installed" branch has no automated coverage
M3 src/extension.ts:1015-1038 test-coverage "Use latest templates" QuickPick branch is never exercised
M4 src/extension.ts:1516-1524 extension-ux Folder picker wording invites selecting the app folder, not its parent
M5 src/extension.ts:1550-1565 test-coverage "Create Anyway" (--force) retry flow lacks command-flow coverage
M6 src/test/cli-json-output.test.ts:10-20 test-coverage extractJsonObject has no adversarial tests (braces in prose/strings)
M7 src/winapp-cli-utils.ts:52-63 correctness, security extractJsonObject anchors on first { and rescans every } (mis-parse + O(n²))
L1 src/new-command-utils.ts:214-220 alternative-solution buildListArgs is a trivial one-caller abstraction
L2 src/test/e2e/new-command-quickpick.spec.ts:28-68 alternative-solution Duplicated pack-probe / temp-dir helpers across both E2E specs

Details

M1 · src/extension.ts:873-1580

  • Severity: medium · Confidence: medium · Domain: alternative-solution
  • Finding: The entire winapp.new workflow (~320 new lines: loadWinUiTemplates, runTemplateList, showNewFailure, resolveTemplatePack, pickWinUiTemplate, plus the command registration) lives inline in extension.ts rather than a focused command module.
  • Evidence: New block // --- winapp new (Create WinUI App) ---, async function loadWinUiTemplates(, and vscode.commands.registerCommand('winapp.new', async () => { all added directly to extension.ts.
  • Recommendation: Move the flow into src/new-command.ts exporting registerWinappNewCommand(context, extensionPath); keep pure helpers in new-command-utils.ts and leave extension.ts as the registration site. Non-blocking.

M2 · src/extension.ts:906-943

  • Severity: medium (originally high; downgraded by multi-model cross-check) · Confidence: high · Domain: test-coverage
  • Finding: The first-run "no pack installed → fall through to unpinned install/list" branch is never exercised by any test.
  • Evidence: extension.ts only falls through on local.code === NEW_EXIT.packFailed (exit 4); CI preinstalls a pack (build.yml runs winapp.exe new --list --json --template-version latest), and both E2E specs test.skip(() => !hasInstalledTemplatePack(), ...), so CI always has a pack present. The new unit tests only cover pure helpers.
  • Recommendation: Add a unit test around loadWinUiTemplates with a mocked runTemplateList: installed-probe exit 4 → unpinned retry success → freshlyInstalled: true, plus the non-4 failure path that shows showNewFailure.

M3 · src/extension.ts:1015-1038

  • Severity: medium · Confidence: high · Domain: test-coverage
  • Finding: The "Use latest templates" branch of resolveTemplatePack — which triggers a machine-wide pack install — is not tested.
  • Evidence: useLatest option leads to loadWinUiTemplates(extensionPath, cwd, 'latest'); the E2E deliberately presses Enter on the pre-selected "Use installed" option to avoid mutating the machine.
  • Recommendation: Add a test (mocked loader) selecting "Use latest templates" and assert the latest load is invoked and its list is used.

M4 · src/extension.ts:1516-1524

  • Severity: medium · Confidence: high · Domain: extension-ux
  • Finding: The folder dialog says "Select a folder for the new app", but the app is actually created at <selected>/<name>, so users may pick the intended final folder and get a nested name/name.
  • Evidence: selectFolder('Select a folder for the new app', ...) immediately followed by const outputDirectory = path.join(parentDirectory, requestedName);.
  • Recommendation: Make the parent-folder behavior explicit in the title, e.g. Select the parent folder — ${requestedName} will be created inside it.

M5 · src/extension.ts:1550-1565

  • Severity: medium · Confidence: high · Domain: test-coverage
  • Finding: The non-empty-directory "Create Anyway" modal → scaffoldOnce(true) retry is only covered at the helper/CLI level, not through the command handler (cancel vs confirm, and that the retry actually adds --force).
  • Evidence: extension.ts shows the modal decision and result = await scaffoldOnce(true); the scaffold E2E only asserts isNonEmptyOutputFailure(...) is true.
  • Recommendation: Make the handler's prompt/runner injectable so a test can drive cancel vs "Create Anyway" and assert the second invocation includes --force.

M6 · src/test/cli-json-output.test.ts:10-20

  • Severity: medium · Confidence: medium · Domain: test-coverage
  • Finding: extractJsonObject tests don't cover braces in surrounding progress text or inside JSON string values — the exact inputs that expose M7.
  • Evidence: Tests cover a clean payload, leading/trailing progress prose, and nested objects, but nothing like warning {x}\n{"Created":true} or {"Error":"bad } name"}.
  • Recommendation: Add those adversarial cases; they will fail against the current implementation and pin the fix from M7.

M7 · src/winapp-cli-utils.ts:52-63

  • Severity: medium · Confidence: high · Domain: correctness, security
  • Finding: extractJsonObject anchors permanently on the first { and then walks back from lastIndexOf('}'), so (a) any { in progress/warning text printed before the payload makes every parse fail, and (b) output with many } characters drives an O(n²) parse-per-brace loop on the extension host. It also mis-handles a } inside a JSON string value.
  • Evidence: const start = output.indexOf('{'); then for (let end = output.lastIndexOf('}'); end > start; end = output.lastIndexOf('}', end - 1)) { JSON.parse(output.slice(start, end + 1)); }.
  • Recommendation: Replace with a single linear balanced-brace scan that respects strings/escapes and skips false-start { positions; cap input size before scanning. Add the M6 adversarial tests alongside.

L1 · src/new-command-utils.ts:214-220

  • Severity: low · Confidence: medium · Domain: alternative-solution
  • Finding: buildListArgs is a trivial exported abstraction with a single production caller (runTemplateList).
  • Evidence: export function buildListArgs(templateVersion?) { const args = ['new', '--list', '--json']; ... }, called only from runTemplateList.
  • Recommendation: Consider inlining into runTemplateList; keep the non-trivial buildNewArgs. Minor — the symmetry with buildNewArgs is a reasonable counter-argument.

L2 · src/test/e2e/new-command-quickpick.spec.ts:28-68

  • Severity: low · Confidence: high · Domain: alternative-solution
  • Finding: hasInstalledTemplatePack and makeTempDirectory / afterAll cleanup are duplicated verbatim in new-command-scaffold.spec.ts.
  • Evidence: Identical function hasInstalledTemplatePack() and makeTempDirectory(...) blocks in both new E2E specs.
  • Recommendation: Extract into src/test/e2e/new-command-helpers.ts and import from both.

Coverage notes

  • docs-and-samples: Verified README command-table row, new "Create a new WinUI app" scenario, and the .NET SDK 8.0.100 Requirements line against the implemented flow; package.json command/title/activation; e2e/RELEASE docs — no drift.
  • packaging: winapp.new has both the contributed command and onCommand activation; no runtime deps added (os is a builtin, no lockfile impact); .vscodeignore still excludes tests and includes the bundled CLI; build/package scripts unchanged; the new CI pack-install step uses the bundled bin/win-x64/winapp.exe with a neutral cwd and explicit exit handling.
  • multi-model (gpt-5.4): Cross-checked the one high finding (downgraded to medium), independently re-scanned process launch, --force data-loss, cancellation, and path handling — no additional critical/high.

Net: solid, well-tested PR — no blockers. The one substantive code issue is M7 (extractJsonObject brace-scan), best paired with the M6 tests. Everything else is test-gap tightening (M2/M3/M5), a one-line dialog fix (M4), and optional structure/dedup polish (M1/L1/L2).

🤖 Generated with GitHub Copilot — multi-dimensional PR review.

@zateutsch Zach Teutsch (zateutsch) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Attached review above.

The main standouts to me are M1 and M7 - the rest are just test coverage.

Take a look and I can re review whenever.

@chiaramooney

Copy link
Copy Markdown
Contributor Author

Review feedback addressed — 270b125

Thanks Zach Teutsch (@zateutsch). Here's where each item landed. Numbering follows your report.

Fixed

# Item What changed
M1 winapp.new flow inflates extension.ts Extracted src/new-command.ts (328 lines) + src/winapp-host.ts for the shared VS Code helpers. extension.ts: 2065 → 1632 lines
M4 Folder prompt ambiguous about parent vs. target Now reads Select the parent folder — <name> will be created inside it
M6 No adversarial coverage for JSON extraction 4 new tests in cli-json-output.test.ts, incl. a linear-time guard (9/9 pass)
M7 extractJsonObject fragile + quadratic Rewritten as a single-pass balanced-brace scanner — details below
L1 buildListArgs indirection Inlined into runTemplateList; export and its unit tests removed
L2 Duplicated E2E fixtures Shared via src/test/e2e/new-command-helpers.ts

M7 in detail

I tested all three claims against the live code rather than reasoning from the source, and one of them didn't hold up:

Claim Verdict
(a) A { in prose before the payload breaks parsing True — warning {x} skipped\n{"Created":true} returned undefined
(b) O(n²) per call True, and worse than described
(c) Mis-handles } inside a JSON string value False — {"Error":"bad } name"} already parsed correctly, because the last-}-first walk-back happens to land on the true end

On (b): the cost is amplified by the caller. parseProcessIdFromJson runs on every stdout chunk against the whole accumulated buffer, so while a payload is still incomplete the quadratic scan repeats per chunk — cubic over the stream, on the extension host thread. Measured on a valid-prefix unterminated payload:

 500 objects   ->   20.6 ms
1000 objects   ->   78.7 ms
2000 objects   ->    296 ms
4000 objects (100 KB) -> 1172 ms

Clean 2x→4x quadratic. The new scanner does that same 100 KB input in 1.4 ms.

Two implementation notes:

  • Strings are only tracked once inside a candidate object (depth > 0). A naive always-on string tracker breaks on prose with an odd number of quotes — the stray quote opens a "string" that swallows the payload. There's a test pinning this.
  • I skipped the recommended input-size cap. The scan is genuinely linear now (each char visited once, total JSON.parse work bounded by total length), so a cap would add complexity whose only real effect is a way to drop a valid payload.

All five original behaviors still hold, including partial input -> undefined, which the streaming caller depends on.

Declined, with reasoning

M5 — test coverage for the --force retry. Worth covering; I don't think the proposed mechanism is the way. Making the handler's prompt/runner injectable re-introduces exactly the test seam that was removed earlier in this PR's review cycle (the TemplateLoadAdapter pattern) — the standing direction here is that the extension shells out to the CLI and doesn't grow abstraction layers to make itself mockable. The same risk is reachable without a seam: extend the existing collision E2E to actually accept the "Create Anyway" modal and assert the scaffold lands alongside the pre-existing file. Happy to add that if you'd like it in this PR.

M2 / M3 — not addressed in this pass; flagging as known rather than silently skipping.

Unrelated pre-existing failure you should know about

The full E2E suite currently has 15 failures, 5 of them in sign-quickpick. These are not from this branch — I stashed every change and reran against clean HEAD, and the identical 5 fail there. They trip on a placeholder-text assertion while two sibling tests driving the same QuickPick pass, which points at the test rather than the product. Out of scope here, but it's red on main today.

Verification

tsc 0 errors - lint 0 errors / 12 warnings (unchanged baseline) - 1047 node + 32 mocha tests passing - esbuild clean - 5/5 new-command E2E passing.

Adds the missing entry point to the extension's funnel. Until now the
earliest command was Initialize Project, which assumes a project already
exists; `winapp new` (winappcli v0.6.0) scaffolds one from an official
Windows App SDK template.

The command is workspace-optional, joining winapp.certInfo as the second
deliberate exception to the getWorkspacePath() convention: scaffolding is
most useful with no folder open, and it writes outside the workspace.

Prompt flow is template -> name -> parent folder, with the project landing
in <folder>/<name>. Because `--json` forces `--use-defaults` inside the CLI
(which means "keep the installed template pack"), a JSON caller would
otherwise pin itself to a stale pack forever, so the user is asked which
pack to use whenever one is already installed. The non-destructive option
is pre-selected, mirroring the CLI's deliberately default-less update
prompt, since installing a pack is a machine-wide side effect.

Collisions are handled before invoking the CLI. An explicit --name skips
the CLI's EnsureAvailableName auto-numbering and hard-fails with exit 2, so
the extension owns the numbering and offers the free name alongside --force.

Post-scaffold, opening a folder restarts the extension host, so the target
is stashed in globalState and the follow-up notification is shown on the
next activation. It offers Run and Initialize rather than chaining into
init automatically -- `dotnet new` output is already buildable.

Prerequisite detection is left to the CLI: a missing .NET SDK surfaces as
exit 3 and gets a modal with a link to the installer, keeping the CLI the
single source of truth for SDK policy.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The new-command spec could not pass as written. Three fixes, found by
running it:

Launch with an isolated --user-data-dir. With a VS Code already running,
a plain --new-window is delegated to that instance and the process
Playwright launched exits immediately, so firstWindow() never resolves.
input-folder-validation.spec.ts already did this; the other specs do not,
which is why they fail the same way on a machine with VS Code open.

Wait on the QuickPick placeholder rather than on list rows. The Command
Palette has rows of its own, so a row-visibility wait succeeded instantly
while the palette was still open and the CLI had not been invoked yet.

Defer temp-directory cleanup to afterAll. VS Code can still hold a handle
on the workspace for a moment after the Electron app closes, so the
per-test delete could fail and leak a directory.

Also make test:e2e run the esbuild bundle first. The extension's main is
dist/extension.js, but test:e2e only ran Playwright, so a missing or stale
dist silently tested the wrong code -- activation failed with "Cannot find
module" and every command-driven assertion failed for reasons that looked
like product bugs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…isting

Two changes to the winapp.new command:

- Remove the post-scaffold follow-up notification. Re-surfacing next steps
  after the window reloads is beyond the scope of scaffolding, and the CLI
  already prints a template-specific next step.

- Ask for '--template-version installed' when listing templates. Without it
  the CLI runs 'dotnet new update --check-only' to detect a stale pack, which
  contacts the configured NuGet feed on every invocation (~8s versus ~1.6s
  measured). This command asks the user which pack version they want instead
  of detecting staleness, so that answer was discarded. The unpinned listing
  is still used as a fallback for the first run, when no pack is installed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
When the 'installed' probe fails because there is no .NET SDK, the unpinned
fallback cannot succeed either, and its 'Installing the WinUI templates...'
progress implies work that can never happen. Detect the SDK-missing exit code
on the probe and surface the actionable error immediately.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Two defects found while tracing the no-templates-installed scenario:

- When no pack is installed, the listing falls through to the unpinned call,
  which installs the newest pack. The result then carries a TemplateVersion,
  so the installed-versus-latest prompt appeared even though both answers
  named the version just fetched. Thread a 'freshlyInstalled' flag through
  the load so the prompt is suppressed in that case.

- The SDK-missing path discarded the CLI's own message, which distinguishes
  'no SDK found' from 'SDK too old' and names the required version. Prefer
  the parsed error and fall back to the generic text.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keeps the template loading path consistent with the rest of the file.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The scenario paragraph said only that the SDK was required. Name 8.0.100 and
cover the out-of-date case, which is a distinct failure the command reports
with its own message.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The bundled CLI is a native binary with no .NET runtime dependency, and
'Run Application' uses the CLI's folder mode, which launches a build output
folder without invoking dotnet. Only 'Create WinUI App' needs the SDK. Say so,
since a .NET-adjacent tool is reasonably assumed to need a runtime.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
`ensureAvailableName` appended a numeric suffix without re-checking the
result against MAX_PROJECT_NAME_LENGTH, so a name already at the maximum
grew past it. That is reachable: when the target directory exists and is
non-empty, resolveScaffoldTarget offers the numbered name as a recovery,
and the CLI rejects an over-length explicit --name with exit 2 — turning
the recovery offer into a dead end.

Trim the base so the numbered variant still fits. Found by the PR review
skill and confirmed by an independent cross-model pass.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Three findings from the review pass, all in the winapp.new flow. They
share src/extension.ts, so they land together to keep every commit
compiling.

H1 -- list templates from a neutral directory. Template listing ran with
cwd set to the workspace (or the home dir with no folder open). That cwd
feeds dotnet's global.json probe, so a workspace pinning an SDK version
the developer does not have made the CLI exit 3 -- "The .NET SDK is
required to create a WinUI app." -- even though the SDK was installed and
the chosen destination would have scaffolded fine. Scaffolding a new app
elsewhere was hard-blocked by an unrelated repo's pin, behind a
misleading error. The template pack is machine-wide, so listing needs no
workspace context: defaultFolder (workspace ?? home) now only seeds the
folder picker's default URI, while a new listingCwd on os.tmpdir() runs
listing and pack resolution clear of any global.json chain. Scaffolding
still runs from parentDirectory so the destination's global.json governs
the target framework.

M2 and M3 -- extract the two branchiest decisions out of the VS Code
layer. loadWinUiTemplates (the five-path listing/install state machine)
and resolveScaffoldTarget (the non-empty-directory and --force decision)
move to new-command-utils.ts behind adapter interfaces, following the
existing SignFlowAdapter/executeSignFlow precedent. extension.ts keeps
thin adapters that wire in the real CLI runner, fs, and VS Code prompts.
No behaviour change.

Adds 17 unit tests over the extracted logic (59 total in the file).
Mutation-checked: reverting the SDK-missing short-circuit fails 2 tests
and reverting the freshlyInstalled suppression fails 1, so the paths
added in earlier review rounds are now genuinely protected.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The specs drove the template QuickPick, which on a machine with no WinUI
template pack installed made the CLI install one -- and only one pack
version can exist at a time, so a run could silently replace whatever
version the developer had. Running the test suite should not mutate the
machine's SDK state.

The suite now probes for an installed pack up front and skips itself when
there is none, so it only ever reads state it did not create. The
install/update decision logic it used to exercise incidentally is covered
directly by the loadWinUiTemplates unit tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
loadWinUiTemplates fell through to the unpinned retry for any failing
pinned probe, not just the missing-pack case. A spawn failure (code null,
e.g. a missing or quarantined CLI) therefore ran a second doomed spawn
behind an `Installing the WinUI templates...` progress notification,
doubling the latency and telling the user something untrue about what
went wrong.

Gate the retry on exit 4 (packFailed), which a probe confirms is what the
CLI returns when no pack is installed. Every other outcome now reports
immediately, still preferring the CLI's own wording and still routing
sdkMissing to the SDK modal.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The winapp.new specs skip themselves when no template pack is installed,
so on a hosted runner they reported green without ever running. Install
the pack in CI before the E2E step so the specs actually execute.

The step runs from RUNNER_TEMP rather than the repo, so a repository
global.json cannot mask the runner's SDK, and it fails loudly with a
clear message if the CLI or the SDK is missing.

Also drop the duplicated resolveCliPath() in the QuickPick spec in favour
of the shared getWinappCliPath() helper, so the test resolves the CLI the
same way the extension does.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Coverage stopped at the prompts: nothing asserted that a scaffold
actually produces a project. Add a spec that drives the extension's own
buildNewArgs -> CLI -> parseScaffoldResult chain and then checks the
files on disk.

Two cases: a successful scaffold, and a name collision, which must fail
with exit 2 and leave a pre-seeded file untouched.

The spec matches on basenames found recursively rather than a fixed
layout, because the template nests the project under App\ instead of
writing flat into --output. Paths are compared via realpath, since
os.tmpdir() reports the 8.3 short form while the CLI reports the long
one. The run pins --template-version installed so it neither reaches a
feed nor changes which pack is on the machine, and skips when no pack is
installed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
runWinappCapture took a per-command cancelMessage so the output channel
could say `App creation cancelled.` or `Loading templates cancelled.`
instead of the packaging wording it was hardcoded to. Per review, cancel
messages should not be command specific.

Drop the parameter entirely rather than renaming its default, and write
`WinApp command cancelled.` for every command. This also removes the
pre-existing `Packaging cancelled.` string, so pack now reads the same
way as the rest.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment blocks ran long enough to bury the code they described. Cut every
block in this feature to at most three lines of prose, keeping @PARAM and
@returns tags intact.

No behavior change: 494 -> 336 comment lines, with the substance kept
(why listing pins --template-version installed, why the scaffold spec
matches basenames, why listing runs from a neutral cwd) and the
restatement dropped.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The template pack is a machine-wide 'dotnet new' install. A user could run
the command, update the pack from a terminal, and run it again in the same
window; the cache would then serve the old list and, worse, label the
version QuickPick with a pack version that is no longer installed. Picking
"use installed" scaffolds with --template-version installed, so the CLI
would use the new pack while the UI named the old one.

There is no invalidation signal short of asking the CLI, which is the
probe itself. The pinned 'installed' listing measures ~1.4s warm, so the
cache bought roughly a second on a repeat run in the same window at the
cost of showing wrong information. Always probe instead.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ures

runTemplateList deliberately returns its outcome instead of surfacing it,
because the first attempt fails routinely on a machine with no template
pack and the retry then succeeds. The old wording said "without reporting
failures" without saying who does report, which reads like a swallowed
error. Name loadWinUiTemplates as the reporter.

Comment-only change.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The doc comment led with plumbing ("wire the file system into X") instead of
what the function decides, and the imported logic function was aliased with a
Logic suffix while the pre-existing wrapper pattern in this file
(resolveProjectDirectory -> resolveProjectDirectoryCore) uses Core.

- Rewrite the resolveScaffoldTarget doc to lead with purpose and return value.
- Rename resolveScaffoldTargetLogic/loadWinUiTemplatesLogic to *Core.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Per review: when a workspace is already open the new app is created inside it,
so offering to open it again is redundant. Replaced with a plain notification
naming the app and its path so success still has feedback.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Per review: the extension was re-implementing winapp new's name rules (max
length, reserved device names, option-shaped names, trailing dot/space,
invalid filename chars), which duplicates CLI logic and can drift from it.

Keep only what the extension needs before it builds a path of its own: a
non-empty name with no path separators or dot segments. Everything else is
left to the CLI, whose error text is already surfaced verbatim.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Per review: validating the name is the CLI's job. Removes validateProjectName
and the input box's validateInput, so every name goes to winapp new and its
error text is surfaced verbatim.

The one real extension-side concern was that path.join(parent, name) could
point outside the folder the user picked, making us inspect and offer to
--force into an unrelated directory. That is now a containment check on the
joined path in resolveScaffoldTarget rather than a rule about the name.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Per review: ensureAvailableName was a port of the CLI's EnsureAvailableName,
and the preflight around it duplicated a guard the CLI already performs.
Verified the CLI refuses a non-empty --output with exit 2, an actionable
message, and no writes.

Removes ensureAvailableName, ScaffoldTarget, ScaffoldTargetAdapter and both
resolveScaffoldTarget functions. The command now scaffolds first and, when the
CLI reports the directory is not empty, offers a --force retry quoting the
CLI's own message. The extension no longer touches the file system here, so
the joined-path containment guard is gone too.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
extractJsonObject was not specific to `winapp new`, and extension.ts already
had a narrower near-duplicate in parseProcessIdFromJson. Move the helper to
winapp-cli-utils.ts (the VS Code-free winapp CLI module) and have both call
sites share it.

parseProcessIdFromJson previously required stdout to be JSON and nothing else;
it now tolerates surrounding progress text, which is strictly more permissive
and still returns undefined on a partially-arrived buffer.

Adds src/test/cli-json-output.test.ts and registers it in the test:unit file
list, which is explicit rather than a glob.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Every template in the pack reports Type "project" (verified against
winapp 0.6.1 --list --json: winui, winui-lib, winui-mvvm, winui-navview,
winui-tabview, winui-unittest). The filter removed nothing, and hiding an
unrecognised template would be worse than showing it.

Removes isProjectTemplate, the now-unused WinUiTemplate.type field and its
parse, and the empty-list guard that parseTemplateList already covers.

Also repairs an E2E test that asserted inline name validation, which was
removed earlier in this branch. It now asserts the opposite contract: an
invalid name is not blocked inline, because the CLI reports it.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Drops sortTemplates and DEFAULT_TEMPLATE_SHORT_NAME. The CLI already returns
templates in a stable order with winui first, so re-sorting in the extension
only risked drifting from whatever ordering winappcli intends.

Removes the now-unused test template() factory and imports.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
describeNewFailure had a switch inventing a message for each exit code. The
CLI already reports an actionable Error in its JSON payload for every failure
reachable in this flow, so the switch was near-dead and risked drifting from
the CLI's wording.

The function now prefers the CLI's Error text, and when no JSON payload was
emitted at all (the CLI died first) it surfaces the raw stdout/stderr rather
than discarding it. The single remaining fallback names the exit code.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The set of WinUI templates is owned by the template pack and will change, so
the README no longer enumerates it.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Both routes to the unpinned listing install the newest pack: an explicit
'latest' updates a stale one, and the default path only gets there after the
'installed' probe reports no pack at all, where unpinned fetches on demand.
The ternary implied a third case that installs something older, which no code
path reaches. Collapse it to one message and pin the first-install wording.

Also restore the project-detection README line to its original wording.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The picker rendered a tag detail line, but the tags carry almost nothing:
'Windows/WinUI' is constant across every template, and the three XAML app
shells are tag-identical, so the detail line repeated itself and could not
distinguish the rows it sat under. Match 'winapp new --list' instead, which
shows the display name and short name (its Type column is always 'project').

Drops formatTemplateTags and the now-unused WinUiTemplate.tags field. The
test fixture keeps Tags, since it documents a real CLI payload and pins that
the parser tolerates fields we ignore.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The adapter existed so the probe-then-retry logic could be unit tested without
spawning the CLI, but 'winapp new --list' is a single call and the extension
already spawns the CLI directly everywhere else. Move the flow next to the
command that uses it and call runTemplateList and showNewFailure directly.

Drops TemplateLoadAdapter and the 13 unit tests that scripted it. The live-CLI
E2E suites still cover the flow end to end; what is no longer pinned is the
exit-4 rule, which needs a machine with no .NET SDK to exercise for real.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Applies the three-line rule to every comment this PR added. The header and the
loadWinUiTemplates doc comment were the worst offenders at four and eight lines;
three more blocks ran to four. Cut restatement, kept the non-obvious why.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
DEFAULT_PROJECT_NAME was documented as matching the CLI's DefaultNameFor, but
the flow always passes --name explicitly, so the CLI default never runs and the
two can never actually disagree. The constant was a UI prefill wearing a
CLI-contract label, inviting drift anxiety over a coupling that does not exist.

Replaced with a local prefill in the input box and removed the export.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Rewrite extractJsonObject as a single-pass balanced-brace scanner. The
previous last-brace walk-back mis-parsed payloads preceded by prose
containing a brace, and was quadratic per call -- which the streaming
caller amplified, since it re-scans the whole accumulated buffer on every
stdout chunk. Strings are only tracked once inside a candidate object so
an odd quote in prose cannot swallow the payload.

Move the winapp.new flow into new-command.ts and the shared VS Code
helpers it needs into winapp-host.ts, keeping extension.ts from growing
without bound and avoiding an import cycle.

Share the E2E temp-directory and template-pack fixtures between the two
new-command specs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@chiaramooney
Chiara Mooney (chiaramooney) force-pushed the chiaramooney-winapp-new-scaffold-support branch from 270b125 to 16886ba Compare September 29, 2026 21:18
CI installs the latest WinUI template pack, which now ships an
experimental "reactor" template ahead of the blank app. The spec pinned
the first row to "WinUI Blank App" and required every row to match
/winui/i, so an upstream pack change failed the build.

Compare the picker against `winapp new --list` instead. That checks what
the extension actually owns -- the CLI's order, and the
"Display Name (short-name)" rendering -- and cannot drift when the pack
gains or reorders templates.

Read the label rather than the whole row: VS Code renders a separator
inside the row and recycles row DOM, so row text can carry stale chrome.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@chiaramooney
Chiara Mooney (chiaramooney) merged commit f0f7f7c into main Sep 29, 2026
6 checks passed
@chiaramooney
Chiara Mooney (chiaramooney) deleted the chiaramooney-winapp-new-scaffold-support branch September 29, 2026 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants