test: share account fixtures + a canonical TokenStore mock#47
Merged
Conversation
Consolidates duplicated test scaffolding across the auth suites:
- New src/test-support/accounts.ts: TestAccount type + Ingen account
fixtures (alanGrant/ellieSattler/ianMalcolm/johnHammond) and a single
stateful buildTokenStore covering the full TokenStore contract
(active/set/clear→ClearedAccount/list/setDefault + optional
activeBundle/setBundle), with id/email/label matching, an overrides
splat, per-method spies and live state.
- New src/test-support/cli-harness.ts: installConsoleLogSpy /
installStdoutSpy and a buildProgram() Commander scaffold helper.
- Migrate account/status/logout/token-view/user-flag/flow/login/refresh/
persist/pkce tests onto the shared fixtures + builder + harness,
removing ~10 duplicate Account types, the ad-hoc account fixtures, 8
bespoke store builders, and the repeated console-spy + program scaffold.
Keyring tests keep their numeric record-key doubles (id woven into
records.get('42')-style assertions; not display identities) and dcr/
internal keep their non-standard account shapes. Pure refactor — no
behavior change.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
doistbot
reviewed
May 23, 2026
Member
doistbot
left a comment
There was a problem hiding this comment.
This PR significantly cleans up the auth test suites by consolidating duplicated account fixtures and TokenStore mocks into shared internal helpers. Centralizing the Commander scaffolds and standardizing on the new test identities greatly improves test readability and maintainability. A few refinements are noted below to ensure the mock store accurately mirrors production default-selection and replacement semantics, tighten up TypeScript generics and imports, and resolve a couple of minor redundancies and dead exports.
Drop the setSpy / activeBundleSpy / setBundleSpy handles from the returned harness (no test reads them — refresh asserts via state.setBundleCalls, flow makes its own spy) and stop exporting the internal ingenEntries default seed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Only three account fixtures are needed; remove the fourth. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
scottlovegrove
commented
May 23, 2026
- buildTokenStore now mirrors KeyringTokenStore's default-selection: effective default = pinned ?? sole account; promote only when unpinned; set/setBundle replace the prior credential shape (drop the stale slot). Removes states production can't produce (a lone survivor is now the effective default after the pinned account is removed). - Tighten the API with overloads so the default Ingen seed only applies to TestAccount; other TAccounts must pass explicit entries (drops the unsound cast at call sites). - Reuse accountNotFoundError() from auth/user-flag so the mock's ACCOUNT_NOT_FOUND wording can't drift from production. - Add buildSingleEntryStore() and adopt it in logout/status/token-view/ user-flag; share ingenEntries() for account.test's fixture; extract an installSpy() lifecycle factory; name the repeated build-helper return type; assert both write paths stay untouched in flow's abort test. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
A descriptive "what is where" orientation file (companion to AGENTS.md's "how to change"), modelled on todoist-cli's CODEBASE.md but adapted for a library: subpath-export surface, the auth/keyring layout, the attacher pattern, the TokenStore contract, and the test-support harness. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
🎉 This PR is included in version 0.24.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A test-suite audit found heavy, mechanical duplication across the auth suites: ~10 redeclared
type Account, ~18 ad-hoc account fixtures, 8 bespokeTokenStoremock builders, and repeated console-spy + Commander-scaffold boilerplate.Test plan
npm run build(tsc) +npm run type-checknpm test— 498 pass (pure refactor, no behaviour change)npm run check(oxlint + oxfmt) clean🤖 Generated with Claude Code