- every {type:"failed"} carries an error reason magpie shows
- commandcode/devin: accounts taken from the CLI are marked metadata.cli and re-read its credentials on each request, usage and models
- factory: a refused refresh answers 401 authentication_error (Anthropic shape on /llm/a/, OpenAI's elsewhere) instead of throwing; the whoami back-off is per account; 403 hints name the account to sign in again
- versions: factory/devin/commandcode/cursor/kiro/mimo/zed/zcode 0.1.2, workbuddy 0.1.3
21 lines
1.1 KiB
JavaScript
21 lines
1.1 KiB
JavaScript
// An account taken from the CLI's sign-in uses the key the CLI has now, as
|
|
// magpie's built-in re-reads ~/.commandcode/auth.json: a `commandcode
|
|
// login` since changes it. Others keep the key they were saved with.
|
|
// Run with HOME a scratch folder (as `HOME=$(mktemp -d) bun test`).
|
|
import { expect, test } from "bun:test"
|
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs"
|
|
import { homedir } from "node:os"
|
|
import { join } from "node:path"
|
|
import { _internal } from "./index.mjs"
|
|
|
|
const home = homedir()
|
|
|
|
test.skipIf(existsSync(join(home, ".commandcode")))("the CLI's account follows the CLI's key; a pasted key stays", async () => {
|
|
const cli = { type: "api", key: "saved", metadata: { cli: true } }
|
|
expect(await _internal.liveKey(cli)).toBe("saved") // the CLI signed out: the saved one
|
|
mkdirSync(join(home, ".commandcode"))
|
|
writeFileSync(join(home, ".commandcode", "auth.json"), JSON.stringify({ apiKey: "rotated" }))
|
|
expect(await _internal.liveKey(cli)).toBe("rotated")
|
|
expect(await _internal.liveKey({ type: "api", key: "pasted", metadata: {} })).toBe("pasted")
|
|
})
|