Skip to content

Add agent output mode for AI coding agents - #1554

Merged
OsirisTerje merged 5 commits into
mainfrom
feature/issue1515-agent-output
Nov 30, 2026
Merged

OsirisTerje merged 5 commits into
mainfrom
feature/issue1515-agent-output

Conversation

@OsirisTerje

Copy link
Copy Markdown
Member

Fixes #1515.

Adds AgentMode (Off | Auto | On, default Auto). Auto turns agent mode on when an AI coding agent is detected from its environment variables. Agent mode only sets defaults; an explicit setting always wins, so the new settings can also be used without agent mode.

Setting Off (6.3 behaviour) On
ShowStdout/ShowStderr All (None if ConsoleOut=0) Failed
StackTrace Full Filtered
Verbosity 0 -1

Failed keeps the output only in the test result, where the VSTest console logger shows it for failed tests. Reasons follow ShowStdout, so in agent mode only reasons of failed tests are sent. Filtered removes NUnit-internal and async state-machine frames. The output decisions are moved into TestOutputPolicy, used by the listener and both converters.

Also fixes: with ShowStderr=Failed, stderr was missing from the test result.

Measured on a repro with 26 tests: console output shrinks by 56 % at minimal verbosity and 63 % at normal. build -t test and build -t acceptance pass locally.

Docs: nunit/docs#1321. Result file: #1552.

🤖 Made by @OsirisTerje with Claude

AgentMode (Off | Auto | On) sets output defaults. Auto detects an AI agent
from environment variables. Explicit settings always win.

- ShowStdout/ShowStderr (All | Failed | None): Failed keeps output only in
  the test result, which the VSTest console logger shows for failed tests.
- StackTrace (Full | Filtered | None): Filtered removes NUnit-internal and
  async state-machine frames.
- Reasons are sent only for failed tests when ShowStdout is Failed.
- TestOutputPolicy centralizes the output decisions for the listener and
  both converters.
- Off keeps the 6.3 behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 07:06

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

Unsupported string.Contains overloads prevent net462 compilation, while output-policy defects leak suppressed stdout, discard progress diagnostics, and override explicit output settings.

4 open issues
What changed in this PR

Adds agent-oriented output defaults to the NUnit VS Adapter to reduce console noise for AI coding tools. This addresses the console-output portion of #1515; result-file support remains separate in #1552.

Changes:

  • Adds automatic agent detection and configurable output, stack-trace, and verbosity defaults.
  • Centralizes output decisions in TestOutputPolicy, shared by the listener and both converters.
  • Documents the settings and adds tests for presets, overrides, and output handling.
File Description
src/​NUnitTestAdapterTests/​TestOutputPolicyTests.cs Tests output policies and stack-trace settings.
src/​NUnitTestAdapterTests/​TestDiscoveryTests.cs Makes discovery-test verbosity explicit.
src/​NUnitTestAdapterTests/​NUnitEventListenerTests.cs Updates mocked output settings.
src/​NUnitTestAdapterTests/​NUnitEventListenerOutputTests.cs Tests agent-mode buffering and console suppression.
src/​NUnitTestAdapterTests/​Fakes/​FakeRunSettings.cs Disables agent detection in shared test settings.
src/​NUnitTestAdapterTests/​AdapterSettingsTests.cs Tests presets and explicit overrides.
src/​NUnitTestAdapter/​TestResultSet.cs Extracts the shared result container.
src/​NUnitTestAdapter/​TestOutputPolicy.cs Centralizes output and stack-trace decisions.
src/​NUnitTestAdapter/​TestConverterForXml.cs Applies policy-based stack traces and changes reason handling.
src/​NUnitTestAdapter/​TestConverter.cs Applies policy-based stack traces and changes reason handling.
src/​NUnitTestAdapter/​StackTraceFilter.cs Adds stack-frame filtering.
src/​NUnitTestAdapter/​NUnitEventListener.cs Applies output policy to event handling.
src/​NUnitTestAdapter/​LLMEnvironmentDetector.cs Detects agent environment variables.
src/​NUnitTestAdapter/​IAdapterSettings.cs Exposes the new settings.
src/​NUnitTestAdapter/​AdapterSettings.cs Resolves agent presets and output overrides.
README.md Documents agent output and command-line usage.

Review effort: Balanced

Comment thread src/NUnitTestAdapter/TestConverter.cs Resolved
OsirisTerje and others added 2 commits November 24, 2026 21:57
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Progress output only goes live to the console, so ShowStdout=Failed lost it.
Keep it in the test result for Failed, apply the reason gate to the XML
converter as well, and document that None keeps NUnit's own result output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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

Unresolved issues suppress failing-fixture diagnostics, remove legitimate MoveNext throw locations, and miss Codex environments that should receive agent defaults.

1 open issue
3 previously missed issues

In code that hasn't changed since last review

Medium severity Recognize Codex environment variables in agent-mode detection

src/​NUnitTestAdapter/​LLMEnvironmentDetector.cs:18

Issue #1515 requests detection using the same environment variables as MTP, but a Codex environment exposing only CODEX_SANDBOX, CODEX_CI or CODEX_THREAD_ID resolves Auto to Off here. MTP's detector on its current default branch at d54b8f1 recognizes all three alongside CODEX_CLI. Add these aliases so those Codex sessions receive the advertised agent defaults without explicitly setting AgentMode=On.

Medium severity Suite setup and teardown output is never flushed for failed suites

src/​NUnitTestAdapter/​NUnitEventListener.cs:270

With ShowStderr=Failed or ShowStdout=Failed, stderr/progress output from OneTimeSetUp or OneTimeTearDown is suppressed and buffered under the suite ID (NUnit's current-test output tagging, default branch). Only TestFinished consumes these buffers, so a failing fixture's diagnostics never reach the console or recorded results. Consume and clear suite-owned buffers in SuiteFinished, reporting suppressed output when the suite fails or attaching it to affected results.

Medium severity Preserve handwritten MoveNext frames in stack traces

src/​NUnitTestAdapter/​StackTraceFilter.cs:23

This removes every method named MoveNext, including handwritten enumerators such as at App.CustomEnumerator.MoveNext() in CustomEnumerator.cs:line 42. A failure in that method therefore loses its actual throw location under the agent preset. Require a compiler-generated state-machine type marker before removing a MoveNext frame so ordinary enumerator methods remain visible.

3 resolved since last review

Review effort: Balanced

OsirisTerje and others added 2 commits November 24, 2026 22:59
- Detect agents with the environment variables MTP uses, including the Codex
  aliases. The list comes from Microsoft.Testing.Platform (MIT); attribution
  is in the new THIRD_PARTY_NOTICES.md.
- Send buffered output of a failed OneTimeSetUp/OneTimeTearDown when it was
  not sent live, and clear the suite buffers.
- Keep MoveNext frames in filtered stack traces. On .NET Framework the throw
  location of an async method is <Method>d__0.MoveNext().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@OsirisTerje
OsirisTerje merged commit ef08685 into main Nov 30, 2026
3 checks passed
@OsirisTerje
OsirisTerje deleted the feature/issue1515-agent-output branch November 30, 2026 14:29
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.

Output settings for AI agents, aligned with Microsoft.Testing.Platform

2 participants