Skip to content

Preserve output of every statement in multi-statement input - #286

Merged
Mike Krüger (mkrueger) merged 5 commits into
mainfrom
dev/mkrueger/fix/277-statement-output
Nov 5, 2026
Merged

Mike Krüger (mkrueger) merged 5 commits into
mainfrom
dev/mkrueger/fix/277-statement-output

Conversation

@mkrueger

Copy link
Copy Markdown
Collaborator

Fixes #277.

Problem

Multi-statement -c/-k commands and piped stdin only rendered the final statement's result, so earlier output and file redirections were silently dropped (including output before a later runtime failure). Redirecting a whole script with script.csh > file kept only the last result because every rendered statement reopened the file in overwrite mode.

Changes

  • ShellInterpreter.RunCommandAsync gains an opt-in renderOutput mode used by the top-level ExecuteCommandCoreAsync path. Each successful statement is rendered in order, and redirections are restored between statements so they stay scoped to their own statement. Internal callers keep the existing final-result-only behavior.
  • Rendering is skipped once the operation is cancelled, so interactive Ctrl+C still does not show or redirect partial results; existing cancellation and timeout handling decides what to report.
  • CommandStatement.RunScriptAsync: an explicit > on a script invocation truncates the destination once (after successful parse) and appends every statement's output; >> never truncates. Unwritable destinations return an error state instead of throwing.
  • Docs (docs/programming.md) and changelog updated.

Behavior notes

  • Parse errors still prevent the entire input from running.
  • script.csh > file now creates/empties file even when the script produces no output, matching usual > semantics.
  • Not changed: an inner echo x > other inside a script invoked with an outer > is still written to the outer destination (pre-existing behavior, out of scope).

Validation

  • Process-level tests for inline/stdin ordering, per-statement >/>>/2> scoping, earlier output before runtime failure, parse-failure no-op, pipelines/expressions not duplicated, and whole-script >/>> with blocks, functions and return.
  • Interactive cancellation regression test (fails without the guard).
  • dotnet build app + tests; offline suite: 5,095 passed, 6 skipped.
Multi-statement -c/-k commands and piped stdin now render each statement's result and honor its redirections in order, like separately typed statements. Whole-script '>' redirection truncates once and keeps all script output.

Fixes #277

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Output redirection to a missing directory suppresses the I/O error diagnostic, leaving a nonzero exit without console or machine-readable error output, even when stderr is redirected.

1 open issue
What changed in this PR

Fixes #277 by preserving intermediate output and file redirections in multi-statement shell input, aligning inline and piped execution with script-file behavior.

Changes:

  • Render successful top-level statements in order, scope redirections per statement, and suppress cancelled partial results.
  • Truncate whole-script > destinations once, then append subsequent statement output.
  • Add regression tests and document output ordering and redirection semantics.
File Description
docs/​programming.md Documents multi-statement output and whole-script redirection.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Parser/​Statement/​CommandStatement.cs Preserves successive results when redirecting an entire script.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Core/​ShellInterpreter.cs Adds per-statement rendering and redirection restoration.
CosmosDBShell.Tests/​UtilTest/​StartupOptionTests.cs Tests suppression of partial results after interactive cancellation.
CosmosDBShell.Tests/​Integration/​ShellProcessTests.cs Tests output ordering, redirection scoping, failures, and script output.
CHANGELOG.md Records the user-visible output preservation fix.

Review effort: Balanced

@github-code-quality

github-code-quality Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage/dotnet

main 819d404 dev/mkrueger/fix/277... 58910e9 +/-
74% 74% 0%
View coverage of the 3 most impacted files.
File main 819d404 dev/mkrueger/fix/277... 58910e9 +/-
D:\a\CosmosDBSh...lInterpreter.cs 80% 80% 0%
D:\a\CosmosDBSh...andStatement.cs 89% 90% +1%
D:\a\CosmosDBSh...QueryCommand.cs 51% 52% +1%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 05, 2026 11:12 UTC

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 5, 2026 09:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Redirection failures return an error state without reporting the exception, leaving stderr or redirected error output empty and omitting the structured error envelope in machine mode.

1 open issue

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Empty script invocations can duplicate prior output or write stale results to redirected files, and eager truncation causes an existing regression test to fail with an uncaught exception.

2 open issues
1 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Shared output-state changes have subtle side effects on auxiliary-file overwrite behavior and empty-function result rendering that require human assessment.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

…286

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the multi-statement output and redirection changes.

No open issues 🎉

Review effort: Balanced

@mkrueger
Mike Krüger (mkrueger) merged commit f6b1dd6 into main Nov 5, 2026
13 checks passed
@mkrueger
Mike Krüger (mkrueger) deleted the dev/mkrueger/fix/277-statement-output branch November 5, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants