Python: Fix Actions token environment (#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
This commit is contained in:
Evan Mattson
2026-07-30 18:57:23 +09:00
committed by GitHub
parent 59fe8bedeb
commit d07edffaed
6 changed files with 53 additions and 9 deletions
@@ -3475,11 +3475,44 @@ class TestGitHubCopilotAttachments:
# ---------------------------------------------------------------------------
# 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."
),
)