CLI: failed keychain deletes are errors; key remove works out its session id locally (#1019) #39

Open
backmeupplz wants to merge 4 commits from board/1019-dada1d into main
Owner

Follow-up to #35 (board #1019).

Failed keychain deletes are errors now

  • state::forget returns Res<()>. The server logout stays best effort, but a local copy (with its Account Key) that can't be deleted is an error.
  • remove_account propagates the Secret Key delete.
  • lock, account remove, key remove --all and passwd no longer print success after a failed delete; each says what did happen and to run plaintext lock or try again.
  • end_sessions returns Res<bool> and no longer swallows its local delete.

key remove works out this terminal's session id locally

  • The id is hex(sha256(token)[..8]), as the server computes it, so there's no GET /v1/sessions.
  • This terminal's session is still ended last.
  • The stored session is dropped only once its own DELETE succeeded. Offline, it stays for unkey and lock.
  • unkey runs only when the stored session is the removed key's, not whenever no keys remain.
  • The warning names the session ids, and so does account remove's.

The NITs from the ticket comment

  • end_sessions uses the stored token only under resume()'s checks: unexpired, and from this terminal. key remove already falls back to state::open(). The CLI unit tests get a #[cfg(test)] terminal(), since CI has no tty.
  • key add: if unlocking this terminal fails after the key was saved, that's a warning, so running it again doesn't hit "already exists".
  • Signing in before the PIN and touches is accepted and commented. Moving it later would only surface a wrong password after the key had made a credential.
  • The concurrent add and renewal race gets a ponytail: comment.

Known and accepted (review nits)

  • account remove from another terminal, or after 12 hours, no longer ends the keys' sessions. It warns with their ids instead, since there's no right account to open() for.
  • key remove NAME with a stored key session older than 12 hours: the open() fallback forgets the expired copy. If that unlock then fails, the warning with the ids is all that's left.

Tests

  • cargo test -p plaintext-cli and clippy with -D warnings pass.
  • New assertions:
    • The local id equals the server's.
    • A session whose end fails is kept.
    • Own-last ordering, which a mutation test showed was untested before.
    • forget and remove_account fail, keeping the account listed, when the session or Secret Key can't be deleted.

🤖 Generated with Claude Code

Follow-up to #35 (board #1019). **Failed keychain deletes are errors now** - `state::forget` returns `Res<()>`. The server logout stays best effort, but a local copy (with its Account Key) that can't be deleted is an error. - `remove_account` propagates the Secret Key delete. - `lock`, `account remove`, `key remove --all` and `passwd` no longer print success after a failed delete; each says what did happen and to run `plaintext lock` or try again. - `end_sessions` returns `Res<bool>` and no longer swallows its local delete. **`key remove` works out this terminal's session id locally** - The id is `hex(sha256(token)[..8])`, as the server computes it, so there's no `GET /v1/sessions`. - This terminal's session is still ended last. - The stored session is dropped only once its own DELETE succeeded. Offline, it stays for `unkey` and `lock`. - `unkey` runs only when the stored session is the removed key's, not whenever no keys remain. - The warning names the session ids, and so does `account remove`'s. **The NITs from the ticket comment** - `end_sessions` uses the stored token only under `resume()`'s checks: unexpired, and from this terminal. `key remove` already falls back to `state::open()`. The CLI unit tests get a `#[cfg(test)] terminal()`, since CI has no tty. - `key add`: if unlocking this terminal fails after the key was saved, that's a warning, so running it again doesn't hit "already exists". - Signing in before the PIN and touches is accepted and commented. Moving it later would only surface a wrong password after the key had made a credential. - The concurrent `add` and renewal race gets a `ponytail:` comment. **Known and accepted** (review nits) - `account remove` from another terminal, or after 12 hours, no longer ends the keys' sessions. It warns with their ids instead, since there's no right account to `open()` for. - `key remove NAME` with a stored key session older than 12 hours: the `open()` fallback forgets the expired copy. If that unlock then fails, the warning with the ids is all that's left. **Tests** - `cargo test -p plaintext-cli` and clippy with `-D warnings` pass. - New assertions: - The local id equals the server's. - A session whose end fails is kept. - Own-last ordering, which a mutation test showed was untested before. - `forget` and `remove_account` fail, keeping the account listed, when the session or Secret Key can't be deleted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CLI: name the sessions account remove couldn't end; context for its errors; test the own-last order (#1019 review)
Some checks failed
CI / check (pull_request) Has been cancelled
CI / wasm (pull_request) Has been cancelled
6d91985442
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CLI: one 'try again' in account remove's error (#1019 review)
Some checks failed
CI / check (pull_request) Has been cancelled
CI / wasm (pull_request) Has been cancelled
0748aeb4e9
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merge remote-tracking branch 'origin/main' into HEAD
Some checks are pending
Apple / Apple (pull_request) Successful in 38s
Android / android (pull_request) Has started running
CI / wasm (pull_request) Has started running
CI / check (pull_request) Successful in 9m45s
abf90f8542
Some checks are pending
Apple / Apple (pull_request) Successful in 38s
Android / android (pull_request) Has started running
CI / wasm (pull_request) Has started running
CI / check (pull_request) Successful in 9m45s
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'board/1019-dada1d:board/1019-dada1d'
git switch 'board/1019-dada1d'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
backmeupplz/plaintext!39
No description provided.