Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/loopzero/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from loopzero.types import BLOCKING, Finding, ReviewResult

GH_BASE_ENV = ("PATH", "HOME", "LANG", "LC_ALL", "TERM", "GH_HOST")
GH_ENV = (*GH_BASE_ENV, "GH_TOKEN", "GITHUB_TOKEN")
GH_ENV = (*GH_BASE_ENV, "GH_TOKEN", "GITHUB_TOKEN", "GH_CONFIG_DIR", "XDG_CONFIG_HOME")
APP_TOKEN_HELPER = Path.home() / ".config/loopzero/app-token"
_app_token_cache = ("", 0.0)
MISSING_REVIEW_REASON = "no review recorded for the current head"
Expand Down
2 changes: 1 addition & 1 deletion tests/fake_gh.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def replay(
argv: list[str], calls: str, scenario: str, cwd: str, token: str | None,
) -> tuple[int, str, str]:
record = {"argv": argv, "token": token}
record = dict(argv=argv, token=token, config=[os.getenv(k) for k in ("GH_CONFIG_DIR", "XDG_CONFIG_HOME")])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: In-process replay records the host's config variables, not the allowlisted ones

replay gets config by calling os.getenv in whatever process runs it. The subprocess fake (tests/test_github.py:50-55) runs as a child of run(..., env_allowlist=GH_ENV), so there the value reflects GH_ENV correctly, and that is the path test_app_identity_selection_and_cache checks. The in-process replay_gh fixture (tests/test_cli.py:160-172) is different: it works out GH_TOKEN from build_env(env_allowlist, extra_env) but calls replay inside the pytest process. Its recorded config therefore shows the test host's environment even when the allowlist would drop those variables. Nothing asserts on it today, but a later test that checks config under replay_gh would pass even if the allowlist were wrong. Smallest fix: pass the environment into replay the same way the token is passed, e.g. an env mapping (the build_env(...) result in-process, os.environ in the script), and read both selectors from that mapping instead of the global environment.

input_files = {}
for flag in ("--input", "--body-file"):
if flag in argv:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,8 @@ def test_app_identity_selection_and_cache(gh: FakeGh, tmp_path: Path, monkeypatc
monkeypatch.setattr(github.time, "CLOCK_BOOTTIME", 7, raising=False)
monkeypatch.setattr(github.time, "clock_gettime", lambda _: boot_time)
monkeypatch.setattr(github.time, "monotonic", lambda: 100.0) # stopped during host suspend
monkeypatch.setenv("GH_CONFIG_DIR", "/fixture/gh")
monkeypatch.setenv("XDG_CONFIG_HOME", "/fixture/xdg")
monkeypatch.setenv("GH_TOKEN", "operator-token")
gh.respond("api repos/acme/widgets", {})
gh.respond("api graphql viewer", {"data": {"viewer": {"login": "app[bot]"}}})
Expand All @@ -752,10 +754,8 @@ def test_app_identity_selection_and_cache(gh: FakeGh, tmp_path: Path, monkeypatc
github._gh("api", "repos/acme/widgets/issues/7/comments", "--method", "POST")
github._gh("api", "graphql", "-f", "query=mutation { resolveReviewThread(input: {}) { clientMutationId } }")
assert github.auth_token() == "operator-token"
assert [c["token"] for c in gh.calls] == [
"synthetic-app-token", "synthetic-app-token", "synthetic-app-token",
"operator-token", "operator-token", "operator-token",
]
assert [c["token"] for c in gh.calls] == ["synthetic-app-token"] * 3 + ["operator-token"] * 3
assert all(call["config"] == ["/fixture/gh", "/fixture/xdg"] for call in gh.calls)
assert counter.read_text().splitlines() == ["called"]
boot_time += 3_620
wall_time += 2_620 # The wall clock stepped back by a thousand seconds.
Expand Down
Loading