Skip to content

Commit d07edff

Browse files
authored
Python: Fix Actions token environment (microsoft#7427)
* Fix Copilot Actions token environment Expose workflow tokens through GITHUB_TOKEN so Copilot CLI uses native Actions authentication, while preserving user-token integration test support. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d9fa4e9c-c32d-42fb-8ee4-4772473e6479 * Gate Copilot integration tests explicitly Use GitHub Actions authentication only when both GITHUB_ACTIONS and GITHUB_TOKEN are present, and require an explicit local opt-in that relies on stored Copilot login. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d9fa4e9c-c32d-42fb-8ee4-4772473e6479 --------- Copilot-Session: d9fa4e9c-c32d-42fb-8ee4-4772473e6479
1 parent 59fe8be commit d07edff

6 files changed

Lines changed: 53 additions & 9 deletions

File tree

‎.github/workflows/dotnet-integration-tests.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ jobs:
102102
env:
103103
COSMOSDB_ENDPOINT: https://localhost:8081
104104
COSMOSDB_KEY: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
105-
COPILOT_GITHUB_TOKEN: ${{ github.token }}
105+
GITHUB_TOKEN: ${{ github.token }}
106106
OpenAI__ApiKey: ${{ secrets.OPENAI__APIKEY }}
107107
OpenAI__ChatModelId: ${{ vars.OPENAI__CHATMODELID }}
108108
OpenAI__ChatReasoningModelId: ${{ vars.OPENAI__CHATREASONINGMODELID }}

‎.github/workflows/python-integration-tests.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ jobs:
509509
contents: read
510510
timeout-minutes: 60
511511
env:
512-
COPILOT_GITHUB_TOKEN: ${{ github.token }}
512+
GITHUB_TOKEN: ${{ github.token }}
513513
GITHUB_COPILOT_TIMEOUT: "120"
514514
defaults:
515515
run:

‎.github/workflows/python-merge-tests.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ jobs:
680680
contents: read
681681
timeout-minutes: 60
682682
env:
683-
COPILOT_GITHUB_TOKEN: ${{ github.token }}
683+
GITHUB_TOKEN: ${{ github.token }}
684684
GITHUB_COPILOT_TIMEOUT: "120"
685685
defaults:
686686
run:

‎.github/workflows/python-sample-validation.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ jobs:
240240
contents: read
241241
id-token: write
242242
env:
243-
COPILOT_GITHUB_TOKEN: ${{ github.token }}
243+
GITHUB_TOKEN: ${{ github.token }}
244244
GITHUB_COPILOT_MODEL: claude-opus-4.6
245245
defaults:
246246
run:

‎dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.IntegrationTests/GitHubCopilotAgentTests.cs‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,20 @@ public class GitHubCopilotAgentTests
1515
{
1616
private static void SkipIfCopilotNotConfigured()
1717
{
18-
if (string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("COPILOT_GITHUB_TOKEN")))
18+
bool actionsAuth =
19+
string.Equals(Environment.GetEnvironmentVariable("GITHUB_ACTIONS"), "true", StringComparison.OrdinalIgnoreCase) &&
20+
!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("GITHUB_TOKEN"));
21+
bool localOptIn =
22+
string.Equals(
23+
Environment.GetEnvironmentVariable("RUN_COPILOT_INTEGRATION_TESTS"),
24+
"true",
25+
StringComparison.OrdinalIgnoreCase);
26+
27+
if (!actionsAuth && !localOptIn)
1928
{
20-
Assert.Skip("COPILOT_GITHUB_TOKEN not set; skipping GitHub Copilot integration tests.");
29+
Assert.Skip(
30+
"GitHub Actions auth is unavailable and RUN_COPILOT_INTEGRATION_TESTS is not true; " +
31+
"skipping GitHub Copilot integration tests.");
2132
}
2233
}
2334

‎python/packages/github_copilot/tests/test_github_copilot_agent.py‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,11 +3475,44 @@ def test_prepare_attachments_skips_non_base64_data_uri(self) -> None:
34753475

34763476

34773477
# ---------------------------------------------------------------------------
3478-
# Integration tests — require COPILOT_GITHUB_TOKEN env var
3478+
# Integration tests — require GitHub Actions auth or explicit local opt-in
34793479
# ---------------------------------------------------------------------------
3480+
def _copilot_integration_configured() -> bool:
3481+
actions_auth = os.getenv("GITHUB_ACTIONS", "").lower() == "true" and bool(os.getenv("GITHUB_TOKEN", "").strip())
3482+
local_opt_in = os.getenv("RUN_COPILOT_INTEGRATION_TESTS", "").lower() == "true"
3483+
return actions_auth or local_opt_in
3484+
3485+
3486+
@pytest.mark.parametrize(
3487+
("environment", "expected"),
3488+
[
3489+
({}, False),
3490+
({"GITHUB_TOKEN": "unrelated-token"}, False),
3491+
({"GITHUB_ACTIONS": "true"}, False),
3492+
({"GITHUB_ACTIONS": "true", "GITHUB_TOKEN": "actions-token"}, True),
3493+
({"RUN_COPILOT_INTEGRATION_TESTS": "true"}, True),
3494+
],
3495+
)
3496+
def test_copilot_integration_configured(
3497+
monkeypatch: pytest.MonkeyPatch,
3498+
environment: dict[str, str],
3499+
expected: bool,
3500+
) -> None:
3501+
"""Integration tests require Actions auth or an explicit local opt-in."""
3502+
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
3503+
monkeypatch.delenv("GITHUB_TOKEN", raising=False)
3504+
monkeypatch.delenv("RUN_COPILOT_INTEGRATION_TESTS", raising=False)
3505+
for name, value in environment.items():
3506+
monkeypatch.setenv(name, value)
3507+
3508+
assert _copilot_integration_configured() is expected
3509+
3510+
34803511
skip_if_copilot_integration_tests_disabled = pytest.mark.skipif(
3481-
os.getenv("COPILOT_GITHUB_TOKEN", "") == "",
3482-
reason="No COPILOT_GITHUB_TOKEN provided; skipping integration tests.",
3512+
not _copilot_integration_configured(),
3513+
reason=(
3514+
"GitHub Actions auth is unavailable and RUN_COPILOT_INTEGRATION_TESTS is not true; skipping integration tests."
3515+
),
34833516
)
34843517

34853518

0 commit comments

Comments
 (0)