Skip to content

test(services): crash-dump / XAML-triage / debug-output coverage to 95% - #644

Merged
Alexandre Zollinger Chohfi (azchohfi) merged 3 commits into
mainfrom
azchohfi-tests-services-crash
Jul 15, 2026
Merged

Alexandre Zollinger Chohfi (azchohfi) merged 3 commits into
mainfrom
azchohfi-tests-services-crash

Conversation

@azchohfi

Copy link
Copy Markdown
Collaborator

PR 5 — Test coverage: crash-dump / XAML-triage / debug-output services

Raises test coverage on the crash-analysis, XAML-triage, and debug-output services toward the ≥95% per-file bar, part of the coverage-to-95% effort (issue #630). Real-workflow tests first (genuine minidumps analyzed by the in-process ClrMD/DbgEng engines; a live Win32 debug-event loop; offline NuGet/bundle acquisition), then targeted unit tests for parsing/orchestration/error paths.

Per-file Debug line coverage (authoritative coverage-report.ps1 -Configuration Debug, full run)

File Before After Status
Services/XamlTriageResult.cs 100% 100% ✅
Services/XamlTriageRunner.cs 78.1% 97.2% ✅
Services/WinDbgJsProviderAcquirer.cs 97.4% 96.6% ✅
Services/XamlTriageService.cs 86.6% 96.4% ✅
Services/DebugOutputService.cs 89.9% 96.4% ✅
Services/XamlTriageBinaries.cs 42.4% 95.6% ✅
Services/CrashDumpService.cs 70.8% 91.5% documented honest ceiling

6 of 7 files ≥95%. CrashDumpService lands at 91.5% as a rigorously per-line-documented ceiling (see below).

Product changes — test seams only, all behavior-preserving

No runtime-behavior change, no coverage exclusions, no visibility widened beyond internal. All changes are at OS/engine boundaries and were reviewed as character-identical extractions / additive-visibility only:

  • CrashDumpService.cs — AppendStackOverflowSummary<TFrame> now takes raw frames + nameSelector/sourceResolver delegates and resolves lazily inside the 15-cap loop (restores origin/main behavior: ≤15 PDB lookups, no eager resolution of thousands of overflow frames). DownloadSymbolsForModules(imagePathProvider) extracted so the download/cache/PE-parse core is covered offline. Analyzer/symbol-downloader Func seams (ClrMdAnalyzerOverride/DbgEngAnalyzerOverride/SymbolFileDownloader); pure helpers extracted (AppendStackOverflowSummary/ParseStackModuleNames/WinUI-module helpers, char-identical); a few helpers widened to internal.
  • DebugOutputService.cs — GetContextFlags(Architecture) extracted; HandleException/ReadExceptionParameters → internal; three pure noise-filter helpers → internal.
  • XamlTriageBinaries.cs — pure KitsArchFor/NuGetArchFor extracted; HttpGetAsync Func seam; TryMaterializePackageAsync → internal.
  • XamlTriageRunner.cs — RunTriageSequence(execute, getOutput) extracted so the whole command sequence + symbol-path + provider-load-fail is covered offline.
  • XamlTriageService.cs — ProcessPathProvider Func seam (reaches the dotnet-host branch — an MTP host is an apphost, never dotnet.exe); BuildTriageStartInfo/DownloadExtensionBytesAsync extracted; timeout/extension-download/hash/binaries-resolver Func seams.
  • WinDbgJsProviderAcquirer.cs — network-free TryAcquireCoreAsync split out; host-arch/signature/engine-compat Func seams.

Precedent for these seams: UpdateNotificationService.cs. No dead code found to delete.

CrashDumpService 91.5% — documented honest ceiling

The 67 residual lines are all genuine native/engine/network boundaries, reconciled per-line in a <remarks> block on CrashDumpServiceWorkflowTests. Reaching them would require a foreign CPU architecture, a live symbol server, a corrupt/stripped/mismatched PE or PDB, or Win32/engine fault injection — all policy-forbidden (no flaky tests, no OS-mutating tests, no [ExcludeFromCodeCoverage] on hand-written logic):

  • 162-165, 171-174 — MiniDumpWriteDump P/Invoke returning FALSE + outer catch (native dump-write failure; can't provoke without corrupting the OS call).
  • 378-407 — cross-architecture DAC / emulation branches (needs a non-x64 dump analyzed on an x64 host).
  • 598-603 — DumpHasWinUiModule catch (DAC not loadable on this host).
  • 689-691 — FormatManagedException per-frame source append — a dedicated test (AnalyzeDumpAsync_DeepStackWithPortablePdb_ResolvesManagedSourceLocations) exists but goes Assert.Inconclusive because the child-runtime DAC is not loadable here.
  • 834-835 — non-CodeView debug-directory-entry skip.
  • 913-925 — DefaultDownloadSymbolFile HTTPS (live msdl network).
  • 1034-1038, 1081-1102, 1143-1223 — no-CodeView-accept, ClrMD null-Method/Module guards (ClrStackFrame/ClrMethod/ClrModule have no public ctor — can't be faked null), and corrupt-/locked-PDB catches.

This mirrors the documented-ceiling approach used elsewhere in this coverage effort. Definition of done: ≥95% OR a documented honest ceiling.

Verification

  • Release build (both WinApp.Cli.csproj + WinApp.Cli.Tests.csproj, -p:UseSharedCompilation=false -nodeReuse:false): 0 warnings / 0 errors (warnings-as-errors).
  • Debug coverage self-verified from the cobertura report (numbers above).
  • Full suite green except the known pre-existing environment failures (EndToEndTests needing src/winapp-npm/dist/cli.js / NativeAOT winapp.exe) and DAC-gated Assert.Inconclusive skips on this host — none introduced by this PR.

Review

This branch was reviewed with the repo's pr-review skill before opening. One high finding (H1 — a stack-overflow-summary extraction that had regressed origin/main's lazy source-resolution into an eager .Select(...).ToList()) was caught and fixed: source resolution is now lazy inside the 15-frame cap, guarded by a regression test (50 distinct frames, a poison resolver that throws past the cap, asserting exactly 15 resolutions). Four medium coverage findings were addressed (XamlTriageRunner 79.7→97.2%, DebugOutputService, XamlTriageBinaries, CrashDumpService lmvm).

Co-authored-by: Copilot App [email protected]

Raise Debug line coverage for the crash-dump / XAML-triage / debug-output
services with real-workflow tests first (genuine minidumps analyzed by the
in-process ClrMD/DbgEng engines, a live Win32 debug-event loop driven by a
controlled child process, and offline NuGet/bundle acquisition), then targeted
unit tests for parsing, orchestration, and error paths.

Product changes are test seams only and behavior-preserving:
- CrashDumpService: ClrMD/DbgEng analyzer + symbol-download Func seams; extract
  AppendStackOverflowSummary / ParseStackModuleNames / WinUI-module helpers as
  pure functions; move ValidatePdbMatchesDll to the outer class; widen a few
  helpers to internal.
- XamlTriageService: extract BuildTriageStartInfo; add timeout / process-path /
  extension-download / hash / binaries-resolver Func seams.
- XamlTriageBinaries: HttpGetAsync Func seam; TryMaterializePackageAsync internal.
- WinDbgJsProviderAcquirer: split out network-free TryAcquireCoreAsync; add
  host-arch / signature / engine-compat Func seams.
- DebugOutputService: widen 3 pure noise-filter helpers to internal.

Final per-file Debug line coverage: XamlTriageResult 100%,
WinDbgJsProviderAcquirer 97.4%, XamlTriageService 96.3%. XamlTriageBinaries
93.7%, DebugOutputService 92.8%, CrashDumpService 89.8% and XamlTriageRunner
79.7% are documented honest ceilings (cross-architecture DAC, live symbol
servers, Win32 fault injection, and host-architecture switch arms are
unreachable without flaky or cross-arch tests; the specific uncovered line
ranges and rationale are recorded in ceiling remarks on each test class).

No coverage exclusions added; coverage.runsettings unchanged.

Co-authored-by: Copilot App <[email protected]>
…lings

H1: AppendStackOverflowSummary now resolves each frame's name/source lazily
inside the 15-frame cap via nameSelector/sourceResolver delegates (was
eagerly resolving PDB source for every deepest frame before the cap - a perf
and exception-surface regression vs origin/main). Added a regression test
asserting resolution happens for at most 15 frames.

M1: Extract XamlTriageRunner.RunTriageSequence (execute/getOutput delegates)
so the full DbgEng command sequence, symbol-path config, and provider-load
failure are covered offline. XamlTriageRunner 79.7% -> 97.2%.

M2: DebugOutputService - HandleException/ReadExceptionParameters made
internal and pure GetContextFlags(Architecture) extracted; covered via
fabricated DEBUG_EVENTs + unit tests. 92.8% -> 96.4%.

M3: Extract pure XamlTriageBinaries.KitsArchFor/NuGetArchFor; covered
X64/Arm64/X86/fallback. 93.7% -> 95.8%.

M4: Extract CrashDumpService.DownloadSymbolsForModules (image-path provider
delegate) so the download/cache/PE-parse core is covered offline; the live
lmvm boundary is isolated in GetModuleImagePath.

Reconcile every ceiling <remarks> to the actual uncovered lines.
CrashDumpService remains a documented 91.5% honest ceiling (native P/Invoke
fault injection, cross-arch DAC, live symbol network, ClrMD-null-object
guards, corrupt-PDB edges - all policy-forbidden to force). All seams are
behavior-preserving and confined to OS/engine boundaries.

Co-authored-by: Copilot App <[email protected]>
Copilot AI review requested due to automatic review settings July 15, 2026 17:36

Copilot AI 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.

Pull request overview

Expands crash-analysis, XAML-triage, and debug-output coverage for issue #630 through internal test seams and workflow tests.

Changes:

  • Extracts injectable OS, engine, network, and process boundaries.
  • Adds real-dump/debug-loop workflows and offline acquisition tests.
  • Adds focused coverage for parsing, orchestration, and failure paths.

Reviewed changes

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

Show a summary per file
File Description
Services/XamlTriageService.cs Adds triage test seams and process helpers.
Services/XamlTriageRunner.cs Extracts the DbgEng command sequence.
Services/XamlTriageBinaries.cs Adds HTTP and architecture seams.
Services/WinDbgJsProviderAcquirer.cs Extracts network-free acquisition logic.
Services/DebugOutputService.cs Exposes pure exception/debug helpers.
Services/CrashDumpService.cs Adds analyzer seams and extracted helpers.
XamlTriageServiceWorkflowTests.cs Tests triage orchestration and processes.
XamlTriageRunnerTests.cs Tests parsing and DbgEng sequencing.
XamlTriageResultTests.cs Covers result factories and properties.
XamlTriageBinariesTests.cs Expands layout and architecture coverage.
XamlTriageBinariesDownloadTests.cs Tests offline package downloads.
XamlTriageBinariesAcquisitionTests.cs Tests local acquisition workflows.
WinDbgJsProviderAcquirerTests.cs Tests provider extraction and verification.
TestProcessDump.cs Generates native and managed test dumps.
FakeWinappDirectoryService.cs Provides isolated cache directories.
DebugOutputServiceWorkflowTests.cs Exercises the live debug-event loop.
DebugOutputServiceTests.cs Covers classification and context helpers.
CrashDumpServiceWorkflowTests.cs Exercises real dump-analysis workflows.
CrashDumpServiceTests.cs Expands orchestration and helper coverage.

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

Comment on lines +555 to +576
var name = nameSelector(frame);
var sourceInfo = sourceResolver(frame);
var displayName = sourceInfo != null ? $"{name} in {sourceInfo}" : name;

if (name == lastFrame)
{
repeatCount++;
continue;
}

if (repeatCount > 0)
{
summary.AppendLine($" ... (repeated {repeatCount} more times)");
displayed++;
}

if (displayed >= 15)
{
break;
}

summary.AppendLine($" {displayName}");
Comment on lines +319 to +321
var stderr = p.StandardError.ReadToEnd();
_ = p.StandardOutput.ReadToEnd();
p.WaitForExit(60000);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in e60b035. Added TestProcessDump.WaitForExitDrainingPipes, which starts both StandardOutput/StandardError ReadToEndAsync before WaitForExit (so neither pipe can back-pressure the child) and kills the process tree on timeout. This call site is rewired to use it.

Comment on lines +603 to +610
var stdout = proc.StandardOutput.ReadToEnd();
var stderr = proc.StandardError.ReadToEnd();
if (!proc.WaitForExit(120000))
{
try { proc.Kill(entireProcessTree: true); } catch { /* best effort */ }
error = "'dotnet build' timed out";
return false;
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in e60b035. Same as the compile path: this dotnet-build call site now uses WaitForExitDrainingPipes (concurrent drain before WaitForExit, kill on timeout) instead of sequential ReadToEnd, and the now-duplicate kill was removed.

Comment on lines +312 to +313
var symbolCache = Path.Combine(Path.GetTempPath(), "symbols");
try { if (Directory.Exists(symbolCache)) { Directory.Delete(symbolCache, recursive: true); } } catch { /* best effort */ }

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in e60b035. Added an internal CrashDumpService.SymbolCacheDirectory seam (defaults to the real %TEMP%\symbols); the test now points it at an isolated _tempDir\symbols and saves/restores it in a finally, so it no longer recursively deletes the shared developer/CI symbol cache. Only per-test temp dirs are cleaned up now.

Comment on lines +850 to +852
// Download from Microsoft Symbol Server (seamed for tests)
var pdbBytes = SymbolFileDownloader($"https://msdl.microsoft.com/download/symbols/{pdbName}/{sig}/{pdbName}");
if (pdbBytes == null)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in e60b035. Restored origin/main streaming: the SymbolFileDownloader seam is now Func<url, destPath, bool>, and DefaultDownloadSymbolFile streams the response straight to the destination file (pdbStream.CopyTo into File.Create(destPath)) with constant memory. DownloadSymbolsForModules no longer materializes the whole PDB via MemoryStream.ToArray + File.WriteAllBytes.

Comment on lines +200 to +202
// Proves the extension commands ran against an opened dump (the extension exports are absent
// because the real JsProvider.dll is not present, which is expected in a hermetic test).
StringAssert.Contains(result, "xamlstowed");

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in e60b035. The test now early-returns Assert.Inconclusive when output contains "could not load the JavaScript provider" (the host-dependent .load HRESULT), so it no longer asserts on the full command sequence when DbgEng rejects the absent provider. The load-failure path stays covered deterministically offline by RunTriageSequence_LoadProviderFails.

Comment on lines +230 to +239
var (exit, stdout, _) = RunCaptured(
[XamlTriageRunner.InternalVerb, "--dump", dump, "--bin", system32, "--ext", ext, "--jsprovider", bogusJsProvider]);

if (exit != 0)
{
Assert.Inconclusive("In-process DbgEng engine unavailable (Run mapped it to a non-zero exit).");
return;
}

StringAssert.Contains(stdout, "xamlstowed");

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in e60b035. Same host-invariant guard: when the .load of the absent provider fails, Run() can return 0 (triage fails open) with the load-failure message in stdout, so the test now goes Assert.Inconclusive in that case instead of treating it as the success path. Offline coverage via RunTriageSequence_LoadProviderFails.

@github-actions

github-actions Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Build Metrics Report

Binary Sizes

Artifact Baseline Current Delta
CLI (ARM64) 31.90 MB 31.92 MB 📈 +15.5 KB (+0.05%)
CLI (x64) 32.23 MB 32.24 MB 📈 +14.5 KB (+0.04%)
MSIX (ARM64) 13.39 MB 13.40 MB 📈 +7.4 KB (+0.05%)
MSIX (x64) 14.23 MB 14.25 MB 📈 +14.1 KB (+0.10%)
NPM Package 27.93 MB 27.95 MB 📈 +18.9 KB (+0.07%)
NuGet Package 27.96 MB 27.97 MB 📈 +9.2 KB (+0.03%)

Test Results

✅ 1855 passed, 2 skipped out of 1857 tests in 507.5s (+194 tests, +96.3s vs. baseline)

Test Coverage

❌ 52.8% line coverage, 61.4% branch coverage · ✅ +4.7% vs. baseline

CLI Startup Time

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


Updated 2026-07-15 20:37:08 UTC · commit e60b035 · workflow run

Fixes the 6 confirmed findings from the auto-review bot, touching only the
files needed:

- #1 (BLOCKING, machine-mutating test): add an internal SymbolCacheDirectory
  seam to CrashDumpService (defaults to the real %TEMP%\symbols). The workflow
  test now points it at an isolated _tempDir\symbols instead of recursively
  deleting the developer's/CI's shared symbol cache.
- #2 (product memory regression): restore origin/main streaming for symbol
  downloads. The SymbolFileDownloader seam becomes Func<url, destPath, bool>;
  DefaultDownloadSymbolFile streams the response straight to the destination
  file (constant memory), and DownloadSymbolsForModules no longer materializes
  the whole PDB via MemoryStream/File.WriteAllBytes.
- #3/#4 (test-helper deadlock): TestProcessDump.WaitForExitDrainingPipes drains
  stdout and stderr concurrently before WaitForExit (was sequential ReadToEnd),
  killing the process tree on timeout. Both call sites rewired.
- #5/#6 (env-dependent tests): the two bogus-provider XamlTriageRunner tests now
  treat a host-dependent `.load` failure as inconclusive instead of asserting on
  output that only appears when the full command sequence runs.

Also reconciles the CrashDumpService coverage-ceiling <remarks> line numbers to
the current source (91.3% Debug, 68 honestly-uncovered native/DAC/network/PDB
boundary lines; the streaming restoration adds one line to the network boundary).

Co-authored-by: Copilot App <[email protected]>
@azchohfi
Alexandre Zollinger Chohfi (azchohfi) merged commit 14c3207 into main Jul 15, 2026
30 of 32 checks passed
@azchohfi
Alexandre Zollinger Chohfi (azchohfi) deleted the azchohfi-tests-services-crash branch July 15, 2026 20:53
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