-
Notifications
You must be signed in to change notification settings - Fork 5
Add Abstraction Layer for Server Start #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
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 introduces an abstraction layer for server startup functionality to improve testability. The IServerService interface allows test cases to mock the StartAsync() method, eliminating the need for static calls to Server.Start() in test scenarios.
Key Changes
- Created
IServerServiceinterface andServerServiceimplementation to wrap server startup logic - Registered
ServerServicein the dependency injection container - Updated
MockToolingServerSubcommandand related commands to accept and useIServerServiceinstead of callingServer.Start()directly - Updated all test files to mock
IServerServicefor better test isolation
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/Microsoft.Agents.A365.DevTools.Cli/Services/IServerService.cs |
New interface defining server startup contract |
src/Microsoft.Agents.A365.DevTools.Cli/Services/ServerService.cs |
Implementation that wraps Server.Start() call |
src/Microsoft.Agents.A365.DevTools.Cli/Program.cs |
Registers IServerService in DI container and passes it to commands |
src/Microsoft.Agents.A365.DevTools.Cli/Commands/DevelopCommand.cs |
Updated to accept and pass IServerService to subcommands |
src/Microsoft.Agents.A365.DevTools.Cli/Commands/DevelopSubcommands/MockToolingServerSubcommand.cs |
Refactored to use injected IServerService instead of static Server.Start() call |
src/Tests/Microsoft.Agents.A365.DevTools.Cli.Tests/Commands/MockToolingServerSubcommandTests.cs |
Updated to mock IServerService for all test cases |
src/Tests/Microsoft.Agents.A365.DevTools.Cli.Tests/Commands/DevelopCommandTests.cs |
Updated to pass mock IServerService to command creation methods |
src/Microsoft.Agents.A365.DevTools.Cli/Services/MockToolingServerService.cs
Show resolved
Hide resolved
src/Microsoft.Agents.A365.DevTools.Cli/Services/ServerService.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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 7 out of 7 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
src/Tests/Microsoft.Agents.A365.DevTools.Cli.Tests/Commands/MockToolingServerSubcommandTests.cs:276
- The tests verify that the server service mock is configured to return Task.CompletedTask, but there's no verification that StartAsync is actually called when running in foreground mode (background=false). Consider adding assertions to verify that the server service's StartAsync method is invoked with the expected arguments in foreground scenarios, similar to how ProcessService.StartInNewTerminal is verified for background mode.
public async Task HandleStartServer_WithNullPort_UsesDefaultPort()
{
// Act - Default behavior is foreground (background=false)
await MockToolingServerSubcommand.HandleStartServer(null, false, false, false, _testLogger, _mockProcessService, _mockServerService);
// Assert - Should log foreground startup messages with default port
Assert.NotEmpty(_testLogger.LogCalls);
Assert.Contains(_testLogger.LogCalls, call =>
call.Level == LogLevel.Information &&
call.Message.Contains("Starting Up MockToolingServer."));
Assert.Contains(_testLogger.LogCalls, call =>
call.Level == LogLevel.Information &&
call.Message.Contains("Press Ctrl+C to stop the server."));
}
src/Tests/Microsoft.Agents.A365.DevTools.Cli.Tests/Commands/MockToolingServerSubcommandTests.cs:297
- The tests verify that the server service mock is configured to return Task.CompletedTask, but there's no verification that StartAsync is actually called when running in foreground mode (background=false). Consider adding assertions to verify that the server service's StartAsync method is invoked with the expected arguments in foreground scenarios, similar to how ProcessService.StartInNewTerminal is verified for background mode.
public async Task HandleStartServer_WithValidPort_LogsStartingMessage(int validPort)
{
// Act - Default behavior is foreground (background=false)
await MockToolingServerSubcommand.HandleStartServer(validPort, false, false, false, _testLogger, _mockProcessService, _mockServerService);
// Assert - Should log foreground startup messages
Assert.NotEmpty(_testLogger.LogCalls);
Assert.Contains(_testLogger.LogCalls, call =>
call.Level == LogLevel.Information &&
call.Message.Contains("Starting Up MockToolingServer."));
Assert.Contains(_testLogger.LogCalls, call =>
call.Level == LogLevel.Information &&
call.Message.Contains("Press Ctrl+C to stop the server."));
}
There was a problem hiding this comment.
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 7 out of 7 changed files in this pull request and generated 3 comments.
Some mts tests are starting up the server, this abstraction layer with
IServerServiceallows test cases to mock theStartAsync()method and avoid the static call forServer.Start()