Skip to content

Fix OpenCode detection and reconcile vendored source baselines - #12174

Merged
Amaury Levé (Evangelink) merged 1 commit into
mainfrom
dev/amauryleve/vendored-source-sync
Nov 2, 2026
Merged

Amaury Levé (Evangelink) merged 1 commit into
mainfrom
dev/amauryleve/vendored-source-sync

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Pull request

Summary

OpenCode sets OPENCODE, but MTP was still checking OPENCODE_AI, so OpenCode sessions missed the agent-aware output defaults. Use the upstream variable name, keep acceptance-test environment isolation in sync, and add focused regression cases.

Reconcile both vendored drift reports. The MSBuild OpenHarmony changes are outside the copied console-mode method and P/Invokes, so that entry needs only a baseline and adaptation-note update.

Fixes #12171
Fixes #12172

Design and decision record

The existing drift reports contain the upstream diffs and rationale; this is a synchronization fix, not a new feature requiring a separate design record. Follow the SDK's rule rename exactly, including ignoring the obsolete variable. Leave local NativeMethods.cs code unchanged rather than importing unrelated OS-detection helpers.

Demonstration

Paired executions of the existing AnsiOptionTests.TestAssetFixture asset against separately packed MTP variants produced the following results. GITHUB_ACTIONS=true, unrelated agent flags and NO_COLOR were cleared, and each child executed exactly one passed result named Test1 with exit 0.

Environment / option Before After
OPENCODE=1 or OPENCODE=false, --ansi auto ANSI and banner No ANSI or banner
OPENCODE absent or empty, --ansi auto ANSI and banner ANSI and banner
Only OPENCODE_AI=1, --ansi auto No ANSI or banner ANSI and banner
OPENCODE=1, --ansi on ANSI and banner ANSI, no banner
OPENCODE=1, --ansi off No ANSI, banner No ANSI or banner

These are seven concrete environment/option cases. Text signals are clearer than screenshots for this detector correction; no CLI strings or layout are changed.

Validation and regression proof

Local Windows x64 validation used the pinned SDK 12.0.100-alpha.1.26509.101. Normal project target-framework matrices were built without warnings or errors. The packed consumer targeted net11.0; host traces confirmed the normal roll-forward to runtime 12.0.0-alpha.1.26509.101.

The following executed commands all exited 0. Only machine-specific scratch paths are parameterized as $Artifacts.

.\eng\build.ps1 -restore -build -msbuildEngine dotnet -nodeReuse:$false -projects 'test\UnitTests\Microsoft.Testing.Platform.UnitTests\Microsoft.Testing.Platform.UnitTests.csproj' '/p:EnableCodeCoverage=false' "/bl:$Artifacts\green-unit-default-tfms-{}.binlog"

.\eng\build.ps1 -restore -build -pack -verbosity quiet -msbuildEngine dotnet -nodeReuse:$false -projects 'src\Platform\Microsoft.Testing.Platform\Microsoft.Testing.Platform.csproj' "/bl:$Artifacts\green-core-pack-{}.binlog"

.\.dotnet\dotnet.exe artifacts\bin\Microsoft.Testing.Platform.UnitTests\Debug\net11.0\Microsoft.Testing.Platform.UnitTests.dll --filter 'FullyQualifiedName~LLMEnvironmentDetectorTests' --no-ansi --progress off --report-trx --report-trx-filename unit.trx --report-junit --report-junit-filename unit.xml --report-ctrf --report-ctrf-filename unit.ctrf.json --results-directory "$Artifacts\unit-green-final"

Final detector run: 12 executed, 12 passed, 0 failed, 0 skipped. TRX, JUnit, and CTRF exports were parsed and checked against independent discovery. Manifest validation, python .github\scripts\check_vendored_files.py validate, exited 0; all 38 detector variables match the acceptance isolation list.

Packed-consumer commands and provenance

The existing asset was generated for net11.0, restored with Microsoft.Testing.Platform mapped exclusively to the respective variant's artifacts\packages\Debug\Shipping feed, and given a fresh .packages cache per variant. $Asset below parameterizes that generated asset's directory.

.\.dotnet\dotnet.exe build "$Asset\AnsiOptionTest.csproj" -c Release "-p:RestoreConfigFile=$Asset\NuGet.config" "-p:RestorePackagesPath=$Asset\.packages" -p:UseSharedCompilation=false -nr:false "-bl:$Asset\consumer-{}.binlog"

& "$Asset\bin\Release\net11.0\AnsiOptionTest.exe" --no-ansi --progress off --ansi auto --show-test-results all

Consumer builds and all seven child launches exited 0 in both states. The last command was repeated with the environment/--ansi values in the demonstration matrix. Checks independently required the expected ANSI/banner state, the passed Test1 identity, and summary counts of total 1, succeeded 1, failed 0, skipped 0.

Both variants used package version 2.6.0-dev, but different bits:

  • Fixed package SHA-256: A9457247249BE0207ABFB91F1DEDB21AEDBDCC3FE361EFB407F7C95B59986DF2.
  • Pre-fix package SHA-256: B3D4499C27661C3DD0AA896E59CDE59592D688E1F046AF2FB13D857BDFE8585A.

project.assets.json, deps.json, matching packed/cached/consumer DLL hashes, and host-resolution traces confirmed the loaded variant. Consumer project and program bytes were identical across states.

Full acceptance-suite and CI execution are not claimed. Raw logs, binlogs, reports, and provenance are retained locally and have not been uploaded.

Test-value evidence

The validated patch is byte-identical to commit ff1e22692d1afaed096bff8185fe1b8fc255a4ea. The pre-fix comparison used base 6075756d0590f3d1643d4fdf4bc03f79684660fd with the same test/isolation changes retained. Both states built cleanly, were packed separately, and used the same selectors, data, and assertions.

Contract / case Pre-fix result Fixed result
IsLLMEnvironment_WhenCheckingOpenCode_ReturnsExpectedResult (five rows) 3 intended equality failures, 2 passed 5 passed
Existing AI_AGENT detector cases 7 passed 7 passed
Seven packaged ANSI/banner scenarios above 5 detected the obsolete rule, 2 passed 7 passed
Terminal native-methods drift Metadata-only reconciliation; copied code unchanged No executable behavior change

The pre-fix unit module exited 2 with exactly the OPENCODE=1, OPENCODE=false, and obsolete-variable assertion failures. The same module exited 0 with all 12 cases passing after the fix. The packaged-check verifier exited 1 before and 0 after; all child hosts still exited 0, so its failures were the intended ANSI/banner assertions, not launch or execution failures.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 09:48
@github-actions github-actions Bot added the state/needs-review Awaiting review from the team. label Nov 2, 2026

@github-actions github-actions Bot 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.

🧪 Test quality review — PR #12174

Compared merge base 6075756d0590f3d1643d4fdf4bc03f79684660fd with head ff1e22692d1afaed096bff8185fe1b8fc255a4ea. Evidence applies to this head, not every intermediate commit.

Test-value evidence

All results below are static predictions. No tests were executed, and no paired red/green execution records were available.

  • Contract: OpenCode detection changes from OPENCODE_AI to OPENCODE.
    • Test: LLMEnvironmentDetectorTests.IsLLMEnvironment_WhenCheckingOpenCode_ReturnsExpectedResult.
    • OPENCODE=1 and OPENCODE=false must give true (decisive assertion: Assert.AreEqual(expected, ...)).
    • OPENCODE empty or null, and OPENCODE_AI=1, must give false.
    • Counterfactual: with the old OPENCODE_AI rule, the OPENCODE=1 and OPENCODE=false cases would fail, and OPENCODE_AI=1 would wrongly return true. This is a static prediction.
    • Correct implementation: all five cases pass (predicted).
  • Contract: AnsiOptionTests and WellKnownEnvironmentVariables clear OPENCODE instead of OPENCODE_AI.
    • These are test-infrastructure updates that keep the host process from being detected as an LLM environment. They are covered indirectly. No dedicated counterfactual was assessed.
  • eng/vendored-files.json: metadata only, so not applicable.

🧵 Parallel safety

STATUS: PARTIAL. The separate specialist task was not run in this session, so parallel-safety coverage is incomplete. This is not a clean result.

Manual check of the changed code, which is not a substitute for the specialist:

  • The new test creates its own Mock<IEnvironment> per call and touches no shared state.
  • The other two test-side changes only rename an environment-variable string.

Per-test assessment

Pseudo-mutation evidence below consists of static predictions, not executed mutation results.

ResultQualityTestNotesHow to improve
Pass A (90–100) new LLMEnvironmentDetectorTests.
IsLLMEnvironment_
WhenCheckingOpenCode_
ReturnsExpectedResult
Data rows cover set, falsy-string, empty, null and the old name. None

Pseudo-mutation evidence:

  • Reverting the rule to OPENCODE_AI is likely killed (inferred) by the OPENCODE=1 row and the OPENCODE_AI=1 row.

No inline findings were published. The helper change to CreateDetector preserves existing AI_AGENT behavior through its default parameter.

This advisory review is heuristic and non-blocking.

Re-run the combined review with /review-tests, or only the parallel-safety specialist with /parallel-audit.

🤖 Automated content by GitHub Copilot. Generated by the Test Quality Review on PR (on open / sync) workflow. · copilot · auto · 25.9 AIC · ⌖ 0.824 AIC · ⊞ 7.8K · ◷

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Nov 2, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Nov 2, 2026

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

No active review issues are identified for the OpenCode detection and vendored-baseline updates.

No open issues 🎉

What changed in this PR

Fixes Microsoft.Testing.Platform’s OpenCode detection so agent-aware output defaults use OPENCODE, and reconciles the vendored drift reports in #12171 and #12172.

Changes:

  • Replaces OPENCODE_AI with OPENCODE in detection and acceptance-test environment isolation.
  • Adds five regression cases covering nonempty, empty, absent, and obsolete variables.
  • Updates both upstream baselines and documents why the MSBuild changes require no local code changes.

Test-value evidence: For ff1e22692d1afaed096bff8185fe1b8fc255a4ea, the PR reports three intended pre-fix unit failures followed by 12 passing cases, plus seven passing packaged-consumer scenarios after the fix. Raw artifacts were not available for independent verification; full acceptance-suite and CI execution are not claimed.

File Description
test/​Utilities/​Microsoft.Testing.TestInfrastructure/​WellKnownEnvironmentVariables.cs Updates the shared environment-isolation list.
test/​UnitTests/​Microsoft.Testing.Platform.UnitTests/​Helpers/​LLMEnvironmentDetectorTests.cs Adds focused OpenCode detection regression cases.
test/​IntegrationTests/​Microsoft.Testing.Platform.Acceptance.IntegrationTests/​AnsiOptionTests.cs Clears OPENCODE for isolated ANSI tests.
src/​Platform/​Microsoft.Testing.Platform/​Helpers/​LLMEnvironmentDetector.cs Detects OpenCode through the upstream variable name.
eng/​vendored-files.json Refreshes baseline hashes and adaptation notes.

Review effort: Balanced

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Nov 2, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. labels Nov 2, 2026
@Evangelink
Amaury Levé (Evangelink) merged commit 0110e19 into main Nov 2, 2026
38 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/vendored-source-sync branch November 2, 2026 11:48
@github-actions github-actions Bot removed the state/approved Proposal approved; ready for implementation. label Nov 2, 2026
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.

[vendored-sync] platform-terminal-native-methods: drift detected (#0) [vendored-sync] platform-llm-environment-detector: drift detected (#0)

3 participants