Skip to content

fix(auth,release): token validation/refresh + env fallback; wire finalize into canonical CI#8

Merged
daniel-garcia merged 2 commits into
mainfrom
fix-auth-token-persistence
Jun 10, 2026
Merged

fix(auth,release): token validation/refresh + env fallback; wire finalize into canonical CI#8
daniel-garcia merged 2 commits into
mainfrom
fix-auth-token-persistence

Conversation

@daniel-garcia

Copy link
Copy Markdown
Contributor

What

Fixes findings #4 and #2 of #5 — the last two pieces needed for an end-to-end working release pipeline (after #6 and #7).

Auth (finding #4)

apx auth login previously reported Authenticated successfully while returning a dead cached token: EnsureToken trusted any cached token unconditionally, GitHub-App user tokens (ghu_) expire, no refresh token was ever persisted, and there was no env-token escape hatch. Now:

  • Expiry-aware tokens — device-flow responses persist expires_in / refresh_token / refresh_token_expires_in; expiring tokens are checked by clock (60s skew).
  • Legacy tokens live-validated — cache files without expiry metadata are checked against GET /user; only a definitive 401 invalidates (offline use unaffected).
  • Refresh grant — expired tokens are renewed via grant_type=refresh_token when possible; otherwise the stale token is evicted so the device flow actually re-runs.
  • Env fallbackAPX_GITHUB_TOKEN > GH_TOKEN > GITHUB_TOKEN override the cache entirely (CI-friendly; also honored by the non-interactive remote-config path).
  • Truthful auth status — expired tokens now report token expired (issued …) — run apx auth login instead of authenticated.

Release finalize in CI (finding #2)

No canonical workflow ever invoked apx release finalize, so merging a release PR never cut a tag (both canonical repos had zero tags). Now:

  • apx release finalize --api <id> --version <v> — CI mode that reconstructs the manifest exactly like prepare does (identity + language coords; lifecycle inferred from the version's prerelease, overridable; --commit selects the tag target). Needed because the producer's local .apx-release.yaml doesn't exist in canonical CI.
  • Generated release-finalize.yml — new canonical workflow (written by apx init canonical and apx workflows): on merged PRs from apx/release/* branches it parses the release coordinates from the PR title, runs CI-mode finalize on the merge commit, pushes the canonical tag, and uploads the release record artifact.

Verified

  • Full suite green with a freshly built binary (go test . ./internal/... ./cmd/... — includes the testscripts).
  • Functional end-to-end: scratch canonical repo → init canonical (generates all three workflows) → real schema → apx release finalize --api proto/payments/ledger/v1 --version v1.0.0-beta.1 → lint/policy pass, tag proto/payments/ledger/v1.0.0-beta.1 cut (correct post-fix(release): derive release tag from the normalized Go-module subdir (v0/v1) #7 format), release record written.

Closes #5.

…CI finalize

Auth (issue #5 finding 4): EnsureToken no longer trusts a cached token
blindly — expiring tokens are checked by clock, legacy tokens are validated
against the API, and stale tokens are refreshed via the refresh-token grant
or evicted so the device flow re-runs. Device-flow responses now persist
expires_in/refresh_token. APX_GITHUB_TOKEN/GH_TOKEN/GITHUB_TOKEN override
the cache entirely (CI escape hatch), and auth status reports expired
tokens instead of claiming they are authenticated.

Release (issue #5 finding 2): 'apx release finalize --api <id> --version
<v>' reconstructs the manifest in CI where the producer's local manifest
does not exist, and canonical repos now get a generated
release-finalize.yml workflow that tags the release when a release PR
merges — previously no workflow ever ran finalize, so no canonical tag was
ever cut.
…de in tests on Windows

Tool auto-download requested asset names that do not exist upstream:
buf spells arm64 as aarch64 only on Linux (Darwin/Windows use arm64) and
ships Windows binaries as bare .exe files, while oasdiff uses Go-style
amd64/arm64 names and a universal darwin_all build. The shared
{OS}/{ARCH} pattern produced 404s ('tool not found') on macOS arm64 and
Windows for buf, and everywhere for oasdiff. Replace the pattern with
per-tool assetName functions verified against the projects' releases.

Also fix config tests overriding HOME, which Windows ignores
(os.UserHomeDir reads USERPROFILE), leaking the real home into tests.
@codecov-commenter

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@daniel-garcia daniel-garcia merged commit 3b7e4ff into main Jun 10, 2026
8 checks passed
@daniel-garcia daniel-garcia deleted the fix-auth-token-persistence branch June 10, 2026 13:03
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.

release finalize fails on proto-module repos (buf invocation) + 3 related release-pipeline gaps

2 participants