diff --git a/.github/workflows/dotnet-integration-tests.yml b/.github/workflows/dotnet-integration-tests.yml index b83a3d9423..fad2b7a671 100644 --- a/.github/workflows/dotnet-integration-tests.yml +++ b/.github/workflows/dotnet-integration-tests.yml @@ -102,7 +102,7 @@ jobs: env: COSMOSDB_ENDPOINT: https://localhost:8081 COSMOSDB_KEY: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw== - COPILOT_GITHUB_TOKEN: ${{ github.token }} + GITHUB_TOKEN: ${{ github.token }} OpenAI__ApiKey: ${{ secrets.OPENAI__APIKEY }} OpenAI__ChatModelId: ${{ vars.OPENAI__CHATMODELID }} OpenAI__ChatReasoningModelId: ${{ vars.OPENAI__CHATREASONINGMODELID }} diff --git a/.github/workflows/python-integration-tests.yml b/.github/workflows/python-integration-tests.yml index 667a8041bd..3308f294dc 100644 --- a/.github/workflows/python-integration-tests.yml +++ b/.github/workflows/python-integration-tests.yml @@ -509,7 +509,7 @@ jobs: contents: read timeout-minutes: 60 env: - COPILOT_GITHUB_TOKEN: ${{ github.token }} + GITHUB_TOKEN: ${{ github.token }} GITHUB_COPILOT_TIMEOUT: "120" defaults: run: diff --git a/.github/workflows/python-merge-tests.yml b/.github/workflows/python-merge-tests.yml index a91da6e265..7db1c4a641 100644 --- a/.github/workflows/python-merge-tests.yml +++ b/.github/workflows/python-merge-tests.yml @@ -680,7 +680,7 @@ jobs: contents: read timeout-minutes: 60 env: - COPILOT_GITHUB_TOKEN: ${{ github.token }} + GITHUB_TOKEN: ${{ github.token }} GITHUB_COPILOT_TIMEOUT: "120" defaults: run: diff --git a/.github/workflows/python-sample-validation.yml b/.github/workflows/python-sample-validation.yml index 686100cff3..8c0ab1b7cf 100644 --- a/.github/workflows/python-sample-validation.yml +++ b/.github/workflows/python-sample-validation.yml @@ -240,7 +240,7 @@ jobs: contents: read id-token: write env: - COPILOT_GITHUB_TOKEN: ${{ github.token }} + GITHUB_TOKEN: ${{ github.token }} GITHUB_COPILOT_MODEL: claude-opus-4.6 defaults: run: diff --git a/dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.IntegrationTests/GitHubCopilotAgentTests.cs b/dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.IntegrationTests/GitHubCopilotAgentTests.cs index c1599012f0..57a604750d 100644 --- a/dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.IntegrationTests/GitHubCopilotAgentTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.IntegrationTests/GitHubCopilotAgentTests.cs @@ -15,9 +15,20 @@ public class GitHubCopilotAgentTests { private static void SkipIfCopilotNotConfigured() { - if (string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("COPILOT_GITHUB_TOKEN"))) + bool actionsAuth = + string.Equals(Environment.GetEnvironmentVariable("GITHUB_ACTIONS"), "true", StringComparison.OrdinalIgnoreCase) && + !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("GITHUB_TOKEN")); + bool localOptIn = + string.Equals( + Environment.GetEnvironmentVariable("RUN_COPILOT_INTEGRATION_TESTS"), + "true", + StringComparison.OrdinalIgnoreCase); + + if (!actionsAuth && !localOptIn) { - Assert.Skip("COPILOT_GITHUB_TOKEN not set; skipping GitHub Copilot integration tests."); + Assert.Skip( + "GitHub Actions auth is unavailable and RUN_COPILOT_INTEGRATION_TESTS is not true; " + + "skipping GitHub Copilot integration tests."); } } diff --git a/python/packages/github_copilot/tests/test_github_copilot_agent.py b/python/packages/github_copilot/tests/test_github_copilot_agent.py index 559180856f..5fe74410a9 100644 --- a/python/packages/github_copilot/tests/test_github_copilot_agent.py +++ b/python/packages/github_copilot/tests/test_github_copilot_agent.py @@ -3475,11 +3475,44 @@ def test_prepare_attachments_skips_non_base64_data_uri(self) -> None: # --------------------------------------------------------------------------- -# Integration tests — require COPILOT_GITHUB_TOKEN env var +# Integration tests — require GitHub Actions auth or explicit local opt-in # --------------------------------------------------------------------------- +def _copilot_integration_configured() -> bool: + actions_auth = os.getenv("GITHUB_ACTIONS", "").lower() == "true" and bool(os.getenv("GITHUB_TOKEN", "").strip()) + local_opt_in = os.getenv("RUN_COPILOT_INTEGRATION_TESTS", "").lower() == "true" + return actions_auth or local_opt_in + + +@pytest.mark.parametrize( + ("environment", "expected"), + [ + ({}, False), + ({"GITHUB_TOKEN": "unrelated-token"}, False), + ({"GITHUB_ACTIONS": "true"}, False), + ({"GITHUB_ACTIONS": "true", "GITHUB_TOKEN": "actions-token"}, True), + ({"RUN_COPILOT_INTEGRATION_TESTS": "true"}, True), + ], +) +def test_copilot_integration_configured( + monkeypatch: pytest.MonkeyPatch, + environment: dict[str, str], + expected: bool, +) -> None: + """Integration tests require Actions auth or an explicit local opt-in.""" + monkeypatch.delenv("GITHUB_ACTIONS", raising=False) + monkeypatch.delenv("GITHUB_TOKEN", raising=False) + monkeypatch.delenv("RUN_COPILOT_INTEGRATION_TESTS", raising=False) + for name, value in environment.items(): + monkeypatch.setenv(name, value) + + assert _copilot_integration_configured() is expected + + skip_if_copilot_integration_tests_disabled = pytest.mark.skipif( - os.getenv("COPILOT_GITHUB_TOKEN", "") == "", - reason="No COPILOT_GITHUB_TOKEN provided; skipping integration tests.", + not _copilot_integration_configured(), + reason=( + "GitHub Actions auth is unavailable and RUN_COPILOT_INTEGRATION_TESTS is not true; skipping integration tests." + ), )