diff --git a/CosmosDBShell.Tests/CommandTests/ConnectCommandTests.cs b/CosmosDBShell.Tests/CommandTests/ConnectCommandTests.cs index 80c0352..db40cef 100644 --- a/CosmosDBShell.Tests/CommandTests/ConnectCommandTests.cs +++ b/CosmosDBShell.Tests/CommandTests/ConnectCommandTests.cs @@ -4,7 +4,10 @@ namespace CosmosShell.Tests.CommandTests; +using Azure.Data.Cosmos.Shell.Commands; using Azure.Data.Cosmos.Shell.Core; +using Azure.Data.Cosmos.Shell.Lsp.Semantics; +using Azure.Data.Cosmos.Shell.Parser; using Microsoft.Azure.Cosmos; public class ConnectCommandTests @@ -21,4 +24,58 @@ await Assert.ThrowsAnyAsync(() => shell.ConnectAsync mode: ConnectionMode.Gateway, token: cancellationTokenSource.Token)); } + + [Fact] + public async Task ConnectCommand_VSCodeCredentialOption_BindsHiddenInteractiveFlag() + { + var command = await BindConnectCommandAsync("connect https://example.documents.azure.com:443/ -vscode-credential"); + + Assert.Equal("https://example.documents.azure.com:443/", command.ConnectionString); + Assert.True(command.UseVSCodeCredential); + } + + [Fact] + public async Task ConnectCommand_StartupVSCodeCredentialOptionAlias_BindsHiddenInteractiveFlag() + { + var command = await BindConnectCommandAsync("connect https://example.documents.azure.com:443/ --connect-vscode-credential"); + + Assert.Equal("https://example.documents.azure.com:443/", command.ConnectionString); + Assert.True(command.UseVSCodeCredential); + } + + [Fact] + public void ConnectCommand_VSCodeCredentialOption_IsHiddenButKnownToCommandMetadata() + { + Assert.True(CommandFactory.TryCreateFactory(typeof(ConnectCommand), out var factory)); + + Assert.DoesNotContain(factory.Options, option => option.MatchesArgument("vscode-credential")); + Assert.Contains(factory.AllOptions, option => option.MatchesArgument("vscode-credential")); + Assert.True(factory.HasOption("vscode-credential")); + + using var shell = ShellInterpreter.CreateInstance(); + Assert.True(shell.App.IsOptionPrefix("connect", "vscode-credential")); + } + + [Fact] + public void ConnectCommand_VSCodeCredentialOption_DoesNotProduceUnknownOptionDiagnostic() + { + const string CommandText = "connect https://example.documents.azure.com:443/ -vscode-credential"; + var parser = new StatementParser(CommandText); + var statements = parser.ParseStatements(); + + var model = new SemanticAnalyzer().Analyze(statements, CommandText); + + Assert.DoesNotContain(model.Diagnostics, diagnostic => diagnostic.Code == "SEM002"); + } + + private static async Task BindConnectCommandAsync(string commandText) + { + var parser = new StatementParser(commandText); + var statement = Assert.IsType(Assert.Single(parser.ParseStatements())); + + Assert.True(CommandFactory.TryCreateFactory(typeof(ConnectCommand), out var factory)); + using var shell = ShellInterpreter.CreateInstance(); + var command = await statement.CreateCommandAsync(factory, shell, new CommandState(), CancellationToken.None); + return Assert.IsType(command); + } } diff --git a/CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/CommandFactory.cs b/CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/CommandFactory.cs index 7f9587c..94c17a7 100644 --- a/CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/CommandFactory.cs +++ b/CosmosDBShell/Azure.Data.Cosmos.Shell.Commands/CommandFactory.cs @@ -54,6 +54,11 @@ public McpAnnotationAttribute? McpAnnotation /// public List