fix(provider): a blank Altimate key is not a sign-in

RA
1d ago
+283-16

Issue for this PR

Closes #1834

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

A credentials file with a blank key, instance name or URL counted as a sign-in. The gateway provider loaded as connected, became the default model, and sent its request with no Authorization header, which the gateway answers with 403 "Not authenticated". People who had never signed in got that on their first message instead of the free Altimate Base model.

  • The credentials schema refuses blank or whitespace-only fields. The provider isn't listed, and the default model falls through to Altimate Base or whatever else is connected.
  • The generic auth-store merge skips altimate-backend. Its entry is a url::instance::key string that only the provider's own loader parses. Merged raw, it listed the provider with no URL whenever the loader declined it ("undefined/chat/completions" cannot be parsed as a URL).
  • An unusable credentials file no longer deletes that auth-store entry. The deletion only existed to stop the raw merge above, and now that blank files count as unusable it would throw away a saved key.
  • Sign-out reads the saved key itself, so a file with no key or a blank one is cleared instead of refused. It still refuses when a key may exist but can't be read.
  • A 401 or 403 from the gateway reads "Sign in to Altimate again: ..." with the existing sign-in command (now in a small shared module), and keeps the gateway's own text at the end. 402 (credits) is untouched.

Limits:

  • isConfigured() still returns true when the file exists, so workspace and identity code keep treating a blank file as configured but incomplete, as they do today.
  • A blank file next to a valid auth entry doesn't fall back to the entry: the file is read first, as on main.
  • What writes a blank key into the file in the first place is out of scope; the reader is safe whatever the writer does.
  • A user config provider block for altimate-backend merges as before.
  • A sign-in that exists only in the auth store now has source "custom", as the file path does; nothing reads it for this provider.

How did you verify your code works?

  • New provider tests: blank key, whitespace key, blank instance or URL each leave the provider unlisted and not the default; an auth entry next to an unusable file lists nothing and is kept; an auth entry alone still loads. Six fail without the fix.
  • New sign-out tests: files with a blank key, a whitespace key or no fields are cleared; a readable key with a blank instance still removes its MCP entries.
  • New error tests for the 401 and 403 message, plus a 402 and another provider's 403 staying as they were. The two sign-in ones fail without the fix.
  • The empty env var test in datamate.test.ts now expects the blank field it leaves to be refused.
  • Ran the provider, ACP, sign-out, logout, workspace-command and datamate suites, plus workspace, telemetry and integrations. Six integrations tests fail the same way on main here; they read local MCP config.
  • Against a stub gateway that answers like the real one: on 0.12.11 a blank-key file sends the first message to the gateway with x-tenant and no Authorization, and gets the 403. On this branch the provider isn't listed, and a revoked key shows the new message.

Cost side effects

None.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR
  • I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"

🤖 Generated with Claude Code

https://claude.ai/code/session_01YNQjkbmBzDHrmvLJUuFJiW

Summary by CodeRabbit

  • Bug Fixes
    • Blank or whitespace-only required Altimate credentials are rejected with clearer validation feedback.
    • Signing out clears credentials when the API key is absent or blank. Matching remote entries are removed when a readable key is available; otherwise, existing entries remain unchanged.
    • Malformed credentials no longer remove a previously saved authentication key.
    • Altimate gateway authentication failures prompt users to sign in again. Credit-related errors and similar responses from other providers retain their existing handling.
    • Valid saved credentials continue to configure the Altimate gateway connection.