Skip to content

fix(auth): surface real auth errors, stop test suite wiping dev credentials - #9

Merged
nathanclevenger merged 3 commits into
mainfrom
fix/auth-error-surfacing
Aug 18, 2026
Merged

fix(auth): surface real auth errors, stop test suite wiping dev credentials#9
nathanclevenger merged 3 commits into
mainfrom
fix/auth-error-surfacing

Conversation

@nathanclevenger

Copy link
Copy Markdown
Contributor

What broke

A user reported the SDK "wasn't working correctly with auth." Root-causing found three distinct bugs:

1. Every auth failure rendered as ✖ 401: [object Object]

The auth middleware returns { status, error: { message } } while every other endpoint returns { error: string }. src/core/client.ts assumed the flat shape, so the object became the error message. Any invalid/expired/revoked credential produced [object Object] across CLI, programmatic SDK (err.message), and MCP tools — hiding the server's actual explanation ("Authentication required. Get your API key at …").

After:✖ 401: Authentication required. Get your API key at https://auto.dev/dashboard/api-keys (verified against the live API).

2. First run with no credentials crashed with a raw stack trace

resolveAuth threw a plain Error; the command factory only formats AutoDevError and rethrew everything else. A brand-new user's first command dumped a Node stack trace instead of the login hint.

After:✖ 401: No API key found + Set AUTODEV_API_KEY or run: auto login. The factory also formats any unexpected error as a fallback (e.g. offline fetch failed).

3. pnpm test logged the developer out of auto.dev (!)

The clearCredentials test (test/auth/auth-origin-headers.test.ts) ran the real implementation against the module-level default storage: it POSTed a live token revocation to id.org.ai with the developer's stored access token, then deleted ~/.id.org.ai/token and ~/.oauth.do/token. Harmless in CI (no credentials there — the test even says so), destructive on any dev machine. Confirmed by planting a dummy token in a sandbox HOME and watching the suite delete it.

After:test/setup.ts sandboxes HOME/USERPROFILE into a fresh temp dir for every vitest run, and the test also mocks fetch so no revoke can escape. Forensic re-check: planted token survives the full suite.

Verification

  • 144/144 tests pass (5 new regression tests: nested + flat + empty error shapes, typed no-credential error, formatted unexpected errors)
  • tsc --noEmit clean, tsup build clean
  • Live-API smoke: invalid key and no-credential paths show the new output; happy path unchanged (success branch untouched)

Known gaps left open (not this PR)

  • docs.auto.dev/v2/cli-mcp-sdk claims credentials are "shared across CLI, SDK, and MCP", but new AutoDev({}) never reads the stored auto login token — doc or SDK should change (follow-up issue)
  • tco returns 404 for VINs that resolve on every other endpoint — API-side, not auth

🤖 Generated with Claude Code

nathanclevengerand others added 3 commits August 18, 2026 08:04
… Object]
The auth middleware returns { status, error: { message } } while every other
endpoint returns { error: string }. The client assumed the flat shape, so any
401 (invalid, expired, or revoked credential) rendered as '[object Object]'
in the CLI, SDK, and MCP tools, hiding the server's actual explanation.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…s exist
resolveAuth threw a plain Error, and the command factory only formats
AutoDevError — so a brand-new user's first command crashed with a raw Node
stack trace. resolveAuth now throws AutoDevError(401) with the login hint as
the suggestion, and the factory formats unexpected errors as a fallback.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…tials
The clearCredentials test called the real implementation against the
module-level default storage: it POSTed a live token revocation to id.org.ai
with the developer's stored access token, then deleted ~/.id.org.ai/token and
~/.oauth.do/token. Running 'pnpm test' logged the developer out of auto.dev.
test/setup.ts now points HOME/USERPROFILE at a fresh temp dir for every run,
and the clearCredentials test also mocks fetch so no revoke can escape.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@nathanclevenger
nathanclevenger merged commit 65418d2 into mainAug 18, 2026
1 check passed
@nathanclevenger
nathanclevenger deleted the fix/auth-error-surfacing branch August 18, 2026 16:17
Sign up for freeto 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

@nathanclevenger