Skip to content

Commit 0110e19

Browse files
EvangelinkCopilot
andauthored
Fix OpenCode detection and reconcile vendored source baselines (#12174)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 44df227 commit 0110e19

5 files changed

Lines changed: 20 additions & 11 deletions

File tree

‎eng/vendored-files.json‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,14 @@
237237
{
238238
"id": "platform-llm-environment-detector",
239239
"local_path": "src/Platform/Microsoft.Testing.Platform/Helpers/LLMEnvironmentDetector.cs",
240-
"notes": "Adapted from dotnet CLI telemetry LLM/agent environment detection. All environment reads already use the injected IEnvironment, so the upstream environment-provider injection requires no port. Detection rules are unchanged.",
240+
"notes": "Adapted from dotnet CLI telemetry LLM/agent environment detection. All environment reads already use the injected IEnvironment, so the upstream environment-provider injection requires no port. OpenCode is detected through OPENCODE.",
241241
"sources": [
242242
{
243243
"repo": "dotnet/sdk",
244244
"ref": "main",
245245
"path": "src/Cli/dotnet/Telemetry/LLMEnvironmentDetectorForTelemetry.cs",
246-
"baseline_ref_sha": "082c56168c1654f1311bbc3cbc4b0548b45ed529",
247-
"baseline_blob_sha": "9d258b7843c990bd4014973aaf7dfb54e5ffb152",
246+
"baseline_ref_sha": "7fcbcb9ad2d7004f04f330f2c586f38e411eb35b",
247+
"baseline_blob_sha": "3b9afc4ad11da70b1e0a7e66e7415ef7eff257af",
248248
"scope": "LLM/agent detection rules"
249249
}
250250
]
@@ -267,14 +267,14 @@
267267
{
268268
"id": "platform-terminal-native-methods",
269269
"local_path": "src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/NativeMethods.cs",
270-
"notes": "Only QueryIsScreenAndTryEnableAnsiColorCodes and its console-mode P/Invokes are copied from msbuild's Framework NativeMethods. Upstream CodeQL annotations in GetLastWriteFileUtcTime are outside the copied scope and require no port.",
270+
"notes": "Only QueryIsScreenAndTryEnableAnsiColorCodes and its console-mode P/Invokes are copied from msbuild's Framework NativeMethods. Upstream OpenHarmony detection and CodeQL annotations in GetLastWriteFileUtcTime are outside the copied scope and require no port.",
271271
"sources": [
272272
{
273273
"repo": "dotnet/msbuild",
274274
"ref": "main",
275275
"path": "src/Framework/NativeMethods.cs",
276-
"baseline_ref_sha": "ad616f42ced6d62a1926a19641bd0c4353d185c3",
277-
"baseline_blob_sha": "cc47aa5f90d7b88184ee6f5b6dc684258aacc77f",
276+
"baseline_ref_sha": "86743d0545fba3d043d4e7aaa12891edb3fd56e6",
277+
"baseline_blob_sha": "724a2e387da9a7295f4d519ce598e0c545910e3f",
278278
"scope": "QueryIsScreenAndTryEnableAnsiColorCodes and supporting console-mode P/Invokes"
279279
}
280280
]

‎src/Platform/Microsoft.Testing.Platform/Helpers/LLMEnvironmentDetector.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal sealed class LLMEnvironmentDetector
4444
// Droid
4545
new EnvironmentDetectionRuleWithResult<string>("droid", new AnyPresentEnvironmentRule("DROID_CLI")),
4646
// OpenCode
47-
new EnvironmentDetectionRuleWithResult<string>("opencode", new AnyPresentEnvironmentRule("OPENCODE_AI")),
47+
new EnvironmentDetectionRuleWithResult<string>("opencode", new AnyPresentEnvironmentRule("OPENCODE")),
4848
// Zed AI
4949
new EnvironmentDetectionRuleWithResult<string>("zed", new AnyPresentEnvironmentRule("ZED_ENVIRONMENT", "ZED_TERM")),
5050
// Kimi CLI

‎test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/AnsiOptionTests.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public async Task NoColorEnvVar_OverriddenByExplicitAnsiOn()
205205
["AMP_HOME"] = string.Empty,
206206
["QWEN_CODE"] = string.Empty,
207207
["DROID_CLI"] = string.Empty,
208-
["OPENCODE_AI"] = string.Empty,
208+
["OPENCODE"] = string.Empty,
209209
["ZED_ENVIRONMENT"] = string.Empty,
210210
["ZED_TERM"] = string.Empty,
211211
["KIMI_CLI"] = string.Empty,

‎test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/LLMEnvironmentDetectorTests.cs‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,20 @@ public void IsLLMEnvironment_WhenAIAgentHoldsAKnownAgentValue_ReturnsTrue(string
2525
public void IsLLMEnvironment_WhenAIAgentDoesNotHoldAKnownAgentValue_ReturnsFalse(string? aiAgentValue)
2626
=> Assert.IsFalse(CreateDetector(aiAgentValue).IsLLMEnvironment());
2727

28-
private static LLMEnvironmentDetector CreateDetector(string? aiAgentValue)
28+
[TestMethod]
29+
[DataRow("OPENCODE", "1", true)]
30+
[DataRow("OPENCODE", "false", true)]
31+
[DataRow("OPENCODE", "", false)]
32+
[DataRow("OPENCODE", null, false)]
33+
[DataRow("OPENCODE_AI", "1", false)]
34+
public void IsLLMEnvironment_WhenCheckingOpenCode_ReturnsExpectedResult(string variableName, string? value, bool expected)
35+
=> Assert.AreEqual(expected, CreateDetector(value, variableName).IsLLMEnvironment());
36+
37+
private static LLMEnvironmentDetector CreateDetector(string? value, string variableName = "AI_AGENT")
2938
{
3039
Mock<IEnvironment> environment = new();
3140
_ = environment.Setup(x => x.GetEnvironmentVariable(It.IsAny<string>())).Returns((string?)null);
32-
_ = environment.Setup(x => x.GetEnvironmentVariable("AI_AGENT")).Returns(aiAgentValue);
41+
_ = environment.Setup(x => x.GetEnvironmentVariable(variableName)).Returns(value);
3342
return new LLMEnvironmentDetector(environment.Object);
3443
}
3544
}

‎test/Utilities/Microsoft.Testing.TestInfrastructure/WellKnownEnvironmentVariables.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static class WellKnownEnvironmentVariables
3636
"AMP_HOME",
3737
"QWEN_CODE",
3838
"DROID_CLI",
39-
"OPENCODE_AI",
39+
"OPENCODE",
4040
"ZED_ENVIRONMENT",
4141
"ZED_TERM",
4242
"KIMI_CLI",

0 commit comments

Comments
 (0)