Skip to content

Fix ASTRO_API_TOKEN context expiry set ~57 years out instead of ~1 year - #2217

Open
jlaneve wants to merge 1 commit into
mainfrom
fix/api-token-expiry
Open

Fix ASTRO_API_TOKEN context expiry set ~57 years out instead of ~1 year#2217
jlaneve wants to merge 1 commit into
mainfrom
fix/api-token-expiry

Conversation

@jlaneve

@jlaneve jlaneve commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Description

SetExpiresIn adds its argument to time.Now() as a count of seconds, but the ASTRO_API_TOKEN path passed it a Unix timestamp (time.Now().AddDate(1, 0, 0).Unix()), landing the stored expiry around the year 2083. Once written to ~/.astro/config.yaml, that context was never considered expired, so refresh and re-auth logic never fired for it.

What changed: SetExpiresIn now takes a time.Duration, so the unit lives in the type and this class of mistake stops being expressible. All four callers were converted; the buggy site now passes 365 * 24 * time.Hour.

Breaking changes

  • Contexts written via ASTRO_API_TOKEN now actually expire about a year out. Day-to-day use is unaffected — the env-var path rewrites the expiry on every command.
  • Already-written far-future expiries are not retroactively repaired; they get overwritten on the next run.
  • Context.SetExpiresIn changed signature from (int64) to (time.Duration) — a Go API change for anyone importing config directly.

Testing

New subtest runs the ASTRO_API_TOKEN path and asserts the stored expiry lands within an hour of one year out (it would have landed in 2083 before). go build ./..., go test ./cmd/... ./config/... ./cloud/auth/..., go vet, and make lint pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01P6DEdUpFBFaAiPKEu81Wti

setup.go passed SetExpiresIn a Unix timestamp (time.Now().AddDate(1,0,0).Unix(),
~1.8 billion) while SetExpiresIn treated its argument as a count of seconds to
add to now. The result: contexts written by ASTRO_API_TOKEN got an expiry
around year 2083 and were never treated as expired, so refresh/re-auth never
triggered.

SetExpiresIn now takes a time.Duration instead of a bare int64, so the unit is
part of the type and this mistake can't be expressed again. Converted its four
callers (setup.go's token-refresh and API-key paths, cloud/auth's OAuth
result handler, and the ASTRO_API_TOKEN path, which now passes
365 * 24 * time.Hour) plus the three test call sites. Added a test that
asserts the ASTRO_API_TOKEN path's stored expiry lands within an hour of one
year out, not decades.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jlaneve
jlaneve requested a review from a team as a code owner July 21, 2026 19:35
@coveralls-official

Copy link
Copy Markdown

Coverage Report for CI Build 29862132715

Coverage remained the same at 43.883%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: 1 uncovered change across 1 file (5 of 6 lines covered, 83.33%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
cmd/cloud/setup.go 3 2 66.67%
Total (3 files) 6 5 83.33%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 59018
Covered Lines: 25899
Line Coverage: 43.88%
Coverage Strength: 8.6 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant