Skip to content

auth login: clear stale oid on user-scoped re-login + tests#291

Merged
maximelb merged 1 commit into
cli-v2from
cli-v2-auth-login-stale-oid-fix
May 7, 2026
Merged

auth login: clear stale oid on user-scoped re-login + tests#291
maximelb merged 1 commit into
cli-v2from
cli-v2-auth-login-stale-oid-fix

Conversation

@maximelb
Copy link
Copy Markdown
Contributor

@maximelb maximelb commented May 7, 2026

Summary

Follow-up to #289. Fixes one user-visible bug, refreshes the help text for the new login shape, and adds unit coverage for the validator (none existed before).

  • Stale oid after switching to a user-scoped login. write_credentials only writes fields it is given, so auth login --uid X --api-key Y in an env that previously held --oid + --api-key left the old oid in place. Subsequent commands silently paired the new user-scoped key with the wrong org context. Fix: pop oid from the affected env block right after the write whenever the login is user-scoped (uid set, oid unset). Mirrors the post-write api_key cleanup the OAuth flow already does.
  • --ai-help text was stale — still claimed --oid + --api-key was the only API-key shape. Updated to advertise the user-scoped shape introduced in auth login: allow user-scoped API key without --oid #289.
  • No tests existed for the auth login validator. Added tests/unit/test_cli_auth_login.py covering the three valid shapes, both error paths, named-env writes, and the new stale-oid cleanup (incl. that other envs are untouched).

The brand-new-account / workshop bootstrap flow #289 targeted is unaffected (no prior oid to clear); this only changes behavior on re-login.

Test plan

  • pytest tests/unit/test_cli_auth_login.py — 11/11 pass
  • pytest tests/unit/test_config.py tests/unit/test_cli_commands.py — 77/77 pass (regression check on neighboring surfaces)
  • Manual: auth login --oid X --api-key Y then auth login --uid Z --api-key W, confirm ~/.limacharlie.d/config.yaml no longer contains oid: X

🤖 Generated with Claude Code

Follow-up to #289. When a user re-runs `auth login --uid X --api-key Y`
in an environment that previously held an `--oid + --api-key` login, the
old `oid` survived in config because `write_credentials` only writes
fields it is given. Subsequent commands would silently pair the new
user-scoped credentials with the stale org context.

Fix it by dropping the `oid` field from the affected env block right
after the write whenever the login was user-scoped (`uid` set, `oid`
unset). Mirrors the post-write cleanup pattern already used by the
OAuth flow for `api_key`.

Also refresh the `--ai-help` text so it advertises the user-scoped
shape (`--uid + --api-key`, no `--oid`) that #289 enabled, and add
unit tests for the validator branches and the stale-oid cleanup --
neither was covered before.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@maximelb maximelb requested a review from dzimine-lc May 7, 2026 15:22
@maximelb maximelb merged commit 7cf1d67 into cli-v2 May 7, 2026
7 checks passed
@maximelb maximelb deleted the cli-v2-auth-login-stale-oid-fix branch May 7, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant