Skip to content

Add comprehensive test suite for GeneralUpdate.Extension core components#137

Merged
JusterZhu merged 3 commits intomasterfrom
copilot/develop-test-cases-generalupdate-extension
Feb 8, 2026
Merged

Add comprehensive test suite for GeneralUpdate.Extension core components#137
JusterZhu merged 3 commits intomasterfrom
copilot/develop-test-cases-generalupdate-extension

Conversation

Copy link
Contributor

Copilot AI commented Feb 8, 2026

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)

  • ExtensionCatalog (14): Manifest loading, platform filtering, CRUD operations
  • VersionCompatibilityChecker (18): Version range validation, min/max constraints, latest version selection
  • PlatformMatcher (13): OS detection (Windows/Linux/MacOS), platform flags, multi-platform support
  • DependencyResolver (14): Dependency chains, circular detection, missing dependency identification
  • GeneralExtensionHost (20): Constructor validation, DI, auto-update config, installation workflow
  • DownloadQueueManager (17): Queue management, concurrent downloads, cancellation, disposal

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:

[Fact]
public void ResolveDependencies_ShouldThrow_WhenCircularDependency()
{
    // Arrange: dep1 → dep2 → dep1
    var dep1 = new ExtensionMetadata { Id = "dep1", Dependencies = "dep2" };
    var dep2 = new ExtensionMetadata { Id = "dep2", Dependencies = "dep1" };
    catalogMock.Setup(c => c.GetInstalledExtensionById("dep1")).Returns(dep1);
    catalogMock.Setup(c => c.GetInstalledExtensionById("dep2")).Returns(dep2);

    // Act & Assert
    Assert.Throws<InvalidOperationException>(() => resolver.ResolveDependencies(dep1));
}
Original prompt

This section details on the original issue you should resolve

<issue_title>GeneralUpdate.Extension Test Case Development</issue_title>
<issue_description>Please develop test cases based on the core functions within GeneralUpdate.Extension.</issue_description>

<agent_instructions>充分理解issue、代码上下文。</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 8, 2026 07:28
Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
Copilot AI changed the title [WIP] Develop test cases for GeneralUpdate.Extension core functions Add comprehensive test suite for GeneralUpdate.Extension core components Feb 8, 2026
Copilot AI requested a review from JusterZhu February 8, 2026 07:31
@JusterZhu JusterZhu marked this pull request as ready for review February 8, 2026 07:39
Copilot AI review requested due to automatic review settings February 8, 2026 07:39
@JusterZhu JusterZhu merged commit f1f8bf9 into master Feb 8, 2026
2 checks passed
@JusterZhu JusterZhu deleted the copilot/develop-test-cases-generalupdate-extension branch February 8, 2026 07:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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, and ExtensionCatalog.
  • Added GeneralExtensionHost constructor/option validation and a couple of install-path failure-path tests.
  • Added DownloadQueueManager queue/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.

Comment on lines +54 to +67
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);
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +203 to +213
// 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);
}
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +256 to +269
// 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);
}
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +13
[Fact]
public void ResolveDependencies_ShouldReturnEmpty_WhenNoDependencies()
{
// Arrange
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +33 to +37
[Fact]
public void ResolveDependencies_ShouldReturnEmpty_WhenDependenciesEmpty()
{
// Arrange
var catalogMock = new Mock<IExtensionCatalog>();
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Assert.Equal(TargetPlatform.MacOS, platform);
}
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
}
}
else
{
Assert.Equal(TargetPlatform.None, platform);
}

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +29
Assert.NotEqual(TargetPlatform.None, platform);
Assert.True(
platform == TargetPlatform.Windows ||
platform == TargetPlatform.Linux ||
platform == TargetPlatform.MacOS
);
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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);
}

Copilot uses AI. Check for mistakes.
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.

GeneralUpdate.Extension Test Case Development

2 participants