test: adopt cli-core buildTokenStore + matchAccount in auth/account tests
@scottlovegrove is already working on this.
Since May 25, 2026.
- Dominant language
- TypeScript
- Stars
- 3
- Forks
- 1
- Avg merge
- 2h 4m
- Merged PRs (30d)
- 14
Description
Background
cli-core#49 published shared test scaffolding via @doist/cli-core/testing. twist adopted the mechanical part — createTestProgram + captureConsole — in #251, but deliberately scoped out the stateful token-store fake (matching todoist-cli#361's scope).
This issue tracks the remaining, non-mechanical half.
What
Replace the hand-rolled interaction mocks in src/commands/account/account.test.ts (and where applicable src/commands/auth/auth.test.ts, src/lib/auth.test.ts) with cli-core's stateful fake:
buildTokenStore({ entries, matchAccount })/buildSingleEntryStore(...)— returns a real in-memoryTokenStore+ spies + mutablestate.entries.- Ingen account fixtures (
alanGrant/ellieSattler/ianMalcolm) instead of hand-built account objects.
Today these tests hand-roll a storeMocks object of bare vi.fn()s and re-implement ref resolution inline (setDefault/clear via mockImplementation(async (ref) => …), account.test.ts:51-56). That logic can drift from production.
Why this is twist-specific
matchAccount was added to buildTokenStore in cli-core#49 specifically for twist — twist resolves refs by numeric id + case-insensitive label, not cli-core's default id/email/label. twist is the only conceivable caller of matchAccount in any repo (cli-core and todoist both use the default). If twist never adopts, matchAccount is a parameter no code anywhere passes — see the "delete it as YAGNI" alternative below.
Watch-out (don't regress)
Current tests assert the exact ref string reaching the store, e.g. expect(storeMocks.setDefault).toHaveBeenCalledWith('alan grant') (account.test.ts:233). That proves twist's command layer normalizes (lowercases) the ref before calling the store. A stateful fake + matchAccount can absorb that normalization — keep an explicit assertion that the command layer normalizes, so we test prod's matcher, not our mirror of it.
Decision fork
- Adopt →
matchAccountgets its first real caller; twist converges onto shared infra; bespoke inline resolution logic deleted. - Decline → flag back to cli-core to remove
matchAccountas YAGNI (keepbuildTokenStore; cli-core uses it internally).
Recommended: fold into the next PR that already touches account.test.ts/auth.test.ts rather than a dedicated rewrite.
Refs: Doist/cli-core#49, #251
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.