Skip to content

feat(auth): tolerate AUTH_STORE_READ_FAILED in logout --user (2/4)#26

Merged
scottlovegrove merged 1 commit into
mainfrom
feat/auth-store-read-failed
May 16, 2026
Merged

feat(auth): tolerate AUTH_STORE_READ_FAILED in logout --user (2/4)#26
scottlovegrove merged 1 commit into
mainfrom
feat/auth-store-read-failed

Conversation

@scottlovegrove
Copy link
Copy Markdown
Collaborator

Stack position: 2 / 4 — base is #25 (feat/keyring-primitive). Replaces part of #24.

Summary

A TokenStore may legitimately throw CliError('AUTH_STORE_READ_FAILED', …) from active(ref) when a matching record exists but the token itself can't be read (e.g. an OS keyring backing the store is offline). Without special handling, logout --user <ref> would abort even though clear(ref) doesn't need the token.

  • Add AUTH_STORE_READ_FAILED to AuthErrorCode.
  • attachLogoutCommand catches it on the explicit-ref pre-flight and proceeds with clear(ref). Other typed errors (notably ACCOUNT_NOT_FOUND from a genuine miss) still propagate.
  • attachStatusCommand / attachTokenViewCommand propagate the error unchanged — they can't render without the token.
  • Extract accountNotFoundError(ref) helper in auth/user-flag.ts so PR 3's setDefault can share the construction.

Why now

The concrete thrower is in PR 3 (createKeyringTokenStore), but this attacher behavioural change is logically a contract addition — any TokenStore consumer can use it — and reviews cleaner on its own.

Test plan

  • npm run type-check, npm run check, npm test (307 passing, +3 new attacher tests)
  • Once PR 3 lands, smoke logout --user <ref> against a createKeyringTokenStore with DBUS_SESSION_BUS_ADDRESS unset.

🤖 Generated with Claude Code

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 usefully enhances the authentication flow by introducing the AUTH_STORE_READ_FAILED error code to allow logout --user <ref> to proceed even when the token itself cannot be read. The changes logically isolate the new contract addition, making the TokenStore more robust and smoothly paving the way for the upcoming keyring implementation. A few adjustments are noted, such as ensuring the onCleared callback retains the requested reference when an account is unreadable, utilizing the existing buildStore helper to avoid test duplication, adding missing test coverage for the token-view command, and keeping the accountNotFoundError helper file-local to prevent a dead export.

Share FeedbackReview Logs

Comment thread src/auth/logout.ts Outdated
Comment thread src/auth/logout.test.ts Outdated
Comment thread src/auth/status.test.ts Outdated
Comment thread src/auth/user-flag.ts Outdated
Comment thread src/auth/status.test.ts
@scottlovegrove scottlovegrove force-pushed the feat/auth-store-read-failed branch from 644b8c5 to 2cd6aaf Compare May 16, 2026 12:35
@scottlovegrove
Copy link
Copy Markdown
Collaborator Author

@doistbot /review

@scottlovegrove scottlovegrove force-pushed the feat/keyring-primitive branch from 165fb07 to 5b0cfd7 Compare May 16, 2026 13:50
@scottlovegrove scottlovegrove force-pushed the feat/auth-store-read-failed branch from 2cd6aaf to 5092110 Compare May 16, 2026 13:50
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 effectively introduces handling for AUTH_STORE_READ_FAILED in the authentication flow, ensuring logout --user can proceed smoothly even when the backing token store is unreadable. The targeted error recovery and extracted helpers create a highly resilient contract for upcoming keyring integrations. A few adjustments are needed to accurately reflect the pre-flight error handling in the contract documentation, streamline the conditional logic for snapshot retrieval, and strengthen the assertions in the error propagation tests.

Share FeedbackReview Logs

Comment thread README.md Outdated
Comment thread src/auth/logout.ts Outdated
Comment thread src/auth/status.test.ts Outdated
Base automatically changed from feat/keyring-primitive to main May 16, 2026 13:57
@scottlovegrove scottlovegrove force-pushed the feat/auth-store-read-failed branch 3 times, most recently from e5b268a to 93bb598 Compare May 16, 2026 14:10
Comment thread src/auth/user-flag.ts Outdated
@scottlovegrove scottlovegrove force-pushed the feat/auth-store-read-failed branch 2 times, most recently from 3c50122 to fe9ab44 Compare May 16, 2026 14:15
@scottlovegrove
Copy link
Copy Markdown
Collaborator Author

@doistbot /review

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 introduces the AUTH_STORE_READ_FAILED error code to allow the logout command to successfully clear records even when the underlying token is unreadable. It is a thoughtful enhancement to the authentication contract that improves the robustness of the CLI against offline keyrings. A few minor additions have been flagged for completeness, specifically updating the TokenStore.active() JSDoc to document the new failure mode and ensuring test coverage includes both the token-view error propagation and plain logouts without hooks.

Share FeedbackReview Logs

Comment thread src/auth/status.test.ts
})
})

it('surfaces AUTH_STORE_READ_FAILED end-to-end (does not collapse to ACCOUNT_NOT_FOUND)', async () => {
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.

[P2] This test successfully asserts error propagation for status, but the analogous test for token-view mentioned in the PR conversation appears to have been omitted from the diff. Please ensure token-view.test.ts is staged and included.

Copy link
Copy Markdown
Collaborator Author

@scottlovegrove scottlovegrove May 16, 2026

Choose a reason for hiding this comment

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

Held — earlier in this PR's review history we explicitly dropped the analogous token-view test as redundant with the status propagation test (both attachers go through the same requireSnapshotForRef with no local catch, so they share a code path and a regression would surface in either).

Comment thread README.md
Comment thread src/auth/logout.test.ts
A `TokenStore` may legitimately throw `CliError('AUTH_STORE_READ_FAILED', …)`
from `active(ref)` when a matching record exists but the token itself
can't be read — e.g. an OS keyring backing the store is offline. Without
special handling, that would abort `logout --user <ref>` even though
local clear doesn't need the token; only the server-side `revokeToken`
hook does, and the hook is harmlessly skipped when the snapshot is
unavailable.

Changes:
- Add `AUTH_STORE_READ_FAILED` to `AuthErrorCode`.
- `attachLogoutCommand` catches it on the explicit-ref pre-flight and
  proceeds with `clear(ref)`. Other typed errors (notably
  `ACCOUNT_NOT_FOUND` from a genuine ref miss) still propagate.
- `attachStatusCommand` / `attachTokenViewCommand` propagate the error
  unchanged — they can't render without the token.
- Add a `ref` field to `AttachLogoutContext` (and the revoke context).
  It is set to the `--user <ref>` argument or `undefined` when absent,
  so a consumer's `onCleared` callback can distinguish "nothing was
  stored" (`account: null`, `ref: undefined`) from "cleared an
  unreadable record by ref" (`account: null`, `ref: "me"`).
- Keep `accountNotFoundError(ref)` as a file-local helper in
  `auth/user-flag.ts` so a future caller can lift it without
  duplicating the error wording.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@scottlovegrove scottlovegrove force-pushed the feat/auth-store-read-failed branch from fe9ab44 to 3e86be6 Compare May 16, 2026 14:23
@scottlovegrove scottlovegrove merged commit 23652bc into main May 16, 2026
4 checks passed
@scottlovegrove scottlovegrove deleted the feat/auth-store-read-failed branch May 16, 2026 14:28
doist-release-bot Bot added a commit that referenced this pull request May 16, 2026
## [0.14.0](v0.13.0...v0.14.0) (2026-05-16)

### Features

* **auth:** tolerate AUTH_STORE_READ_FAILED in logout --user ([#26](#26)) ([23652bc](23652bc))
@doist-release-bot
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.14.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