From e0f50fd47d256746f030877515fde1691344c434 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Thu, 12 Feb 2026 11:26:06 -0800 Subject: [PATCH] fix(python): always use fake token in E2E tests to prevent hang MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The E2E test harness overrides XDG_CONFIG_HOME to an isolated temp directory. When running locally (not CI), github_token was None, so the CLI defaulted to use_logged_in_user=True but found no credentials in the empty temp dir. This caused a silent auth failure — the CLI logged 'Session was not created with authentication info' but never emitted a session.error event, making send_and_wait() hang forever. Since E2E tests use a replaying proxy with canned responses, real auth is never needed. Always pass the fake token. --- python/e2e/test_session.py | 5 ++--- python/e2e/testharness/__init__.py | 3 ++- python/e2e/testharness/context.py | 10 +++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/python/e2e/test_session.py b/python/e2e/test_session.py index f2e545ed..84437d03 100644 --- a/python/e2e/test_session.py +++ b/python/e2e/test_session.py @@ -7,7 +7,7 @@ from copilot import CopilotClient from copilot.types import Tool -from .testharness import E2ETestContext, get_final_assistant_message, get_next_event_of_type +from .testharness import E2E_FAKE_GITHUB_TOKEN, E2ETestContext, get_final_assistant_message, get_next_event_of_type pytestmark = pytest.mark.asyncio(loop_scope="module") @@ -160,13 +160,12 @@ async def test_should_resume_a_session_using_a_new_client(self, ctx: E2ETestCont assert "2" in answer.data.content # Resume using a new client - github_token = "fake-token-for-e2e-tests" if os.environ.get("CI") == "true" else None new_client = CopilotClient( { "cli_path": ctx.cli_path, "cwd": ctx.work_dir, "env": ctx.get_env(), - "github_token": github_token, + "github_token": E2E_FAKE_GITHUB_TOKEN, } ) diff --git a/python/e2e/testharness/__init__.py b/python/e2e/testharness/__init__.py index 58a36028..8a0f8e8a 100644 --- a/python/e2e/testharness/__init__.py +++ b/python/e2e/testharness/__init__.py @@ -1,11 +1,12 @@ """Test harness for E2E tests.""" -from .context import CLI_PATH, E2ETestContext +from .context import CLI_PATH, E2E_FAKE_GITHUB_TOKEN, E2ETestContext from .helper import get_final_assistant_message, get_next_event_of_type from .proxy import CapiProxy __all__ = [ "CLI_PATH", + "E2E_FAKE_GITHUB_TOKEN", "E2ETestContext", "CapiProxy", "get_final_assistant_message", diff --git a/python/e2e/testharness/context.py b/python/e2e/testharness/context.py index 533ee87e..a397945b 100644 --- a/python/e2e/testharness/context.py +++ b/python/e2e/testharness/context.py @@ -30,6 +30,12 @@ def get_cli_path_for_tests() -> str: CLI_PATH = get_cli_path_for_tests() SNAPSHOTS_DIR = Path(__file__).parents[3] / "test" / "snapshots" +# E2E tests use a replaying proxy with canned responses, so real auth is +# never needed. Without a token the CLI looks for credentials under +# XDG_CONFIG_HOME, which points to an isolated temp dir and is therefore +# empty, causing a silent auth failure that makes tests hang. +E2E_FAKE_GITHUB_TOKEN = "fake-token-for-e2e-tests" + class E2ETestContext: """Holds shared resources for E2E tests.""" @@ -53,14 +59,12 @@ async def setup(self): self.proxy_url = await self._proxy.start() # Create the shared client (like Node.js/Go do) - # Use fake token in CI to allow cached responses without real auth - github_token = "fake-token-for-e2e-tests" if os.environ.get("CI") == "true" else None self._client = CopilotClient( { "cli_path": self.cli_path, "cwd": self.work_dir, "env": self.get_env(), - "github_token": github_token, + "github_token": E2E_FAKE_GITHUB_TOKEN, } )