Skip to content

refactor(auth): adopt cli-core 0.16 createSecureStore - #226

Merged
scottlovegrove merged 3 commits into
mainfrom
refactor/secure-store-from-cli-core
May 16, 2026
Merged

refactor(auth): adopt cli-core 0.16 createSecureStore#226
scottlovegrove merged 3 commits into
mainfrom
refactor/secure-store-from-cli-core

Conversation

@scottlovegrove

@scottlovegrove scottlovegrove commented May 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Delete src/lib/secure-store.ts (+ its test) and switch every consumer to createSecureStore from @doist/cli-core/auth — cli-core's version is a strict superset (memoised AsyncEntry promise, cause propagation on SecureStoreUnavailableError).
  • Bump @doist/cli-core 0.12.0 → 0.16.1.
  • Keep SECURE_STORE_DESCRIPTION and the serviceName / account literals local in src/lib/auth.ts (cli-core doesn't publicly re-export the description string).
  • No user-facing change. Single-user model preserved. Foundation for a later, larger migration to createKeyringTokenStore + migrateLegacyAuth.

Test plan

  • npm run type-check
  • npm run lint:check
  • npm test — 36 files / 605 tests pass
  • npm run build
  • Manual smoke (keyring present): tw auth logintw auth statustw auth logouttw auth status
  • Manual smoke (keyring absent): tw auth token <token> falls through to config-file with the "system credential manager unavailable" warning

🤖 Generated with Claude Code

Replace the local @napi-rs/keyring wrapper in src/lib/secure-store.ts
with @doist/cli-core/auth's createSecureStore. cli-core's version is a
strict superset (memoised AsyncEntry, cause propagation) and owning the
keyring contract in one place is the prerequisite for the larger
multi-user TokenStore / migrateLegacyAuth migration to follow.

- Delete src/lib/secure-store.ts + its test (cli-core owns the surface).
- Bump @doist/cli-core 0.12.0 → 0.16.1.
- Move SECURE_STORE_DESCRIPTION + service/account constants into auth.ts
  (cli-core doesn't publicly re-export the description string).
- Rewire auth-provider.ts, commands/config/view.ts, and the three test
  files (auth.test.ts, auth-provider.test.ts, config.test.ts) onto
  @doist/cli-core/auth.

No user-facing change. Single-user model preserved.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@doistbot
doistbot requested a review from pedroalves0 May 16, 2026 19:59
@scottlovegrove scottlovegrove self-assigned this May 16, 2026
@scottlovegrove scottlovegrove added the 👀 Show PR PR must be reviewed before or after merging label May 16, 2026

@doistbot doistbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This refactoring successfully adopts @doist/cli-core/auth's createSecureStore, cleanly removing the custom local implementation and reducing the overall code footprint. The changes lay a solid foundation for future auth migrations while preserving the existing single-user model. A few minor adjustments were noted to improve testing and architectural boundaries, specifically around centralizing error imports, re-exporting external auth types from the local library instead of pulling them directly into command handlers, and strengthening a mock to verify the correct keyring arguments are requested.

Share FeedbackReview Logs

Comment thread src/lib/auth-provider.test.ts Outdated
Comment thread src/commands/config/view.ts
Comment thread src/lib/auth.test.ts Outdated
scottlovegrove and others added 2 commits May 16, 2026 21:07
Address doistbot review on #226:
- auth.test.ts: convert the createSecureStore mock to vi.fn and add a
  test asserting it is called with `{serviceName:'twist-cli',
  account:'api-token'}` — coverage previously lived in the deleted
  secure-store.test.ts.
- auth-provider.test.ts: hoist `SecureStoreUnavailableError` to a
  top-level static import; collapse three duplicated dynamic imports.

Declined the third nit (re-export `SecureStoreUnavailableError` from
lib/auth.ts for config/view): the proposed boundary doesn't exist —
commands/auth/{login,logout,status}.ts already depend on
@doist/cli-core/auth directly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The earlier dedupe pass only collapsed the 8-space-indented dynamic
import; the two copies at 12-space indent inside `describe('ref-aware
lookups')` slipped through. Remove them so all three call sites use the
top-level static import.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@scottlovegrove
scottlovegrove merged commit c498e58 into main May 16, 2026
5 checks passed
@scottlovegrove
scottlovegrove deleted the refactor/secure-store-from-cli-core branch May 16, 2026 20:14
@doist-release-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 2.38.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@pedroalves0 pedroalves0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Labels

released 👀 Show PR PR must be reviewed before or after merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants