test(oauth): cover credential-generation compare-and-set helpers - #246
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 2, 2026, 12:40 PM ET / 16:40 UTC. ClawSweeper reviewWhat this changesThe branch adds a 15-case Vitest suite for OAuth token and client generation helpers, including hidden serialization and compare-and-set stale-write rejection behavior. Merge readinessThis PR is still necessary: current Likely related people: Priority: P3 Review scores
Verification
How this fits togetherOAuth credential persistence stamps token and dynamic-client records with opaque generations so concurrent writes across vault and persistence backends can use compare-and-set behavior. The helpers hide the internal marker from OAuth-facing values while preserving it for recovery and stale-write detection. flowchart LR
A[OAuth token or client] --> B[Generation helper]
B --> C[Vault and persistence writes]
C --> D[Compare generation and public value]
D --> E[Accept current write]
D --> F[Reject stale write]
B --> G[Hidden marker for API values]
Before merge
Agent review detailsSecurityNone. Review metrics
Technical reviewBest possible solution: Clear the draft state and land the focused regression coverage after confirming the existing successful checks still apply to the exact head. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR adds direct regression coverage rather than repairing a reported runtime failure; the supplied live runs show the new tests execute against the real helpers. Is this the best way to solve the issue? Yes: direct unit coverage of the exported helpers is the narrowest maintainable way to lock down the established compare-and-set contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against e1689c3dec7c. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (15 earlier review cycles; latest 8 shown)
|
|
Maintainer repair and verification are complete at I added the two missing client-side compare-and-set cases from review: restamping preserves an existing client generation, and a changed public client value is rejected even when it carries the same generation. I also removed the redundant assertion-restatement comments. The contributor's original commit remains intact. Proof on Node 26.1.0 / pnpm 10.33.2:
Maintainer disposition: LAND once exact-head CI completes successfully. |
|
Landed as ced43e4. Verification at exact head
Test-only change, so no changelog entry. Thanks @KrasimirKralev! |
What Problem This Solves
src/oauth-token-generation.tsexports eight helpers that stamp each OAuth credential save with an opaque generation marker, so the vault/persistence layer can do compare-and-set writes across multiple backing stores (oauth-vault.ts:167/173/214/308/320/363,oauth-persistence.ts). They decide which concurrent store write wins — yet shipped with no direct test coverage (they are only exercised transitively through save/load round-trips; a repo-wide search finds no test importing the module).The contract is subtle and easy to regress silently:
withOAuthTokenGeneration/withOAuthClientGenerationreuse an existing generation and only mint a new one (randomUUID) when none is present — so two independent stamps of the same value are distinct saves;withHiddenOAuthTokenGeneration/withHiddenOAuthClientGenerationmake the marker non-enumerable (hidden from JSON/API values) while keeping it readable for recovery, and return the input unchanged when there is nothing to hide;sameOAuthTokenGeneration/sameOAuthClientGenerationrequire matching generation AND matching public value when a generation is present, returnfalsefor an absent current, and fall back to deep-equality only for two legacy (generation-less) values — so a generationed value never matches a legacy one;sameOAuthTokenValue/sameOAuthClientValuecompare public values while ignoring only the internal marker.A regression in any of these — dropping the reuse, leaking the marker into serialized values, or dropping the public-value check from the compare-and-set — would let a stale write win or a live write be rejected, and would not be caught before merge.
Why This Change Was Made
Coverage-only. This adds one new file,
tests/oauth-token-generation.test.ts(+115, no production code touched), pinning all eight exported helpers' currentmainbehavior. The tests drive the real exported functions directly (no stub), asserting enumerability viaObject.keys/JSONround-trips and identity via reference checks, so they exercise the production compare-and-set path the persistence layer relies on. No new config, defaults, dependencies, or behavior — the diff is a single test file.User Impact
No user-visible or runtime change. For maintainers, the credential-generation contract now regresses loudly instead of silently: a future edit that breaks generation reuse, the hidden-marker semantics, or the generation-plus-value comparison will fail this suite.
Evidence
Linux, Node 22.22,
pnpm install --frozen-lockfilefrom source, branched off currentmain(7259c8c).13/13 pass on clean
main:Non-vacuous — the suite bites when the target is mutated (each mutation applied to
oauth-token-generation.ts, suite re-run, then reverted byte-identical):oauth-token-generation.tswithOAuthTokenGenerationalways mints (drop the reuse of an existing generation)sameOAuthTokenValuecompares full objects (stop ignoring the generation)enumerable: true)sameOAuthTokenGenerationdrops the public-value checkFormat / lint / types:
Scope note: one new
*.test.tsundertests/,+115 / -0, no production code touched. The randomness inrandomUUIDis only exercised through the deterministic distinct-vs-reuse contract (two stamps differ; a re-stamp preserves), so the suite is stable.Related: none — coverage mined from the module itself; no linked issue.
AI-assisted contribution.
Generated by Claude Code