Skip to content

Extract shared experimental test output capture - #22716

Open
Mitch Denny (mitchdenny) wants to merge 1 commit into
mainfrom
mitchdenny-shared-test-output-capture
Open

Mitch Denny (mitchdenny) wants to merge 1 commit into
mainfrom
mitchdenny-shared-test-output-capture

Conversation

@mitchdenny

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 55b3ffe76415044c2834e36d150c7f0aec0bf33a

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ Shared production patch matches the prepared Go source exactly.
↑ 153 focused capture, cancellation, MSTest compatibility and SDK generation tests pass.
↓ Live DCP end-to-end capture and Windows/Linux execution were not validated; private-artifact behavior has not had independent security review.

Description

Test integrations need raw process output without depending on another language's hosting integration. This standalone prerequisite extracts the experimental ResourceTestingContext.CaptureOutputAsync() capability from #21585 into core Hosting, against main rather than the integration stack.

Collectors can await authoritative completion, including failed execution, and capture separate timestamp-free stdout/stderr streams into their private output directory. Both streams must reach EOF and both files must close before output.complete is created. Repeated calls share the same capture task, including faults; collection cancellation and deadlines still apply. Ordinary run behavior is unchanged.

The raw accessor, DCP durable-stream adapter, capture implementation, coordinator wiring, README contract and constructor adaptations match prepared Go revision 1a6812bafe33a93a036ec94a0659f7985aa7c38b exactly. Capture tests retain the same behavior, with inert executable names changed from go to test-runner. The scanner/export regression scans only Hosting; no Go integration project reference was added. SDK snapshots were regenerated normally for all five language generators, including the original 35-line Go projection.

No Go parser, resource, factory API, playground integration, language-specific testing integration, or stack metadata is included. Existing merged foundation and MSTest support are the only prerequisites. Extraction base: d390bb0f5b6ef991e94f48222e9220b599324cb7.

User-facing usage

Inside an experimental runtime test collector:

#pragma warning disable ASPIRETESTING001

resource.WithTesting(async context =>
{
    await context.CaptureOutputAsync();
    var stdoutPath = Path.Combine(context.OutputPath, "stdout.log");
    // Translate captured output into framework-neutral TestResult publications.
});

This supports one native, non-terminal executable invocation. Integrations must prevent replicas, restarts and retries before launch. Partial artifacts remain on failures without a completion marker.

Security considerations

Capture writes exclusively created files inside the existing private test output directory, uses Unix 0600 permissions, and rejects symlinked/reparse-point output directories and existing artifacts. Raw output may contain sensitive process data. No new listener or process launch is introduced. Independent threat modeling/security review and live cross-platform validation were not performed.

Validation

All final targeted runs passed on macOS arm64: 126 core Hosting tests, 20 MSTest collector tests, 3 TypeScript export/scanning tests, and one scanning test each for Go, Python, Rust and Java (153 total). Initial expected snapshot mismatches were regenerated, reviewed and rerun successfully. Live DCP capture, full repository suites, Windows and Linux were not run.

SDK restore — passed:

./restore.sh

Raw capture, collector deadlines/cancellation, streaming and completion — passed, 126 tests:

MSBUILDTERMINALLOGGER=false dotnet test --project tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj --no-launch-profile -- --filter-class '*.TestOutputCaptureTests' --filter-class '*.TestRunCoordinatorTests' --filter-class '*.TestRunStreamingTests' --filter-class '*.TestingCollectorTests' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'

Merged MSTest constructor/DI and collection compatibility — passed, 20 tests:

MSBUILDTERMINALLOGGER=false dotnet test --project tests/Aspire.Hosting.Dotnet.Tests/Aspire.Hosting.Dotnet.Tests.csproj --no-launch-profile -- --filter-class '*.MsTestCollectorTests' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'

Hosting-only experimental export, MSTest projection and TypeScript scanning — passed, 3 tests:

MSBUILDTERMINALLOGGER=false dotnet test --project tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests.csproj --no-launch-profile -- --filter-method '*.GeneratesExperimentalCaptureOutputWithoutIntegrationAssemblies' --filter-method '*.GeneratesOneAddMsTestMethodWithTypedOptionsAndExecutableCapabilities' --filter-method '*.TwoPassScanning_GeneratesWithEnvironmentOnTestRedisBuilder' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'

Go shared SDK projection — passed, 1 test:

MSBUILDTERMINALLOGGER=false dotnet test --project tests/Aspire.Hosting.CodeGeneration.Go.Tests/Aspire.Hosting.CodeGeneration.Go.Tests.csproj --no-launch-profile -- --filter-method '*.TwoPassScanning_GeneratesWithEnvironmentOnTestRedisBuilder' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'

Remaining affected shared SDK projections — passed, 1 test per language:

for language in Python Rust Java; do MSBUILDTERMINALLOGGER=false dotnet test --project "tests/Aspire.Hosting.CodeGeneration.$language.Tests/Aspire.Hosting.CodeGeneration.$language.Tests.csproj" --no-launch-profile -- --filter-method '*.TwoPassScanning_GeneratesWithEnvironmentOnTestRedisBuilder' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true' || exit "$?"; done

Fixes # (issue)

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 22716

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 22716"

@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot November 26, 2026 05:31
@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

52 / 101 PR test projects · 4 PR jobs, from 20 changed files.

Selected PR test projects (52 / 101)

Aspire.Cli.EndToEnd.Tests, Aspire.Hosting.Analyzers.Tests, Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Kubernetes.Tests, Aspire.Hosting.Azure.Kusto.Tests, Aspire.Hosting.Azure.Provisioning.Tests, Aspire.Hosting.Azure.Tests, Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Browsers.Tests, Aspire.Hosting.CodeGeneration.Go.Tests, Aspire.Hosting.CodeGeneration.Java.Tests, Aspire.Hosting.CodeGeneration.Python.Tests, Aspire.Hosting.CodeGeneration.Rust.Tests, Aspire.Hosting.CodeGeneration.TypeScript.Tests, Aspire.Hosting.Containers.Tests, Aspire.Hosting.DevTunnels.Tests, Aspire.Hosting.Docker.Tests, Aspire.Hosting.Dotnet.Tests, Aspire.Hosting.DotnetTool.Tests, Aspire.Hosting.EntityFrameworkCore.Tests, Aspire.Hosting.Foundry.Tests, Aspire.Hosting.Garnet.Tests, Aspire.Hosting.Go.Tests, Aspire.Hosting.Java.Tests, Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Kafka.Tests, Aspire.Hosting.Keycloak.Tests, Aspire.Hosting.Kubernetes.Tests, Aspire.Hosting.Maui.Tests, Aspire.Hosting.Milvus.Tests, Aspire.Hosting.MongoDB.Tests, Aspire.Hosting.MySql.Tests, Aspire.Hosting.Nats.Tests, Aspire.Hosting.OpenAI.Tests, Aspire.Hosting.Oracle.Tests, Aspire.Hosting.Orleans.Tests, Aspire.Hosting.PostgreSQL.Tests, Aspire.Hosting.Python.Tests, Aspire.Hosting.Qdrant.Tests, Aspire.Hosting.RabbitMQ.Tests, Aspire.Hosting.Radius.Tests, Aspire.Hosting.Redis.Tests, Aspire.Hosting.RemoteHost.Tests, Aspire.Hosting.Rust.Tests, Aspire.Hosting.Seq.Tests, Aspire.Hosting.SqlServer.Tests, Aspire.Hosting.Testing.Tests, Aspire.Hosting.Tests, Aspire.Hosting.Valkey.Tests, Aspire.Hosting.Yarp.Tests, Aspire.Playground.Tests, Aspire.Templates.Tests

Selected PR jobs (4)

cli-starter-validation, extension-e2e, polyglot, typescript-api-compat


How these were chosen — grouped by what changed

⚠️ 34 of the 52 selected test projects come from a single change — tests/Aspire.Hosting.TestUtilities/Utils/TestConsoleLogsService.cs.

🧪 tests/Aspire.Hosting.TestUtilities/Utils/TestConsoleLogsService.cs (changed test)
→ 34 via the project graph

show 34

Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Kubernetes.Tests, Aspire.Hosting.Azure.Kusto.Tests, Aspire.Hosting.Browsers.Tests, Aspire.Hosting.Containers.Tests, Aspire.Hosting.DevTunnels.Tests, Aspire.Hosting.Docker.Tests, Aspire.Hosting.DotnetTool.Tests, Aspire.Hosting.EntityFrameworkCore.Tests, Aspire.Hosting.Foundry.Tests, Aspire.Hosting.Garnet.Tests, Aspire.Hosting.Go.Tests, Aspire.Hosting.Java.Tests, Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Kafka.Tests, Aspire.Hosting.Keycloak.Tests, Aspire.Hosting.Kubernetes.Tests, Aspire.Hosting.Milvus.Tests, Aspire.Hosting.MongoDB.Tests, Aspire.Hosting.MySql.Tests, Aspire.Hosting.Nats.Tests, Aspire.Hosting.OpenAI.Tests, Aspire.Hosting.Oracle.Tests, Aspire.Hosting.Orleans.Tests, Aspire.Hosting.PostgreSQL.Tests, Aspire.Hosting.Python.Tests, Aspire.Hosting.Qdrant.Tests, Aspire.Hosting.RabbitMQ.Tests, Aspire.Hosting.Redis.Tests, Aspire.Hosting.Rust.Tests, Aspire.Hosting.Seq.Tests, Aspire.Hosting.SqlServer.Tests, Aspire.Hosting.Valkey.Tests, Aspire.Hosting.Yarp.Tests

🔧 src/Aspire.Hosting/ApplicationModel/ResourceLoggerService.cs (changed source)
→ 7 via the project graph: Aspire.Hosting.Analyzers.Tests (2 hops), Aspire.Hosting.Azure.Provisioning.Tests (3 hops), Aspire.Hosting.Azure.Tests, Aspire.Hosting.Maui.Tests, Aspire.Hosting.RemoteHost.Tests, Aspire.Hosting.Testing.Tests (2 hops), Aspire.Playground.Tests

🧪 tests/Aspire.Hosting.Tests/Cli/TestOutputCaptureTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests
→ 2 via the project graph: Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Radius.Tests

📦 affected project Aspire.Hosting.Dotnet
→ 2 tests: Aspire.Cli.EndToEnd.Tests, Aspire.Templates.Tests

📦 affected project Aspire.Hosting
→ 1 test: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.Go.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Java.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.java (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.Java.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.Python.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Rust.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.rs (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.Rust.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/MsTestExportTests.GeneratesOneAddMsTestMethodWithTypedOptionsAndExecutableCapabilities.verified.txt (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.TypeScript.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TestOutputCaptureExportTests.GeneratesExperimentalCaptureOutputWithoutIntegrationAssemblies.verified.txt (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.TypeScript.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.TypeScript.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/TestOutputCaptureExportTests.cs (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.TypeScript.Tests

🧪 tests/Aspire.Hosting.Dotnet.Tests/MsTestCollectorTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Dotnet.Tests

🧪 tests/Aspire.Hosting.Tests/Cli/TestRunCoordinatorTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests

🧪 tests/Aspire.Hosting.Tests/Cli/TestRunStreamingTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests

🧪 tests/Aspire.Hosting.Tests/Cli/TestingCollectorTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests

Job reasons

Job Triggered by
cli-starter-validation affected project Aspire.Hosting.PostgreSQL
extension-e2e • src/Aspire.Hosting/ApplicationModel/ResourceLoggerService.cs, src/Aspire.Hosting/ApplicationModel/ResourceTestingContext.cs, src/Aspire.Hosting/Cli/TestOutputCapture.cs, src/Aspire.Hosting/Cli/TestRunCoordinator.cs, src/Aspire.Hosting/Dcp/DcpResourceWatcher.cs, src/Aspire.Hosting/IConsoleLogsService.cs
• affected project Aspire.Hosting
polyglot • affected project Aspire.Hosting
• affected project Aspire.Hosting.Azure.Provisioning.KeyVault
typescript-api-compat affected project Aspire.Hosting

Selection computed for commit 55b3ffe.

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

A pre-existing completion marker can remain visible after failed or cancelled capture leaves partial logs, and the tests do not cover the actual DCP log endpoint’s capture guarantees.

2 open issues
What changed in this PR

Extracts experimental raw test-output capture from the Go integration work into core Hosting, allowing language integrations to collect process output without depending on another hosting integration.

Changes:

  • Adds shared CaptureOutputAsync() support with separate stdout/stderr files, completion tracking, cancellation, and private file creation.
  • Connects collectors to DCP’s raw output streams and documents the supported execution contract.
  • Adds capture and export tests, adapts coordinator construction, and updates generated SDK snapshots for five languages.
File Description
tests/​Aspire.Hosting.TestUtilities/​Utils/​TestConsoleLogsService.cs Adds configurable raw streams for tests.
tests/​Aspire.Hosting.Tests/​Cli/​TestRunStreamingTests.cs Supplies the coordinator’s logger dependency.
tests/​Aspire.Hosting.Tests/​Cli/​TestRunCoordinatorTests.cs Updates coordinator construction.
tests/​Aspire.Hosting.Tests/​Cli/​TestOutputCaptureTests.cs Tests capture, cancellation, artifacts, and safety checks.
tests/​Aspire.Hosting.Tests/​Cli/​TestingCollectorTests.cs Updates collector test setup.
tests/​Aspire.Hosting.Dotnet.Tests/​MsTestCollectorTests.cs Adapts MSTest coordinator construction.
tests/​Aspire.Hosting.CodeGeneration.TypeScript.Tests/​TestOutputCaptureExportTests.cs Tests Hosting-only experimental export.
tests/​Aspire.Hosting.CodeGeneration.TypeScript.Tests/​Snapshots/​TwoPassScanningGeneratedAspire.verified.ts Records TypeScript capture bindings.
tests/​Aspire.Hosting.CodeGeneration.TypeScript.Tests/​Snapshots/​TestOutputCaptureExportTests.GeneratesExperimentalCaptureOutputWithoutIntegrationAssemblies.verified.txt Records the standalone capture export.
tests/​Aspire.Hosting.CodeGeneration.TypeScript.Tests/​Snapshots/​MsTestExportTests.GeneratesOneAddMsTestMethodWithTypedOptionsAndExecutableCapabilities.verified.txt Updates MSTest’s shared context projection.
tests/​Aspire.Hosting.CodeGeneration.Rust.Tests/​Snapshots/​TwoPassScanningGeneratedAspire.verified.rs Records the Rust capture binding.
tests/​Aspire.Hosting.CodeGeneration.Python.Tests/​Snapshots/​TwoPassScanningGeneratedAspire.verified.py Records the Python capture binding.
tests/​Aspire.Hosting.CodeGeneration.Java.Tests/​Snapshots/​TwoPassScanningGeneratedAspire.verified.java Records the Java capture binding.
tests/​Aspire.Hosting.CodeGeneration.Go.Tests/​Snapshots/​TwoPassScanningGeneratedAspire.verified.go Records the Go capture binding.
src/​Aspire.Hosting/​README.md Documents experimental collection and artifact guarantees.
src/​Aspire.Hosting/​IConsoleLogsService.cs Adds the raw-stream service contract.
src/​Aspire.Hosting/​Dcp/​DcpResourceWatcher.cs Opens separate timestamp-free DCP streams.
src/​Aspire.Hosting/​Cli/​TestRunCoordinator.cs Connects runtime collectors to capture.
src/​Aspire.Hosting/​Cli/​TestOutputCapture.cs Implements stream persistence and completion marking.
src/​Aspire.Hosting/​ApplicationModel/​ResourceTestingContext.cs Exposes and shares the capture task.
src/​Aspire.Hosting/​ApplicationModel/​ResourceLoggerService.cs Delegates raw-stream access to the console service.

Review effort: Balanced

// Open both destinations before draining either stream. CreateNew prevents reusing a stale
// report or following an existing file symlink. Mark completion only after both streams drain.
using var stop = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
var stdout = CreateFile(context.OutputPath, "stdout.log");
Comment on lines +644 to +646
return _kubernetesService.GetLogStreamAsync(executable,
standardError ? Logs.StreamTypeStdErr : Logs.StreamTypeStdOut,
cancellationToken, follow: true, timestamps: false, lineNumbers: false);
@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

This branch has not been deployed

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

Labels

needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants