fix(oauth): read OPENCODE_API_KEY in e2e models opencode-console

Merged
YI
13d ago
+148-44

Fixes #1014.

  • e2e models opencode-console reads OPENCODE_API_KEY when it is set, in place of the stored login, as opencodeConsole() already does. With both set, the listing now shows the workspace the tests actually run on.
  • e2e models with no provider includes OpenCode Console when only the key is set.
  • With no credential, both errors name the key along with npx e2e login opencode-console. A rejected key says check OPENCODE_API_KEY.
  • The key lookup lives in one place: apiKeyEnv on the provider (packages/e2e/src/oauth/types.ts) and credentialSource() in packages/e2e/src/oauth/providers.ts, used by both opencodeConsole() and listModels().

Verified

Ran it locally: yes

  • Built CLI (dist/cli/bin.js models) on main and on this branch. A stub server stood in for opencode.ai/console/api/config (fetch redirected by a --import preload) and logged the bearer each run sent.
casemainthis branch
key only, models opencode-consoleno OpenCode Console login is stored; run npx e2e login opencode-console, exit 12 models (Zen + go/), Bearer <key>, no x-org-id, exit 0
key only, bare modelsno login is stored; sign in with e2e login <...>, exit 1lists OpenCode Console, exit 0
neither... run npx e2e login opencode-console, exit 1... run npx e2e login opencode-console or set OPENCODE_API_KEY, exit 1
key + stored loginlists via the login (Bearer st_tok, x-org-id: org_1)lists via the key (Bearer <key>), same as opencodeConsole()
rejected key + stored loginlists via the login, ignoring the key the tests useOpenCode Console rejected the stored token (401: invalid key); check OPENCODE_API_KEY, exit 1
login onlylists via the loginunchanged
  • Not verified against the live service, since no OpenCode key was available. OpenCode's docs describe a single oc_sk_ key kind bound to a workspace, and Go as a property of the workspace, so a Go subscription key is most likely the same key as a service account key. The listing reads the same config opencodeConsole() already reads with the key.