Skip to content

Add JSON / NDJSON test report extension (Microsoft.Testing.Extensions.JsonReport) #8828

Closed as not planned

Description

Summary

Introduce a new MTP extension Microsoft.Testing.Extensions.JsonReport that emits a stable, documented NDJSON (newline-delimited JSON) event stream of test execution events, plus a final summary event. Models the existing Microsoft.Testing.Extensions.TrxReport, Microsoft.Testing.Extensions.HtmlReport, and Microsoft.Testing.Extensions.AzureDevOpsReport extensions.

Motivation

Today MTP offers two machine-readable outputs:

There is no structured output for test execution results that an agent or downstream tool can stream-parse incrementally. Modern test runners all expose this:

For LLM/agent consumption, NDJSON is far superior to TRX:

  • One event per line: agents can grep/tail without parsing
  • Stable schema: agents can rely on field names
  • Streamable: events flush as tests complete, enabling live reactions

Proposed shape

Each line is a single JSON object. Event types:

{"event":"run_started","schemaVersion":1,"runId":"...","startTimeUtc":"...","framework":{"name":"MSTest","version":"3.x"}}
{"event":"test_started","testId":"...","testUid":"...","displayName":"...","fullyQualifiedName":"...","source":"..."}
{"event":"test_completed","testId":"...","outcome":"passed|failed|skipped|inconclusive","durationMs":12.3,"messages":[...],"errors":[{"type":"...","message":"...","stackTrace":"..."}],"output":{"stdout":"...","stderr":"..."},"location":{"file":"...","line":42}}
{"event":"run_summary","schemaVersion":1,"runId":"...","durationMs":1234,"counts":{"total":42,"passed":40,"failed":1,"skipped":1,"inconclusive":0},"endTimeUtc":"..."}

Per-test fields are optional and omitted when empty to reduce file size / token count.

CLI surface

--report-json [filename]      # writes NDJSON file under results-directory
--report-json-filename <path> # explicit filename

Mirrors --report-trx* / --report-html* exactly.

Implementation outline

  • New project: src/Platform/Microsoft.Testing.Extensions.JsonReport/Microsoft.Testing.Extensions.JsonReport.csproj
  • Class JsonReportDataConsumer : IDataConsumer consumes TestNodeUpdateMessage from the message bus (same pattern as TrxDataConsumer).
  • JsonReportCommandLineOptionsProvider : ICommandLineOptionsProvider registers the two options.
  • Use System.Text.Json Utf8JsonWriter for AOT-safety and zero-allocation writes.
  • Document schema in PACKAGE.md and a docs/JsonReportSchema.md page.
  • Add --list-tests json was already added in Add --list-tests json for machine-readable test discovery output #8280; this extension is for execution results.

Risks / questions

  • Naming: JsonReport vs JsonlReport vs EventStreamReport. NDJSON is the format; "JsonReport" matches the existing extension-name pattern (Trx, Html, AzureDevOps).
  • Should the schema also produce one big JSON document (Jest-style --json) in addition to NDJSON? NDJSON is strictly more useful for streaming agents; the umbrella issue can debate.
  • Stability: bump schemaVersion on breaking changes.

Acceptance criteria

  • New package Microsoft.Testing.Extensions.JsonReport produced and shipped.
  • --report-json and --report-json-filename options registered and visible in --help with-extensions snapshot.
  • Documented schema in PACKAGE.md + a versioned schema doc.
  • Acceptance integration tests: run a known failing+passing test set, assert the NDJSON file has the expected events.

References

Activity

  1. added
    needs/triage
    area/mtp
    area/mtp-extensions
    and removed on Jun 4, 2026
  2. added
    area/mtp-reporting
    and removed
    area/mtp-extensions
    needs/triage
    on Aug 27, 2026
  3. Evangelink commented on Oct 15, 2026

    @Evangelink
    MemberAuthor

    Evaluation follow-up: reframe around public streaming, not just JSON

    At the investigated revision, 6c6b1f474acbb6ab1bdbdec73fa32568f12dfcb5, the repository already contains experimental CTRF JSON execution reporting, including final outcomes, identities and retry history. This narrows the "we need any execution JSON" gap, but does not itself satisfy a stable public streaming contract.

    Measured comparison

    The #8824 local pilot used eight synthetic scenarios, one repeat and a fixed gpt-6.1-sol executor, with Vally 0.14.0 / Copilot SDK 1.0.11 / nested CLI 1.0.80. Every arm had the same task, exact grader, run metadata and full terminal fallback.

    Initial view Correct Mean input tokens Input change vs terminal Reported provider-cost change
    Terminal 8/8 48,306 baseline baseline
    CTRF-shaped failure query 8/8 41,633 -13.8% -2.8%
    Prototype full NDJSON 8/8 44,910 -7.0% +4.2%
    Prototype NDJSON failure query 8/8 41,631 -13.8% -2.8%

    The two query views were effectively tied in this pilot. The NDJSON inputs were prototype files, including module/attempt metadata needed by the cases, not an implemented reporter or agreed schema. This did not test flush latency, streaming, backpressure or time-to-first-action. Provider cost is not the same as total input tokens, raw bytes, USD or energy.

    Two separately evaluated real-output cases did not reproduce a consistent saving. All six exact grades passed, but the query path still needed terminal details; two recovered read-path mistakes in one CTRF trial confound its observed cost increase. These are small pilot observations, not statistical evidence that CTRF is intrinsically faster or slower.

    Diagnostic fidelity matters more than the format name

    An actual packed-host case published a failed node with an exception of this shape, without a richer explanation:

    new InvalidOperationException(
        "[INVOCATION_FAILED] Invocation failed.",
        new InvalidOperationException("[SERVICE_AUTH_401] The service rejected the credential."))

    The terminal retained both diagnostics. The actual CTRF test record contained only the outer message and its stack: SERVICE_AUTH_401 was absent. The current shared capture helper takes the provided exception's Message and StackTrace without traversing the inner chain. Other producers can supply richer explanation strings, so this is a specific demonstrated producer shape, not a claim about every framework.

    The synthetic CTRF fixture had a full multiline message and was therefore more informative than this real report. A query cannot recover information the reporter did not preserve. Keeping terminal fallback, and adding focused diagnostic-preservation coverage, is a higher-confidence next step than assuming a new JSON label solves triage.

    Producer overhead was also observable

    The controlled net9.0/Windows x64 consumer used the actual locally packed MTP 2.6.0-dev and CTRF 1.0.0-dev, built with repository SDK 12.0.100-alpha.1.26509.101. Feed/cache/package hashes and loaded runtime DLLs were matched.

    Across pass, failure, nested, zero, all-skipped and recovered-retry scenarios, five interleaved measured samples per mode after warmups showed about 0.49-0.51 seconds extra startup-inclusive wall time with CTRF enabled. For the 1,000-pass case the medians were 437ms off versus 936ms on; terminal output was 286 bytes and the CTRF file 463,863 bytes. This includes reporting/recovery/hosting lifecycle, not isolated JSON serialization cost; the cause was not profiled.

    This argues against auto-enabling a report for very short agent loops without measuring the composed path. It does not measure a future NDJSON emitter's overhead.

    Suggested direction

    Use existing CTRF as a final-results baseline. Pursue a new NDJSON package if a concrete public incremental consumer needs it, and measure correct actionable information arriving before run completion.

    Before making that a supported contract, define module/TFM/test/attempt identities, missing start events, all relevant failure states, explicit completion versus missing/truncated summary, bounded serialized writes/backpressure, cancellation/crash behavior, and aggregation across retries/modules. The internal recovery journal and server-mode events are prior art, not public report schemas to expose unchanged.

    Also, the current shared report CLI has a zero-argument report switch and a separate one-argument filename switch; --report-json [filename] does not literally mirror that arity.

    The real host used a controlled framework, not the MSTest adapter. Repair quality, larger held-out suites, other models/OSes, release branches and live streaming remain unmeasured. Full scripts/traces/CSV are retained locally, not yet published as a reproducible benchmark artifact. No production implementation or issue-state change was made.

    Posted by GitHub Copilot at the maintainer's request.

  4. Evangelink commented on Nov 9, 2026

    @Evangelink
    MemberAuthor

    Closing as not planned. The need for machine-readable test results is valid, but a separate Microsoft.Testing.Extensions.JsonReport package is not justified by the current evidence.

    Existing paths cover the main use cases

    • Persisted execution results: CTRF reporting already implements execution JSON, including test identities, outcomes and retry history. Its public packages are currently alpha; the stable compatibility commitment prepared in source should not be confused with an already shipped stable release. TRX remains available for existing report consumers.
    • Live observability: MTP's OpenTelemetry integration provides test spans, outcomes, exceptions and metrics, with correlation to application traces. Completed test spans can be exported while the rest of a suite continues. A local exporter or Collector can support this without requiring a hosted service.
    • Interactive runner clients: Server-mode JSON-RPC already provides incremental test updates for consumers that own the execution workflow.

    Why not another format now?

    The earlier evaluation did not establish an NDJSON-specific accuracy or cost advantage over querying CTRF for failures. The small synthetic pilot's two failure-query views were effectively tied, real-output observations did not show consistent savings, and live streaming was not measured. This is limited evidence, not proof that streaming can never help.

    A new format also would not repair diagnostics that were lost before serialization. Improving diagnostic fidelity in existing reporting is a more direct response to that demonstrated problem. A separate reporter would introduce another supported schema and lifecycle contract covering module/test/attempt identities, retries, partial runs, buffering and delivery failures.

    Limits and conditions for reconsideration

    OTel is not automatically a complete test-results ledger: sampling, queue saturation, attribute limits and interrupted flushing can lose information. Normal span export delivers completed spans, not immediate test-start notifications or each event added to a still-running span. Persisted reports and telemetry serve different purposes.

    A lightweight, directly tail-able lifecycle artifact could still be useful. We can reconsider it when a concrete consumer demonstrates a requirement that CTRF, OTel or server mode cannot reasonably meet, with a measurable improvement in useful, correct action before run completion and acceptable producer overhead. Any proposal should define identity, completion versus truncation, and delivery semantics rather than assume NDJSON supplies those guarantees.

    This closes the proposed additional package, not future improvements to existing reporters or telemetry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/mtparea/mtp-reporting

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions