Use simctl --json-output flag to avoid stdout pollution#170
Conversation
LogInfo, LogWarning, and LogDebug in ConsoleLogger now use Console.Error.WriteLine (stderr) instead of Console.WriteLine (stdout). This prevents log messages from polluting structured output (e.g. JSON) for consumers that capture stdout. Fixes #2 Agent-Logs-Url: https://github.com/dotnet/macios-devtools/sessions/005240a3-2797-4f5f-865c-c920f0723994 Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/macios-devtools/sessions/005240a3-2797-4f5f-865c-c920f0723994 Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
…tignore Agent-Logs-Url: https://github.com/dotnet/macios-devtools/sessions/005240a3-2797-4f5f-865c-c920f0723994 Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
rolfbjarne
left a comment
There was a problem hiding this comment.
Relying on stdout not containing noise is unreliable, because any number of places can print to stdout.
A better solution is to get specific output written to a file instead.
For instance for xcrun simctl list devices --json, pass --json-output /path/to/temporary/file.json as well, and read that file afterwards, instead of relying on stdout.
Also the solution of writing to stderr instead of stdout has a separate problem: some MSBuild tasks will automatically fail if anything is printed to stderr.
|
@copilot can you look at @rolfbjarne comment and use the file route |
…sed output Per reviewer feedback: writing to stderr breaks MSBuild tasks. Instead, add SimCtl.RunToFile() so consumers can capture structured output (JSON) to a file, isolating it from any stdout noise. Agent-Logs-Url: https://github.com/dotnet/macios-devtools/sessions/2bbfd1eb-7c88-49ed-8bb9-6e335c369cee Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
…eptions Agent-Logs-Url: https://github.com/dotnet/macios-devtools/sessions/2bbfd1eb-7c88-49ed-8bb9-6e335c369cee Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/macios-devtools/sessions/2bbfd1eb-7c88-49ed-8bb9-6e335c369cee Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
Reverted the ConsoleLogger stderr changes and added Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Per reviewer feedback, use xcrun simctl's native --json-output=<file> flag to write structured JSON output directly to a temp file, instead of capturing stdout and writing it ourselves. - Revert RunToFile/RunCore approach back to original Run() method - Add RunJson() that passes --json --json-output=<tempPath> to simctl and reads the result from the temp file - Update SimulatorService, RuntimeService, and tests to use RunJson() Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Updated per @rolfbjarne's feedback: now using The new |
…ter to 4.6.0 NUnit3TestAdapter 5.0.0 pulled in Microsoft.Testing.Platform which brought a broken transitive dependency chain (ApplicationInsights, Telemetry DLLs not copied to output). Downgrade to 4.6.0 to avoid the Testing Platform migration issues. Add Microsoft.NET.Test.Sdk (implicitly referenced by .NET SDK) and CopyLocalLockFileAssemblies to ensure all test dependencies are resolved at runtime. Remove NUnit.ConsoleRunner (unused with dotnet test). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Use Path.GetTempFileName() instead of GetRandomFileName() to atomically reserve the temp file path (avoids race condition). - Check Run() return value before reading the file, so simctl failures surface the correct error instead of a misleading 'no JSON output file' message. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The walk-up logic stopped at artifacts/bin/tests/ (first dir named 'tests') instead of the source tests/ directory. Fix by requiring tests.csproj to exist as a sentinel, disambiguating the source directory from the Arcade SDK output layout. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The explicit PackageReference is needed for testhost.runtimeconfig.json, but .NET SDK 10.0+ implicitly references it causing duplicate errors. Suppress NETSDK1023 and NU1504 in the test project. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
9e0781d to
a4864e8
Compare
rolfbjarne
left a comment
There was a problem hiding this comment.
Also the PR title & description seem out of date.
… Microsoft.NET.Test.Sdk Tested: build succeeds and 118/119 tests pass (1 skipped) with NUnit3TestAdapter 5.0.0 + Microsoft.NET.Test.Sdk 17.12.0. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@copilot resolve the merge conflicts in this pull request |
Resolve conflict in tests/TestHelper.cs by taking main's IsTestsProjectDir helper approach. Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
Per review feedback, relying on stdout being clean is fragile, and routing ConsoleLogger output to stderr would break MSBuild tasks.
Changes
Xamarin.MacDev/SimCtl.cs— AddRunJson(params string[] args)which passes--json --json-output=<tempfile>toxcrun simctl, reads JSON from the temp file, then cleans up. JSON output is never read from stdout.SimulatorService,RuntimeService— Updated to callsimctl.RunJson("list", ...)instead ofsimctl.Run("list", ..., "--json").tests/tests.csproj— Add explicitMicrosoft.NET.Test.Sdkpackage reference and suppress NETSDK1023/NU1504 warnings.