Skip to content

test: share account fixtures + a canonical TokenStore mock#47

Merged
scottlovegrove merged 5 commits into
mainfrom
test/shared-account-fixtures
May 23, 2026
Merged

test: share account fixtures + a canonical TokenStore mock#47
scottlovegrove merged 5 commits into
mainfrom
test/shared-account-fixtures

Conversation

@scottlovegrove
Copy link
Copy Markdown
Collaborator

@scottlovegrove scottlovegrove commented May 23, 2026

Summary

A test-suite audit found heavy, mechanical duplication across the auth suites: ~10 redeclared type Account, ~18 ad-hoc account fixtures, 8 bespoke TokenStore mock builders, and repeated console-spy + Commander-scaffold boilerplate.

Test plan

  • npm run build (tsc) + npm run type-check
  • npm test498 pass (pure refactor, no behaviour change)
  • npm run check (oxlint + oxfmt) clean

🤖 Generated with Claude Code

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>
Copy link
Copy Markdown
Member

@doistbot doistbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Share FeedbackReview Logs

Comment thread src/test-support/accounts.ts Outdated
Comment thread src/test-support/accounts.ts
Comment thread src/test-support/accounts.ts
Comment thread src/test-support/cli-harness.ts
Comment thread src/auth/logout.test.ts Outdated
Comment thread src/auth/account.test.ts Outdated
Comment thread src/test-support/accounts.ts Outdated
Comment thread src/auth/account.test.ts Outdated
Comment thread src/test-support/accounts.ts Outdated
Comment thread src/auth/flow.test.ts
scottlovegrove and others added 2 commits May 23, 2026 18:00
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>
Comment thread src/auth/account.test.ts Outdated
Comment thread src/test-support/accounts.ts Outdated
scottlovegrove and others added 2 commits May 23, 2026 18:19
- 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>
@scottlovegrove scottlovegrove merged commit 6ceca7b into main May 23, 2026
4 checks passed
@scottlovegrove scottlovegrove deleted the test/shared-account-fixtures branch May 23, 2026 17:39
@doist-release-bot
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.24.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants