From 7e4f075f2d153a58ca946b1286902a5e5fd284cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Mon, 26 Oct 2026 16:34:32 +0100 Subject: [PATCH 1/2] Pin console width in import dry-run output test The interactive JSON renderer wraps at the console width, so on narrow build agents the long temp-file path was split inside a JSON string and the test failed to parse the output. --- CosmosDBShell.Tests/CommandTests/ImportCommandTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/CosmosDBShell.Tests/CommandTests/ImportCommandTests.cs b/CosmosDBShell.Tests/CommandTests/ImportCommandTests.cs index 09b6d826..5ee24945 100644 --- a/CosmosDBShell.Tests/CommandTests/ImportCommandTests.cs +++ b/CosmosDBShell.Tests/CommandTests/ImportCommandTests.cs @@ -41,6 +41,7 @@ public async Task ExecuteAsync_DryRun_UsesSelectedOutputFormat(string? format) ColorSystem = ColorSystemSupport.NoColors, Out = new AnsiConsoleOutput(output), }); + AnsiConsole.Console.Profile.Width = 200; var command = new ImportCommand { File = file, DryRun = true, Format = format }; var state = await command.ExecuteAsync(shell, new CommandState(), string.Empty, TestContext.Current.CancellationToken); From 1b585d4d6fb0eb3c6a17c325de24557722ea0b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Mon, 26 Oct 2026 16:54:06 +0100 Subject: [PATCH 2/2] Keep long terminal JSON output valid --- .../CommandTests/ImportCommandTests.cs | 34 +++++++++++++++++++ .../ShellInterpreter.cs | 27 ++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/CosmosDBShell.Tests/CommandTests/ImportCommandTests.cs b/CosmosDBShell.Tests/CommandTests/ImportCommandTests.cs index 5ee24945..08e8a47f 100644 --- a/CosmosDBShell.Tests/CommandTests/ImportCommandTests.cs +++ b/CosmosDBShell.Tests/CommandTests/ImportCommandTests.cs @@ -93,6 +93,40 @@ public async Task ExecuteAsync_DryRun_UsesSelectedOutputFormat(string? format) } } + [Fact] + public void PrintState_JsonWithLongLine_DoesNotWrapJsonString() + { + var originalOut = Console.Out; + var originalConsole = AnsiConsole.Console; + using var output = new StringWriter(); + using var shell = ShellInterpreter.CreateInstance(); + try + { + Console.SetOut(output); + AnsiConsole.Console = AnsiConsole.Create(new AnsiConsoleSettings + { + Ansi = AnsiSupport.No, + ColorSystem = ColorSystemSupport.NoColors, + Out = new AnsiConsoleOutput(output), + }); + AnsiConsole.Console.Profile.Width = 40; + + var value = new string('x', 100); + var state = new CommandState { Result = new ShellJson(JsonSerializer.SerializeToElement(new { value })) }; + state.SetFormat("json"); + + shell.PrintState(state); + + using var document = JsonDocument.Parse(output.ToString()); + Assert.Equal(value, document.RootElement.GetProperty("value").GetString()); + } + finally + { + Console.SetOut(originalOut); + AnsiConsole.Console = originalConsole; + } + } + [Theory] [InlineData("items.json", (int)ImportFormat.Json)] [InlineData("items.jsonl", (int)ImportFormat.Json)] diff --git a/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ShellInterpreter.cs b/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ShellInterpreter.cs index 4c6f47ab..b6c9257c 100644 --- a/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ShellInterpreter.cs +++ b/CosmosDBShell/Azure.Data.Cosmos.Shell.Core/ShellInterpreter.cs @@ -2104,7 +2104,32 @@ private CommandState PrintStateCore(CommandState state, bool markAsRendered) var element = (JsonElement?)state.Result.ConvertShellObject(Parser.DataType.Json); if (element.HasValue) { - AnsiConsole.MarkupLine(JsonOutputHighlighter.BuildMarkup(element.Value)); + var jsonText = state.GenerateOutputText(); + var lineStart = 0; + var hasLongLine = false; + for (var index = 0; index < jsonText.Length; index++) + { + if (jsonText[index] == '\n') + { + if (index - lineStart >= AnsiConsole.Console.Profile.Width) + { + hasLongLine = true; + break; + } + + lineStart = index + 1; + } + } + + if (hasLongLine || jsonText.Length - lineStart >= AnsiConsole.Console.Profile.Width) + { + Console.Out.WriteLine(jsonText); + } + else + { + AnsiConsole.MarkupLine(JsonOutputHighlighter.BuildMarkup(element.Value)); + } + return state; } }