Skip to content

refactor(db): one refreshing-value helper for cloud credential caches - #2302

Merged
cevheri merged 2 commits into
mainfrom
refactor/db-auth-refresh
Nov 15, 2026
Merged

cevheri merged 2 commits into
mainfrom
refactor/db-auth-refresh

Conversation

@cevheri

@cevheri cevheri commented Nov 15, 2026

Copy link
Copy Markdown
Member

Moves the Google token source's cache and refresh logic into src/lib/db/auth/refresh.ts as createRefreshingValue, so the next cloud credential that expires (such as a temporary database password) reuses one implementation instead of copying it.
Behaviour is unchanged: tests/unit/db/auth/google/token-source.test.ts passes without a single edit.

What changes

  • src/lib/db/auth/refresh.ts is new and holds what the token source kept inline: the cached value served until expiresAt - earlyMs, one shared refresh on its own 30-second deadline combined with close(), a caller's own abort that rejects only that caller (with the same two TransportError sentences), nothing cached from a failed refresh, and close().
    RefreshRun (the refresh's signal and throwIfClosed()) and the private untilAborted move with it unchanged.
    throwIfClosed() still reads close() alone, so a deadline that fires while a key is signed is reported as a timeout, never as closed.
  • src/lib/db/auth/google/token-source.ts keeps its strategies, lanes and token-answer parsing and hands the cache to createRefreshingValue with its 60-second margin and its closed sentence; close() still closes every lane it built.
  • tests/unit/db/auth/refresh.test.ts covers the helper on its own: single flight with one deadline, the early-refresh boundary at exactly expiresAt - earlyMs, the deadline, one caller's abort leaving the others, a failure caching nothing, close() during a refresh, get() after close(), and a deadline during a step that takes no signal.
  • tests/unit/db/auth/seam-guard.test.ts lists the new layer file.
  • docs/DB_AUTH.md gains a Root pieces row and a "Shared refresh" section; the auth/ line of docs/ARCHITECTURE.md names refresh.ts.

User-visible change

None.

Test plan

bun tests/run-tests.ts tests/unit/db/auth/refresh.test.ts
bun tests/run-tests.ts tests/unit/db/auth/google/token-source.test.ts
bun tests/run-tests.ts tests/unit/db/auth/google/credentials.test.ts
bun tests/run-tests.ts tests/unit/db/auth/seam-guard.test.ts
bun tests/run-tests.ts tests/integration/db/firestore-provider.test.ts
bun tests/run-tests.ts tests/unit/db/firestore/provider-doc.test.ts
SEED_CONFIG_PATH= heavy bun tests/run-tests.ts tests/unit/db/auth
(cd vscode-extension && npm ci --ignore-scripts) && bun run format && bun run lint && bun run typecheck && bun run knip && bun run chart:check && bun run channels:showcase:check && bun run readme:check && bun run security:check && bun run test && bun run build
bun run test:coverage && bun run coverage:check
bun run build:lib && bun run attw && bun run lib:closure
(cd vscode-extension && npm run build)

Move the Google token source's cache, 60-second early refresh, shared
refresh on its own 30-second deadline, caller abort handling and close()
into src/lib/db/auth/refresh.ts as createRefreshingValue, so the next
cloud credential that expires reuses it instead of a second copy.
Behaviour is unchanged; the Google token-source tests pass as they were.
Review round 1: pin one deadline per shared refresh, name the close()
test after what it proves, and rewrap the token source docblock.
@codecov

codecov Bot commented Nov 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sonarqubecloud

Copy link
Copy Markdown

@cevheri
cevheri merged commit afe31f3 into main Nov 15, 2026
29 checks passed
@cevheri
cevheri deleted the refactor/db-auth-refresh branch November 15, 2026 05:59
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