Skip to content

Commit b0aebdb

Browse files
EvangelinkCopilot
andauthored
Port copilot-app LLM detection rule from dotnet/sdk (#10255)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e2cd5646-d310-4513-86bd-1b02ea6ab3d2
1 parent ad2d8d5 commit b0aebdb

3 files changed

Lines changed: 40 additions & 3 deletions

File tree

‎eng/vendored-files.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@
198198
"repo": "dotnet/sdk",
199199
"ref": "main",
200200
"path": "src/Cli/dotnet/Telemetry/LLMEnvironmentDetectorForTelemetry.cs",
201-
"baseline_ref_sha": "bcafbe92a30b1866bd17789759c9941761bf6b49",
202-
"baseline_blob_sha": "0682d3bf641c49fe17b4a0de4d48929b36ab87e1",
201+
"baseline_ref_sha": "79e9664eb6918a0d6b78d1018e196a468901977f",
202+
"baseline_blob_sha": "d8b750e1f8eb0b004a4566f455ce7997f07bfa61",
203203
"scope": "LLM/agent detection rules"
204204
}
205205
]

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Microsoft.Testing.Platform.Helpers;
55

6-
// Adapted from https://github.com/dotnet/sdk/tree/bcafbe92a30b1866bd17789759c9941761bf6b49/src/Cli/dotnet/Telemetry/LLMEnvironmentDetectorForTelemetry.cs
6+
// Adapted from https://github.com/dotnet/sdk/blob/79e9664eb6918a0d6b78d1018e196a468901977f/src/Cli/dotnet/Telemetry/LLMEnvironmentDetectorForTelemetry.cs
77
// Diverged from the upstream telemetry-only version so detection results can drive
88
// user-facing platform defaults (ANSI mode, banner, --show-stdout/--show-stderr).
99
// IMPORTANT: keep the environment-variable list below in sync with
@@ -25,6 +25,8 @@ internal sealed class LLMEnvironmentDetector
2525
// GitHub Copilot CLI (legacy gh extension: GITHUB_COPILOT_CLI_MODE; new Copilot CLI: GH_COPILOT_WORKING_DIRECTORY, COPILOT_CLI, COPILOT_MODEL, COPILOT_ALLOW_ALL, or COPILOT_GITHUB_TOKEN is set).
2626
new EnvironmentDetectionRuleWithResult<string>("copilot-cli", new AnyPresentEnvironmentRule(
2727
"GITHUB_COPILOT_CLI_MODE", "GH_COPILOT_WORKING_DIRECTORY", "COPILOT_CLI", "COPILOT_MODEL", "COPILOT_ALLOW_ALL", "COPILOT_GITHUB_TOKEN")),
28+
// GitHub Copilot app (the desktop GitHub application running as an AI agent), which sets AI_AGENT=github_copilot_app_agent.
29+
new EnvironmentDetectionRuleWithResult<string>("copilot-app", new EnvironmentVariableValueRule("AI_AGENT", "github_copilot_app_agent")),
2830
// GitHub Copilot agent mode in VS Code, which sets AI_AGENT=github_copilot_vscode_agent and COPILOT_AGENT=1 on the terminals it runs commands in.
2931
new EnvironmentDetectionRuleWithResult<string>("copilot-vscode", new AnyMatchEnvironmentRule(
3032
new EnvironmentVariableValueRule("AI_AGENT", "github_copilot_vscode_agent"),
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Microsoft.Testing.Platform.Helpers;
5+
6+
using Moq;
7+
8+
namespace Microsoft.Testing.Platform.UnitTests;
9+
10+
[TestClass]
11+
public sealed class LLMEnvironmentDetectorTests
12+
{
13+
[TestMethod]
14+
[DataRow("github_copilot_app_agent")]
15+
[DataRow("GitHub_Copilot_App_Agent")]
16+
[DataRow("github_copilot_vscode_agent")]
17+
public void IsLLMEnvironment_WhenAIAgentHoldsAKnownAgentValue_ReturnsTrue(string aiAgentValue)
18+
=> Assert.IsTrue(CreateDetector(aiAgentValue).IsLLMEnvironment());
19+
20+
[TestMethod]
21+
[DataRow(null)]
22+
[DataRow("")]
23+
[DataRow("github_copilot_app")]
24+
[DataRow("some_other_agent")]
25+
public void IsLLMEnvironment_WhenAIAgentDoesNotHoldAKnownAgentValue_ReturnsFalse(string? aiAgentValue)
26+
=> Assert.IsFalse(CreateDetector(aiAgentValue).IsLLMEnvironment());
27+
28+
private static LLMEnvironmentDetector CreateDetector(string? aiAgentValue)
29+
{
30+
Mock<IEnvironment> environment = new();
31+
_ = environment.Setup(x => x.GetEnvironmentVariable(It.IsAny<string>())).Returns((string?)null);
32+
_ = environment.Setup(x => x.GetEnvironmentVariable("AI_AGENT")).Returns(aiAgentValue);
33+
return new LLMEnvironmentDetector(environment.Object);
34+
}
35+
}

0 commit comments

Comments
 (0)