Repository navigation
Age GitHub App tokens with suspend-aware elapsed time #1209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5a35ab2
e055863
eccddc8
db8afa5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -178,3 +178,21 @@ def test_strict_fake_matches_input_contents(fake_bin: Path, tmp_path: Path) -> N | |
| ) | ||
| github.update_body(REPO, 7, "new body") | ||
| fake.assert_complete() | ||
|
|
||
|
|
||
| def test_app_token_expires_after_wall_clock_rollback(tmp_path, monkeypatch): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Rollback regression test is in the gh contract suite instead of next to the other app-token tests
|
||
| helper = tmp_path / "app-token" | ||
| counter = tmp_path / "helper-calls" | ||
| helper.write_text(f'#!/bin/sh\necho called >> "{counter}"\nwc -l < "{counter}"\n') | ||
| helper.chmod(0o755) | ||
| monkeypatch.setattr(github, "APP_TOKEN_HELPER", helper) | ||
| wall_time = 10_000.0 | ||
| boot_time = 10_000.0 | ||
| monkeypatch.setattr(github.time, "time", lambda: wall_time) | ||
| monkeypatch.setattr(github.time, "CLOCK_BOOTTIME", 7, raising=False) | ||
| monkeypatch.setattr(github.time, "clock_gettime", lambda _clock_id: boot_time) | ||
| assert github.app_token() == "1" | ||
| assert github.app_token() == "1" | ||
| wall_time += 2_620 | ||
| boot_time += 3_620 | ||
| assert github.app_token() == "2" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: No test covers the path for hosts without a suspend-aware clock
When
_app_token_clock()returns None (notime.CLOCK_BOOTTIME, orclock_gettimeraises OSError),app_token()now returns the minted token without caching it. Every later call then runs the helper again. That includes_refresh_publisher_token(cli.py:862), which will always see a different token and callloginagain. This matches the task notes, but no test pins it down. A later change could start caching(token, None)or comparing against None without any test failing. Smallest fix: add a test that deletesCLOCK_BOOTTIMEwithmonkeypatch.delattr(github.time, 'CLOCK_BOOTTIME', raising=False), then checks that two calls run the helper twice and that_app_token_cachestays empty.