Skip to content

test(hr): re-enable the hot-reload metadata test suite on Roslyn 5.6 and make it run on Linux - #24072

Merged
dr1rrb merged 7 commits into
masterfrom
dev/dr/hr-metadata-tests-linux
Aug 22, 2026
Merged

dr1rrb merged 7 commits into
masterfrom
dev/dr/hr-metadata-tests-linux

Conversation

@dr1rrb

@dr1rrb dr1rrb commented Aug 13, 2026

Copy link
Copy Markdown
Member

GitHub Issue: closes #24071

PR Type:

🏗️ Build or CI related changes

What changed? 🚀

The MetadataUpdate hot-reload suite in Uno.UI.SourceGenerators.Tests — the only end-to-end
coverage we have for XAML codegen × Edit-and-Continue — has not run since it was Compile Removed
as a consequence of the dev-server Roslyn 5.6 bump. It was not failing, it was not compiled: the
project discovered 232 tests instead of 482, and nothing signalled it, because the scenario data kept
being copied to the output directory. This re-enables it, migrates it to the 5.6 line, and makes it
run on a non-Windows host.

Measured on this branch: 482 tests, 468 passing, 12 failing, 2 skipped — from 232 discovered and
0 hot-reload scenarios executing.

1. Re-enable the suite on Roslyn 5.6

Restore the two Compile Removed files and the Uno.HotReload ProjectReference, and take the
Roslyn versions from Uno.DevServer.Roslyn.props instead of pinning them locally — this project
references Uno.HotReload, so its Roslyn line has to be that project's line by construction, and a
local pin is exactly what produced the NU1107 that got the suite disabled.

Two 5.6 adjustments were needed:

  • Workspace.WorkspaceFailed is [Obsolete] (error under warnaserror) in Roslyn 5.x → use
    RegisterWorkspaceFailedHandler, the shape CompilationWorkspaceProvider already uses in the
    dev-server host.
  • SourceText.From defaults to SourceHashAlgorithm.Sha1 while Roslyn 5.x creates the project — and
    hence the actual generated documents — with Sha256, and the harness compares the two.

Validated by an A/B against the 4.14 line (project built as net9.0, which resolves
Uno.HotReload's net9 flavor): both lines fail the exact same tests, so nothing here is a
5.6-specific regression.

2. Make the harness run on Linux

Three host assumptions kept every scenario failing off Windows:

  • The globalconfig declared build_property.MSBuildProjectFullPath as C:\Project\<name>.csproj.
    The generator derives _projectDirectory from it with Path.GetDirectoryName, which returns ""
    for a drive-letter path on Unix, and an empty project directory then mangles every path it feeds
    through Substring(_projectDirectory.Length + 1). 218 → 2 "does not contain a definition for
    InitializeComponent" failures.
  • Compilation.Emit(assemblyPath, pdbPath:) writes a Windows PDB, which needs the native
    DiaSymReader and fails on Linux with CS0041 Unexpected error writing debug information. Emit
    through Uno.HotReload's own EmitCompilationOutputAsync instead: it writes an embedded pdb, and
    the baseline the EnC session starts from becomes the one HotReloadManager captures in production.
    248 → 12 hot-reload failures.
  • HotReloadWorkspace leaked a Roslyn workspace, its compilations and an open EnC session per
    scenario. Over ~250 scenarios the test host got OOM-killed partway through — and because the kill
    landed after the last reported result, runs looked complete while silently covering only 145-154 of
    250 tests. It is now IDisposable.

3. Make the snapshot fixture host-independent

The fixture hardcoded a Windows fake project root (C:\Project, [C:/Project/0/...] sections).
Roslyn rejects a drive-letter section name on Unix — PathUtilities.IsAbsolute only accepts a
leading / there, so the section is dropped with "is invalid as it is not an absolute path. Section
will be ignored"
— which left the XAML files without their SourceItemGroup=Page metadata, so no
page was ever generated.

//Project is used instead: two leading separators are absolute on both platforms
(IsAbsolute's UNC branch on Windows, the leading / on Unix), so one literal serves both hosts.
The generated file name embeds a hash of the file path (XamlFileDefinition.UniqueID), so the
snapshots were regenerated.

Two further host dependencies had to go, or the regenerated snapshots would only have been valid on
the host that produced them:

  • build_metadata.AdditionalFiles.Link is now declared. Without it the generator derives the
    source link — the // Source … comments, the BaseUri target path and the ms-appx:/// URIs — from
    the item path minus _projectDirectory, using Path.GetDirectoryName and
    Path.DirectorySeparatorChar. Both are host dependent: the committed baselines said
    0\MainPage.xaml while Linux produced 0/MainPage.xaml.
  • The expected SourceText now carries the checksum algorithm the actual document carries, per
    file.
    The harness matches expected to actual by a weighted distance over content, encoding and
    checksum algorithm, so a single mismatched document leaves no exact alignment, the matcher falls
    back to an arbitrary one, and the failure surfaces as a misleading "Expected source file list to
    match"
    . Roslyn takes the algorithm from how the generator adds the source:
    AddSource(name, string) uses the compilation's (Sha256 on the 5.x line) while
    AddSource(name, SourceText) keeps what the SourceText carries — and the generators here build
    it with SourceText.From, whose API default is Sha1.

4. Deterministic generated line endings

XamlCodeBehindEmitter.Emit built its output from a verbatim string literal, so the newlines of the
generated code-behind were those of the emitter's own source file as checked out (* text=auto
yields LF on Unix and CRLF on Windows), and the interpolated source comment hardcoded CRLF on top of
that. The same sources produced different generated code on different hosts, with mixed endings
inside one file. The emitted text is now normalized to LF, so the output is a function of its inputs
only.

The snapshot fixtures are also marked -text: they are compared byte-for-byte against generator
output, so * text=auto was actively harmful — it stored them with LF, so a checkout materialized LF
on Unix while some of them come from a generator shipped as a NuGet package, which bakes the newlines
of its own sources at package build time and therefore emits CRLF on every host. Those fixtures only
ever matched on the platform whose checkout happened to restore the original endings, and git hid it:
the working copy kept its CRLF bytes while the blob held LF, and git status reported no change
because the clean filter normalized them back on comparison.

Still failing, tracked separately

12 hot-reload scenario cases (6 scenarios × 2 configurations) fail with ENC0014 (base class change)
and ENC0033 (class deletion) against expectations of zero diagnostics —
When_Base_Type_* and When_Style_MarkupExtension_*Remove_Inc_Ext. This is not a Linux problem:
an A/B of the complete suite against the 4.14 line fails none of them, so Roslyn 5.6 reports these as
rude edits where 4.14 did not. Whether the scenarios' expectations should change is a separate
decision, so they are left failing rather than silently re-baselined.

When_Page_Res_xBind_Remove remains skipped behind its IsCrashingRoslyn flag.

PR Checklist ✅

dr1rrb added 4 commits August 13, 2026 11:00
…#24071)

The suite was Compile Remove'd in ea42f02 (spec 053 R2): the project
pinned Roslyn 4.14 while Uno.HotReload pins 5.6 on net10, which NuGet
cannot resolve (NU1107). 232 tests were discovered instead of 482, and
nothing signalled it -- the scenario data kept being copied to the output
directory.

Restore the two files and the Uno.HotReload ProjectReference, and take the
Roslyn versions from Uno.DevServer.Roslyn.props instead of pinning them
here: this project references Uno.HotReload, so its Roslyn line must be
that project's line by construction, and a local pin is exactly what
produced the skew.

Two 5.6 adjustments were required:

- Workspace.WorkspaceFailed is [Obsolete] (error under warnaserror) in
  Roslyn 5.x. Use RegisterWorkspaceFailedHandler behind
  NET10_0_OR_GREATER, the same shape CompilationWorkspaceProvider already
  uses in the dev-server host.
- SourceText.From defaults to SourceHashAlgorithm.Sha1 while Roslyn 5.x
  creates the project -- and hence the actual generated documents -- with
  Sha256, and the testing harness compares the two. Pass Sha256 for the
  hand-written expected sources.

Validated by an A/B against the 4.14 line (project built as net9.0, which
resolves Uno.HotReload's net9 flavor): both lines now fail the exact same
349 tests, so this leaves no 5.6-specific regression.

Those 349 remaining failures are pre-existing and environmental, not a
consequence of this change: the harness hardcodes
build_property.MSBuildProjectFullPath = C:\Project\Project.csproj and
[C:/Project/0/...] config sections, and 109 committed snapshots embed
C:/Project, so the XAML page file is never generated when running on
Linux. Snapshot regeneration must therefore happen on Windows -- doing it
from Linux would bake host paths into the baselines.
…4071)

Three host assumptions kept every scenario of the suite failing on a
non-Windows host. Measured on 482 tests: 349 failures -> 113, and the run
now completes instead of being OOM-killed.

- The globalconfig declared build_property.MSBuildProjectFullPath as
  C:\Project\<name>.csproj. The XAML generator derives _projectDirectory
  from it with Path.GetDirectoryName, which returns "" for a drive-letter
  path on Unix, and an empty project directory then mangles every path it
  feeds through Substring(_projectDirectory.Length + 1). Use a host-native
  absolute path: 218 "MainPage does not contain a definition for
  InitializeComponent" failures -> 2.

- Compilation.Emit(assemblyPath, pdbPath:) writes a Windows PDB, which
  needs the native DiaSymReader and fails on Linux with CS0041 "Unexpected
  error writing debug information -- Value cannot be null (Parameter
  'type')". Emit through Uno.HotReload's own EmitCompilationOutputAsync
  instead: it writes an embedded pdb, and the baseline the EnC session
  starts from becomes the one HotReloadManager captures in production.
  248 hot-reload failures -> 12.

- HotReloadWorkspace leaked a Roslyn workspace, its compilations and an
  open EnC session per scenario. Over ~250 scenarios the host got
  OOM-killed partway through, and because the kill happened after the last
  reported result the runs looked complete while silently covering only
  145-154 of 250 tests. Make it IDisposable (end the session, dispose the
  workspace) and use it from ApplyScenario.

The 12 hot-reload failures left are NOT a Linux problem: an A/B of the
complete suite against the 4.14 line (project built as net9.0) fails none
of them, so Roslyn 5.6 reports ENC0014 (base class change) and ENC0033
(class deletion) as rude edits where 4.14 did not. Six scenarios are
affected -- When_Base_Type_* and When_Style_MarkupExtension_*Remove_Inc_Ext
-- and whether their expectations should change is a separate decision.

The remaining 101 failures are the XamlCodeGeneratorTests family: its
verifier hardcodes C:/Project paths, which Roslyn rejects as global
analyzer config section names on Unix ("not an absolute path. Section will
be ignored"), so no page is generated. Addressed separately.
…24071)

Takes the suite from 113 failures to 21 on Linux (459 of 482 passing).

The fixture hardcoded a Windows fake project root, "C:\Project\Project.csproj"
plus [C:/Project/0/...] global analyzer config sections. Roslyn rejects a
drive-letter section name on Unix -- PathUtilities.IsAbsolute only accepts a
leading '/' there, so the section is dropped with "is invalid as it is not an
absolute path. Section will be ignored" -- which left the XAML files without
their SourceItemGroup=Page metadata, so no page was ever generated and 98 tests
failed on a file list that could not contain MainPage_<hash>.cs.

Use "//Project" instead: two leading separators are absolute on BOTH platforms
(IsAbsolute's UNC branch on Windows, the leading '/' on Unix), so one literal
serves both hosts. Since the generated file name embeds a hash of the file path
(XamlFileDefinition.UniqueID), the snapshots had to be regenerated -- 91
old-hash files removed, 93 added, 121 updated.

Two further host dependencies had to go, or the regenerated snapshots would
have been valid only on the host that produced them:

- Declare build_metadata.AdditionalFiles.Link. Without it the generator derives
  the source link -- the `// Source ...` comments, the BaseUri target path and
  the ms-appx:/// URIs -- from the item path minus _projectDirectory, using
  Path.GetDirectoryName and Path.DirectorySeparatorChar. Both are host
  dependent: the committed baselines said `0\MainPage.xaml` while Linux
  produced `0/MainPage.xaml`. Link short-circuits that math in GetSourceLink
  and XamlFileParser.GetTargetFilePath alike. No snapshot carries a
  backslash-form source link any more.
- Build the expected SourceText with the checksum algorithm the actual document
  carries, per file. The harness matches expected to actual by a weighted
  distance over content, encoding AND checksum algorithm, so one mismatched
  document leaves no exact alignment and the matcher falls back to an arbitrary
  one -- surfacing as a misleading "Expected source file list to match" rather
  than a checksum error. Roslyn takes the algorithm from how the generator adds
  the source: AddSource(name, string) uses the compilation's (Sha256 on the 5.x
  line) while AddSource(name, SourceText) keeps what the SourceText carries,
  and every generator here builds it with SourceText.From, whose API default is
  Sha1. LocalizationResources is the lone string-overload call, hence the odd
  one out.

Also: use Path.Combine for a diagnostic path that hardcoded '\', and refresh
the generated-file hashes embedded in diagnostic expectations.

Not fixed here, and not a Linux problem: 9 XamlCodeBehindGeneratorTests still
fail on line endings. XamlCodeBehindEmitter hardcodes "\r\n" for the `// Source`
line while the rest of its template inherits the newlines of its own source
file, which `* text=auto` makes LF in a Unix checkout. The generated code
therefore differs between a Windows and a Unix build of the same sources.
Making it deterministic touches the generator, and its source link also feeds
ms-appx:/// URIs, so it is left as a separate decision.
Last 9 failures of the suite on Linux, and the fixture stops depending on
which platform checked it out. 482 tests: 468 pass, 12 fail (all hot-reload
scenarios, tracked separately).

XamlCodeBehindEmitter.Emit built its output from a verbatim string literal, so
the newlines of the generated code-behind were those of the emitter's OWN
source file as checked out -- `* text=auto` yields LF on Unix and CRLF on
Windows -- and the interpolated source comment hardcoded CRLF on top of that.
The same sources therefore produced different generated code on different
hosts, and mixed endings within one file. Normalize the emitted text to LF so
the output is a function of its inputs only.

The test expectations had the mirror-image problem: they are raw string
literals in the test file, so they carried the checkout's newlines too. Route
them through a helper that normalizes to LF.

Also mark the snapshot fixtures `-text`. They are compared byte-for-byte
against generator output, so `* text=auto` was actively harmful: it stored them
with LF, so a checkout materialized LF on Unix while 17 of them are produced by
a generator shipped as a NuGet package -- which bakes the newlines of its own
sources at package build time and therefore emits CRLF on every host. Those
fixtures only ever matched on the platform whose checkout happened to restore
the original endings, and git hid the discrepancy: the working copy kept its
CRLF bytes while the blob held LF, and `git status` reported no change because
the clean filter normalized them back on comparison.
@github-actions github-actions Bot added the area/code-generation Categorizes an issue or PR as relevant to code generation label Aug 13, 2026
@github-actions

github-actions Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @dr1rrb's task in 5m 45s —— View job


Review Complete ✓

Verdict: ship — 1 style nit (inline), no correctness blockers.

  • Gather context and understand the PR
  • Review HotReloadWorkspaceProvider.cs (main logic changes)
  • Review XamlCodeBehindGeneratorTests.cs (test changes)
  • Review project file changes (Uno.UI.SourceGenerators.Tests.csproj)
  • Review snapshot fixture changes and .gitattributes
  • Check async/cancellation discipline
  • Check cross-platform correctness
  • Check code style and conventions
  • Post inline findings (1 nit)
  • Post summary

Summary

The PR correctly identifies and fixes three distinct root causes that had the hot-reload metadata suite either disabled or silently incomplete:

Root-cause fixes reviewed:

  • Roslyn 5.6 re-enable: Removing the local Roslyn version pin and importing Uno.DevServer.Roslyn.props instead is the right fix — a local pin is structurally incompatible with referencing Uno.HotReload (which owns the Roslyn line). The two 5.6 adjustments (RegisterWorkspaceFailedHandler for the obsoleted WorkspaceFailed event, Sha256 for SourceText.From) are both correct and properly guarded with #if NET10_0_OR_GREATER.
  • Linux path fix: Replacing C:\Project\<name>.csproj with a real host-native path (Path.Combine(_baseWorkFolder, ...)) is the right root-cause fix; the downstream Substring(_projectDirectory.Length + 1) mangling was a symptom, not the site to fix.
  • Linux PDB fix: Switching from Compilation.Emit(pdbPath:) to EmitCompilationOutputAsync (embedded PDB) avoids the native DiaSymReader dependency on Linux — and as a bonus aligns the test baseline with what HotReloadManager captures in production.
  • OOM fix: HotReloadWorkspace : IDisposable with Interlocked.Exchange for both _hotReloadService and _workspace is a correct, thread-safe disposal pattern. The using at the call site in Given_HotReloadService.cs properly triggers it per scenario.

Snapshot fixture portability (CSGenerator.cs):
The //Project/… UNC-style fake root is a clean host-independent substitute for C:\Project — PathUtilities.IsAbsolute accepts it on both platforms (UNC branch on Windows, leading / on Unix). Adding build_metadata.AdditionalFiles.Link to decouple the generator's source-link computation from Path.DirectorySeparatorChar is the right fix for the snapshot divergence. The SourceHashAlgorithm.Sha256 selection based on how each generator calls AddSource is subtle but correct.

.gitattributes (* -text): Correct — byte-for-byte fixture comparison breaks if text=auto normalizes line endings on checkout.

No issues found with:

  • Async/cancellation: no new .Result, async void, or CancellationToken.None introduced
  • Event patterns: no event Action / event Action<T>
  • Cross-platform correctness: host-path handling is now correct
  • Project file: taking Roslyn versions from Uno.DevServer.Roslyn.props is exactly right per the PR's own diagnosis

1 nit (inline, CSGenerator.cs lines 297-314): 18-line comment where the first paragraph duplicates the setup of the second; the second paragraph plus the LocalizationResources callout already carry all the non-obvious information. Suggestion to compress to ~10 lines is in the inline comment.

@unodevops

Copy link
Copy Markdown
Contributor

@dr1rrb
dr1rrb marked this pull request as ready for review August 14, 2026 15:08
Copilot AI lite review requested due to automatic review settings August 14, 2026 15:08
@dr1rrb
dr1rrb enabled auto-merge August 14, 2026 15:08
@github-actions

github-actions Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @dr1rrb's task in 4m 58s —— View job


Review Complete

  • Gather context and understand the PR
  • Review HotReloadWorkspaceProvider.cs (core changes)
  • Review XamlCodeBehindGeneratorTests.cs
  • Review project file changes
  • Review .gitattributes and snapshot fixture portability
  • Review CSGenerator.cs verifier changes
  • Check async/cancellation discipline
  • Check cross-platform correctness
  • Post inline findings
  • Post summary

Verdict: ship — no correctness blockers found. The previous Claude review posted 1 style nit inline (comment verbosity in CSGenerator.cs lines 297-314); no new issues beyond that.

Root-cause fixes: all correct

Roslyn 5.6 re-enable (Uno.UI.SourceGenerators.Tests.csproj): Removing the local PackageReference versions and importing from Uno.DevServer.Roslyn.props is precisely right — a local pin is structurally incompatible with ProjectReference-ing Uno.HotReload (which owns the Roslyn line). Both 5.6 adjustments are sound:

  • #if NET10_0_OR_GREATER … RegisterWorkspaceFailedHandler — correct; _ = discards the unsubscribe token without calling Dispose(), which keeps the handler registered for the workspace's lifetime (the workspace holds a strong reference to the handler). Same pattern as the dev-server host.
  • SourceHashAlgorithm.Sha256 in CSGenerator.cs for the LocalizationResources fixture — correct; TryGenerateUnoResourcesKeyAttribute calls AddSource(name, string) which takes the compilation's algorithm (Sha256 on Roslyn 5.x), while all other generators pass a SourceText and keep its Sha1.

Linux path fix (HotReloadWorkspaceProvider.cs line 280): Path.Combine(_baseWorkFolder, project.Name, $"{project.Name}.csproj") is the root-cause fix for the Substring(_projectDirectory.Length + 1) path mangling. The XAML section headers in the globalconfig use .Replace("\\", "/") — on Unix Path.Combine already uses / (no-op), on Windows it converts to forward slashes; both forms satisfy PathUtilities.IsAbsolute.

Linux PDB fix: Switching from Compilation.Emit(pdbPath:) (Windows PDB → needs DiaSymReader) to EmitCompilationOutputAsync (embedded PDB) removes the native-library dependency on Linux and aligns the test baseline with what HotReloadManager captures in production.

OOM fix (IDisposable + using): Interlocked.Exchange(ref _hotReloadService, null) / Interlocked.Exchange(ref _workspace, null) is a correct thread-safe disposal guard. EndSession() is only called if a session was started. _currentSolution = null is a non-interlocked write, but that's fine — the test harness is sequential under the using pattern and Solution is a reference type whose assignment is atomic on .NET.

Snapshot fixture portability (CSGenerator.cs, XamlCodeBehindGeneratorTests.cs): //Project as the fake project root is the right cross-platform substitute — UNC path on Windows (PathUtilities.IsAbsolute UNC branch), leading / on Unix. The Link metadata short-circuits the host-dependent Path.GetDirectoryName/Path.DirectorySeparatorChar math in GetSourceLink and XamlFileParser.GetTargetFilePath. The Expected() helper's Replace("\r\n", "\n") correctly normalises raw-literal line endings independent of checkout platform.

.gitattributes (* -text): Correct — byte-for-byte fixture comparison breaks if text=auto normalises endings on checkout.

Pre-existing issues (not introduced by this PR)

  • Task.Delay(100).Wait() (line 102): blocking I/O retry in UpdateSourceFile. Pre-existing; out of scope.
  • CancellationToken.None in Update() (line 434). Pre-existing; out of scope.

Style nit (already flagged inline)

The existing inline comment on CSGenerator.cs:314 from the prior review calls out that the 18-line block duplicates context in its first paragraph. Per code-style.md, comments should be "a line or two — never a wall of text". No new inline needed; the suggestion there stands.

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

This PR restores end-to-end Hot Reload (MetadataUpdate) coverage in Uno.UI.SourceGenerators.Tests after the Roslyn 5.6 migration, and makes the generator + snapshot harness host-independent so it can run on Linux. It also removes a cross-platform nondeterminism in generated code-behind line endings and regenerates snapshot baselines to match the new stable paths/metadata/checksums.

Changes:

  • Normalize XamlCodeBehindEmitter output to LF to make generated code-behind deterministic across hosts.
  • Update the source-generator test harness to use host-independent project roots/links and to align expected SourceText checksum algorithms with Roslyn 5.x behavior.
  • Re-enable the MetadataUpdate Hot Reload suite (restoring references and disposing per-scenario workspace state), and regenerate snapshot outputs accordingly.

Reviewed changes

Copilot reviewed 14 out of 226 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlCodeBehindEmitter.cs Normalizes generated code-behind newlines to LF for deterministic output across Windows/Linux.
src/SourceGenerators/Uno.UI.SourceGenerators.Tests/Uno.UI.SourceGenerators.Tests.csproj Switches Roslyn package versions to the shared Uno.DevServer.Roslyn.props matrix and restores the Uno.HotReload project reference to re-enable the HR test suite.
src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Verifiers/CSGenerator.cs Makes the snapshot harness host-independent (paths/link metadata) and aligns expected SourceText checksum algorithms with actual generated documents.
src/SourceGenerators/Uno.UI.SourceGenerators.Tests/MetadataUpdateTests/Given_HotReloadService.cs Ensures per-scenario Hot Reload workspace state is disposed to avoid leaked EnC sessions/memory growth.
src/SourceGenerators/Uno.UI.SourceGenerators.Tests/GeneratorTests/.cs Updates expected SourceText creation to use Sha256 where required by Roslyn 5.x document checksum comparisons.
src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/** Regenerated snapshot baselines to reflect stable, host-independent paths/URIs and updated UniqueID-derived filenames/hashes.
src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Out/.gitattributes Disables line-ending normalization for snapshot fixtures to keep byte-for-byte comparisons stable across checkouts.
Suppressed comments (1)

src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Verifiers/CSGenerator.cs:309

  • This block repeats the explanation from the preceding comment and makes the method harder to scan. Keeping a single concise rationale here would reduce noise while preserving the intent.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@unodevops

Copy link
Copy Markdown
Contributor

The synthetic project path this suite feeds the generator, `//Project/Project.csproj`,
is read by Windows as the UNC path `\\Project\Project.csproj` -- server `Project`,
share `Project.csproj`. The path IS its own root, so Path.GetDirectoryName returns
null and XamlCodeGeneration throws for an invalid MSBuildProjectFullPath. The
generator therefore died before emitting anything, on all 91 XAML tests: they
reported "Expected source file list to match" with three expected documents against
none produced, and two hit the harness's own "Unexpected test resource" guard.

The two leading separators have to stay. Roslyn accepts a global analyzer config
section name as absolute only if it starts with '/' on Unix, or is drive-rooted or
UNC on Windows, and `//x/y` is the only shape valid on both; a section name that is
not absolute is dropped silently, taking SourceItemGroup with it and leaving the
generator with no Page item. Give the project file a share above it instead.

The items then sit directly in the project directory, which removes a second
divergence: the `// Source ...` comments come from XamlFileGenerator._relativePath,
a computation Link does not reach and which ends in Path.DirectorySeparatorChar.
Relative to the folder it lives in, a flat item yields a name holding no separator
at all, so those comments can no longer differ between hosts. That is the whole
snapshot diff.

Line endings then have to follow the generator instead of being pinned to whichever
host produced the fixture. Uno's generators build their output with AppendLine, so
`* text=auto` tracks them exactly, and `-text` is kept only for the two families
whose newlines genuinely do not follow the host: the generator shipped as a NuGet
package, which baked its own sources' newlines at package build time and emits CRLF
everywhere, and the code-behind emitter, which is pinned to LF. Two hardcoded
"\r\n" in XamlFileGenerator go with it -- they were the one thing that made a Unix
build emit a file with mixed endings.

Last, the embedded sources provider emits a SHA-1 of the XAML source text, and a
hash cannot be converted back on checkout, so the inputs' newlines are pinned in
the harness.

232 of 232 XAML tests pass on Linux. The hot reload suite is unchanged at 236 of
250, with the same 12 failures tracked separately.
Copilot AI review requested due to automatic review settings August 17, 2026 17:39

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

Copilot reviewed 15 out of 227 changed files in this pull request and generated no new comments.

Suppressed comments (2)

src/SourceGenerators/Uno.UI.SourceGenerators.Tests/MetadataUpdates/HotReloadWorkspaceProvider.cs:209

  • The messages reference MSBuildWorkspace, but this code is using AdhocWorkspace. This is misleading when diagnosing failures. Update the log/exception text to reference the correct workspace type (or just “workspace”) so test failures are easier to understand.
				Console.WriteLine($"MSBuildWorkspace warning: {diagnostic}");

src/SourceGenerators/Uno.UI.SourceGenerators.Tests/MetadataUpdates/HotReloadWorkspaceProvider.cs:213

  • The messages reference MSBuildWorkspace, but this code is using AdhocWorkspace. This is misleading when diagnosing failures. Update the log/exception text to reference the correct workspace type (or just “workspace”) so test failures are easier to understand.
				taskCompletionSource.TrySetException(new InvalidOperationException($"Failed to create MSBuildWorkspace: {diagnostic}"));

@unodevops

Copy link
Copy Markdown
Contributor

dr1rrb added 2 commits August 17, 2026 14:11
Given_ImplicitXamlNamespaces.When_Ambiguous_Type_In_Global_Namespaces restated the
whole default global config in its GlobalConfigOverride, only to add one key. An
override entry SUPPRESSES the default of the same key, so the test stayed frozen on
a MSBuildProjectFullPath the harness had already moved away from: it was the single
remaining place feeding the generator a UNC share root, where Path.GetDirectoryName
returns null, and so the only XAML test still generating nothing at all on Windows.

Keep just the two keys that genuinely differ from the defaults. Its snapshot follows,
for the same reason as the rest of the suite: the item now sits directly in the
project directory, so the `// Source ...` comment holds no separator.
Re-enabling the suite left 12 cases red, which would keep the whole build red and so
hold up the re-enablement itself. Mark them ignored, following the mechanism the
harness already has for IsCrashingRoslyn -- a flag in Scenario.json and
Assert.Inconclusive -- rather than [Ignore], which MSTest only applies to a whole
method and would take all 250 data-driven cases with it.

An ignored case reads as a pass to everything looking at the run, so each one carries
the reason and where it is being addressed:

- the 8 When_Base_Type_* cases (4 scenarios x NetCore/MonoVM) report no diagnostic
  where ENC0014 is expected, because hot reload commits a rude edit as the EnC
  baseline on the Roslyn 5.x line. Fixed by #24085, which should drop these entries.

- the 4 When_Style_MarkupExtension_*Remove_Inc_Ext cases remove a file, which deletes
  a type; Roslyn 5.6 reports ENC0033 for it -- correctly, since Edit-and-Continue can
  delete members but not types -- while the expectations declare no diagnostic.
  Whether to record it or to stop treating a file removal as a rude edit is a product
  decision, so it is left open rather than quietly re-baselined.

The suite is now green: 482 tests, 468 pass, 14 ignored (these 12 plus the 2 already
known to crash Roslyn).
Copilot AI review requested due to automatic review settings August 18, 2026 13:41
@github-actions

github-actions Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @dr1rrb's task in 3m 35s —— View job


Review Complete

  • Gather context and understand the PR
  • Review HotReloadWorkspaceProvider.cs (core hot-reload changes)
  • Review CSGenerator.cs (snapshot harness portability)
  • Review XamlCodeBehindEmitter.cs (line-ending normalization)
  • Review project file and .gitattributes changes
  • Review Given_HotReloadService.cs (dispose discipline)
  • Check async/cancellation discipline
  • Check cross-platform correctness
  • Post inline findings
  • Post summary

Verdict: ship — 1 nit inline (stale log message text), no correctness blockers.

Root-cause fixes: all correct

Roslyn 5.6 re-enable (Uno.UI.SourceGenerators.Tests.csproj): Removing the local PackageReference versions and importing from Uno.DevServer.Roslyn.props is exactly right — a local pin is structurally incompatible with referencing Uno.HotReload, which owns the Roslyn line. Both 5.6 adjustments are sound:

  • #if NET10_0_OR_GREATER … RegisterWorkspaceFailedHandler — correct; _ = discards the unsubscribe token, keeping the handler registered for the workspace lifetime. Same pattern as the dev-server host.
  • SourceHashAlgorithm.Sha256 for LocalizationResources in CSGenerator.cs — correct; TryGenerateUnoResourcesKeyAttribute calls AddSource(name, string), which takes the compilation's algorithm (Sha256 on Roslyn 5.x), while all other generators pass a SourceText that carries Sha1.

Linux path fix (HotReloadWorkspaceProvider.cs line 280): Path.Combine(_baseWorkFolder, project.Name, $"{project.Name}.csproj") is the root-cause fix for the Substring(_projectDirectory.Length + 1) mangling; the .Replace("\\", "/") in the globalconfig section headers covers both platforms.

Linux PDB fix: Switching to EmitCompilationOutputAsync (embedded PDB) removes the native DiaSymReader dependency and aligns the test baseline with what HotReloadManager captures in production.

OOM fix (IDisposable + using): Interlocked.Exchange for _hotReloadService and _workspace is correct and thread-safe. _currentSolution = null without interlocking is safe under the sequential using pattern.

Snapshot fixture portability (CSGenerator.cs): //Project as the fake root is the right cross-platform substitute — UNC on Windows, leading / on Unix. build_metadata.AdditionalFiles.Link short-circuits host-dependent path math in GetSourceLink/XamlFileParser.GetTargetFilePath. Expected().Replace("\r\n", "\n") correctly normalizes raw-literal line endings in XamlCodeBehindGeneratorTests.cs.

.gitattributes (ObservablePropertyGenerator_*.g.cs -text, *.codebehind.g.cs -text): Correct and well-scoped — only the two generator families whose output doesn't follow the host newline get the -text override; the rest inherit * text=auto.

Line-ending normalization (XamlCodeBehindEmitter.cs): The trailing .Replace("\r\n", "\n") is the right fix — it makes the output a function of inputs only, decoupled from the emitter's own checkout platform.

12 remaining failures (6 scenarios × 2 configs): Correctly marked Ignore rather than silently re-baselined. The PR description explains these are Roslyn 5.6 regressions (ENC0014/ENC0033) not introduced here.

Pending from earlier review

The wall-of-text comment at CSGenerator.cs:335-352 (18 lines that duplicate each other) was flagged inline by the 2026-08-13 Claude review. That suggestion still stands; the comment was not condensed.

Pre-existing issues (not introduced by this PR)

  • Task.Delay(100).Wait() at line 102 in HotReloadWorkspaceProvider.cs — blocking I/O retry.
  • CancellationToken.None in Update() at line 434.

1 inline finding

Misleading "MSBuildWorkspace" label in the OnWorkspaceFailed handler (lines 209, 213) — the workspace is AdhocWorkspace. Suggestion posted inline.

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

Copilot reviewed 21 out of 233 changed files in this pull request and generated no new comments.

Suppressed comments (4)

src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlCodeBehindEmitter.cs:1

  • Normalizing with Replace("\r\n", "\n") won’t handle standalone '\r' line endings (rare, but possible when concatenating inputs from different sources). To make the normalization fully robust, consider also converting remaining '\r' to '\n' (eg, an additional Replace("\r", "\n")).
    src/SourceGenerators/Uno.UI.SourceGenerators.Tests/MetadataUpdates/HotReloadWorkspaceProvider.cs:209
  • These messages refer to MSBuildWorkspace, but this code is using AdhocWorkspace. Please update the log/exception text to match the actual workspace type (or use a generic 'workspace' wording) to avoid misleading diagnostics when failures occur.
				Console.WriteLine($"MSBuildWorkspace warning: {diagnostic}");

src/SourceGenerators/Uno.UI.SourceGenerators.Tests/MetadataUpdates/HotReloadWorkspaceProvider.cs:213

  • These messages refer to MSBuildWorkspace, but this code is using AdhocWorkspace. Please update the log/exception text to match the actual workspace type (or use a generic 'workspace' wording) to avoid misleading diagnostics when failures occur.
				taskCompletionSource.TrySetException(new InvalidOperationException($"Failed to create MSBuildWorkspace: {diagnostic}"));

src/SourceGenerators/Uno.UI.SourceGenerators.Tests/Uno.UI.SourceGenerators.Tests.csproj:21

  • This unconditional Import will hard-fail the build if the props file is missing (eg, partial source fetch/packaging scenarios). Consider guarding it with a condition (eg, Condition="Exists('..\..\Uno.DevServer.Roslyn.props')") and failing with a clearer error if it’s required.
	<Import Project="..\..\Uno.DevServer.Roslyn.props" />

@unodevops

Copy link
Copy Markdown
Contributor

@dr1rrb
dr1rrb merged commit b7bc4f8 into master Aug 22, 2026
68 checks passed
@dr1rrb
dr1rrb deleted the dev/dr/hr-metadata-tests-linux branch August 22, 2026 23:18
@dr1rrb dr1rrb mentioned this pull request Oct 14, 2026
2 of 5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/code-generation Categorizes an issue or PR as relevant to code generation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Re-enable the hot-reload MetadataUpdate test suite (Roslyn 5.x migration + snapshot regeneration)

4 participants