Skip to content

fix(cli): make sonilo whoami answerable, in both directions - #53

Merged
spencer-zqian merged 1 commit into
mainfrom
fix/whoami-usable-as-a-check
Aug 14, 2026
Merged

fix(cli): make sonilo whoami answerable, in both directions#53
spencer-zqian merged 1 commit into
mainfrom
fix/whoami-usable-as-a-check

Conversation

@spencer-zqian

@spencer-zqian spencer-zqian commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Two bugs that compound into one: whoami could not be used to answer "am I signed in", and its output said the wrong thing when you were.

Exit code

whoami returned 0 whether or not a credential existed — it printed Not signed in. Run sonilo login. and then exited successfully. Anything branching on it took the signed-in path with nothing on disk, and only found out when the next command failed on auth.

signed in not signed in
sonilo whoami (before) 0 0
sonilo whoami (after) 0 1
sonilo account 0 1

gh auth status sets the precedent: a status command that cannot be branched on is not a status command.

An expired credential still exits 0. It names a real account, the line already says (expired), and sonilo login is the fix — reporting "not signed in" would send callers to first-time setup instead.

Blank account name

accountLabel was account_name ?? account_id, and the API returns account_name: " " for an account with no display name set. A single space is neither null nor undefined, so it won, and whoami printed:

account:
key: sk-47060...
expires: 2026-11-11

That empty line is indistinguishable from a credential that never loaded.

How this surfaced

Found while testing the skills repo's transport routing, whose CLI branch is gated on this command ("sonilo whoami exits 0 → use the CLI").

Both bugs are verified directly and independently of any agent behaviour — the exit-code table above and the " " account name are reproducible from a shell in one command each. That is what this PR rests on.

One agent run did misread the blank account: line against a fully authenticated CLI and conclude nothing was set up. I initially wrote that up as "reproduced 2/2"; a later controlled comparison showed that was overstated — the second run had failed for an unrelated reason (Bash was not permitted in that non-interactive session), and with permissions held constant the misread did not reproduce every time. The behavioural evidence is one real occurrence, not a consistent failure. The exit-code defect needs no behavioural evidence at all: a probe that returns 0 in both states carries no information by construction.

Notes

runWhoami returns a boolean instead of setting process.exitCode itself — the tests call it directly, and setting the exit code there would leave the whole vitest run at 1.

Verification

  • 157 tests pass (6 files); tsc --noEmit clean.
  • Built and run against a real credential — the account id now prints where the blank was, exit 0.
  • Built and run against an empty HOMENot signed in, exit 1.
  • New tests cover the boolean in all four states (none / stored / env key / expired) and the blank-name fallback across " ", "", " ", and null.

🤖 Generated with Claude Code

Two bugs that compound into one: whoami could not be used to answer "am I
signed in", and its output said the wrong thing when you were.

Exit code. whoami returned 0 whether or not a credential existed — "Not
signed in. Run sonilo login." printed, then success. Anything branching on
it took the signed-in path with nothing on disk and only found out when the
next command failed on auth. `gh auth status` sets the precedent: a status
command that cannot be branched on is not a status command. It now exits 1
with no credential, and stays 0 for an expired one, which names a real
account and wants `sonilo login`, not first-time setup.

Blank account name. `accountLabel` was `account_name ?? account_id`, and the
API returns `account_name: " "` for an account with no display name set. A
single space is neither null nor undefined, so it won, and whoami printed
`account: ` with nothing after it — indistinguishable from a credential that
never loaded. Trimming first and falling back on any blank shows the id,
which is always present.

Found while testing the skills repo's transport routing, whose CLI branch is
gated on exactly this command. An agent ran whoami against a fully
authenticated CLI, read the empty account line, concluded nothing was set
up, and detoured to first-time setup. Reproduced 2/2.

runWhoami returns a boolean rather than setting process.exitCode itself, so
the tests that call it directly do not leave the runner's exit code at 1.

Verified: 157 tests pass; built and run against a real credential (account id
now shown) and against an empty HOME (exit 1).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sapient-app

sapient-app Bot commented Aug 13, 2026

Copy link
Copy Markdown

Lightsage docs evals

Waiting for the staging docs URL before running evals.

Lightsage will start the selected PR evals automatically when GitHub reports a successful docs deployment for this PR. This usually happens within 15 minutes.

Commit: 8f3ff6e
Status: waiting for staging docs URL

@spencer-zqian
spencer-zqian merged commit 8ada33d into main Aug 14, 2026
1 check passed
@spencer-zqian
spencer-zqian deleted the fix/whoami-usable-as-a-check branch August 14, 2026 00:10
spencer-zqian added a commit that referenced this pull request Aug 17, 2026
…ed it (#57)

#53 landed on main without a changeset, so `sonilo whoami`'s exit-code
change rode out inside 0.14.0 with nothing in that release's notes. The
version number is right — it went out in a minor bump, which is the
correct slot for a behaviour change at 0.x — only the changelog was
silent.

Written against the existing 0.14.0 heading rather than as a new
changeset, so no phantom 0.15.0 gets published for a change that is
already in users' hands. Anyone whose script broke on `whoami` returning
1 can now find the version that did it.

Supersedes #54, which proposed the changeset and would have dated this
to the next release instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant