Conversation
Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds an initial xUnit-based test suite to the ExtensionTest project to cover core behaviors of GeneralUpdate.Extension (catalog, compatibility/platform checks, dependency resolution, host wiring, and download queue behavior).
Changes:
- Added unit tests for
VersionCompatibilityChecker,PlatformMatcher,DependencyResolver, andExtensionCatalog. - Added
GeneralExtensionHostconstructor/option validation and a couple of install-path failure-path tests. - Added
DownloadQueueManagerqueue/event/concurrency/disposal tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/c#/ExtensionTest/VersionCompatibilityCheckerTests.cs | Tests version parsing and min/max host version compatibility + latest compatible selection |
| src/c#/ExtensionTest/PlatformMatcherTests.cs | Tests OS platform detection and platform flag matching |
| src/c#/ExtensionTest/GeneralExtensionHostTests.cs | Tests ctor validation, directory creation, compatibility delegation, and basic install failure paths |
| src/c#/ExtensionTest/ExtensionCatalogTests.cs | Tests manifest load, platform filtering, add/update/remove behaviors |
| src/c#/ExtensionTest/DownloadQueueManagerTests.cs | Tests enqueue/get/cancel/events, concurrent processing, and disposal behavior |
| src/c#/ExtensionTest/DependencyResolverTests.cs | Tests dependency chain resolution, cycles, whitespace, and missing dependency detection |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public void IsCurrentPlatformSupported_ShouldReturnTrue_WhenAllPlatformsSupported() | ||
| { | ||
| // Arrange | ||
| var extension = new ExtensionMetadata | ||
| { | ||
| Id = "ext1", | ||
| SupportedPlatforms = TargetPlatform.All | ||
| }; | ||
|
|
||
| // Act | ||
| var result = _matcher.IsCurrentPlatformSupported(extension); | ||
|
|
||
| // Assert | ||
| Assert.True(result); |
There was a problem hiding this comment.
This test assumes the current runtime platform is always one of the platforms included in TargetPlatform.All. On platforms where GetCurrentPlatform() returns None, IsCurrentPlatformSupported will return false and this test will fail. Either guard/skip when current platform is None, or update the expectation to match the implementation.
| // Act | ||
| _manager.Enqueue(task); | ||
|
|
||
| // Wait for processing (with timeout) | ||
| await Task.Delay(300); | ||
|
|
||
| // Assert | ||
| Assert.Contains(ExtensionUpdateStatus.Queued, statusChanges); | ||
| Assert.Contains(ExtensionUpdateStatus.Updating, statusChanges); | ||
| Assert.Contains(ExtensionUpdateStatus.UpdateSuccessful, statusChanges); | ||
| } |
There was a problem hiding this comment.
These assertions rely on a fixed Task.Delay(300) to wait for background processing. This can be flaky under CI load (timing variance) and can also hide deadlocks. Prefer waiting on a TaskCompletionSource/event signal (with a generous timeout) or polling until the expected terminal status is observed.
| // Act - Enqueue multiple tasks | ||
| for (int i = 1; i <= 5; i++) | ||
| { | ||
| var ext = CreateTestExtension($"ext{i}"); | ||
| var task = new DownloadTask { Extension = ext }; | ||
| _manager.Enqueue(task); | ||
| } | ||
|
|
||
| // Wait for all to complete (with timeout) | ||
| await Task.Delay(1000); | ||
|
|
||
| // Assert | ||
| Assert.Equal(5, completedTasks); | ||
| } |
There was a problem hiding this comment.
This test assumes all 5 tasks will reach UpdateSuccessful within a fixed 1000ms window. That can intermittently fail on slower machines or when the test runner is heavily loaded. Consider waiting until completedTasks == 5 (or a timeout) rather than using a fixed delay.
| [Fact] | ||
| public void ResolveDependencies_ShouldReturnEmpty_WhenNoDependencies() | ||
| { | ||
| // Arrange |
There was a problem hiding this comment.
Test name says "ShouldReturnEmpty" but the assertions expect a single-item list containing the extension itself. Renaming to reflect the actual expected behavior (e.g., returning the extension ID when there are no dependencies) will make failures easier to interpret.
| [Fact] | ||
| public void ResolveDependencies_ShouldReturnEmpty_WhenDependenciesEmpty() | ||
| { | ||
| // Arrange | ||
| var catalogMock = new Mock<IExtensionCatalog>(); |
There was a problem hiding this comment.
Test name says "ShouldReturnEmpty" but the assertions expect the resolver to return the extension itself (single-item list). Consider renaming to match the expected result for an empty dependency string.
| else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
| { | ||
| Assert.Equal(TargetPlatform.MacOS, platform); | ||
| } |
There was a problem hiding this comment.
If the runtime is on an unsupported platform (none of the OSPlatform checks match), this test performs no assertion and will pass vacuously. Adding a final else assertion (e.g., expecting TargetPlatform.None) would make the intent explicit and keep the test meaningful on all runners.
| } | |
| } | |
| else | |
| { | |
| Assert.Equal(TargetPlatform.None, platform); | |
| } |
| Assert.NotEqual(TargetPlatform.None, platform); | ||
| Assert.True( | ||
| platform == TargetPlatform.Windows || | ||
| platform == TargetPlatform.Linux || | ||
| platform == TargetPlatform.MacOS | ||
| ); |
There was a problem hiding this comment.
These assertions will fail on any OS where PlatformMatcher.GetCurrentPlatform() legitimately returns TargetPlatform.None (e.g., FreeBSD/other Unix-like platforms). Consider asserting equivalence to RuntimeInformation (including an else branch asserting None), or skip the test when the current platform is not Windows/Linux/macOS.
| Assert.NotEqual(TargetPlatform.None, platform); | |
| Assert.True( | |
| platform == TargetPlatform.Windows || | |
| platform == TargetPlatform.Linux || | |
| platform == TargetPlatform.MacOS | |
| ); | |
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || | |
| RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || | |
| RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | |
| { | |
| Assert.NotEqual(TargetPlatform.None, platform); | |
| Assert.True( | |
| platform == TargetPlatform.Windows || | |
| platform == TargetPlatform.Linux || | |
| platform == TargetPlatform.MacOS | |
| ); | |
| } | |
| else | |
| { | |
| Assert.Equal(TargetPlatform.None, platform); | |
| } |
The ExtensionTest project existed but contained no test implementations. This adds full test coverage for the extension system's core functionality.
Test Coverage (96 tests)
Implementation Notes
Tests use xUnit with Moq for dependency isolation. All tests follow AAA pattern with proper cleanup via IDisposable. Async tests handle timing appropriately for queue processing verification.
Example test structure:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.