diff --git a/packages/devin/cli-key.test.mjs b/packages/devin/cli-key.test.mjs index 37268a5..8f5c0b7 100644 --- a/packages/devin/cli-key.test.mjs +++ b/packages/devin/cli-key.test.mjs @@ -5,7 +5,7 @@ import { afterAll, expect, test } from "bun:test" import { mkdtempSync, mkdirSync, writeFileSync } from "node:fs" import { tmpdir } from "node:os" import { join } from "node:path" -import { _internal } from "./index.mjs" +import { DevinAuthPlugin, _internal } from "./index.mjs" const was = process.env.XDG_DATA_HOME const wasAppData = process.env.APPDATA @@ -25,3 +25,23 @@ test("the CLI's account follows credentials.toml; a browser sign-in stays", asyn expect(await _internal.live(cli)).toEqual({ key: "rotated", server: "https://t.example" }) expect(await _internal.live({ type: "api", key: "own", metadata: {} })).toMatchObject({ key: "own" }) }) + +// OpenCode 1 keeps an auth's metadata as strings only and drops an +// auth.json entry with any other value (#396), so the CLI sign-in saves +// every value, cli included, as a string. +test("the CLI sign-in saves only string metadata", async () => { + mkdirSync(join(data, "devin"), { recursive: true }) + writeFileSync(join(data, "devin", "credentials.toml"), 'windsurf_api_key = "cli-key"\napi_server_url = "https://server.codeium.com"\n') + const realFetch = globalThis.fetch + globalThis.fetch = async () => new Response(JSON.stringify({ userStatus: { email: "me@example.com", planStatus: { planInfo: { planName: "Pro", devinInfo: { orgId: "org-1" } } }, teamId: "team-1" } }), { status: 200, headers: { "content-type": "application/json" } }) + try { + const hooks = await DevinAuthPlugin({}) + const method = hooks.auth.methods.find((m) => m.authorize && m.label === "Devin CLI's sign-in") + const r = await (await method.authorize()).callback() + expect(r.type).toBe("success") + expect(r.metadata.cli).toBe("true") + for (const [k, v] of Object.entries(r.metadata)) expect([k, typeof v]).toEqual([k, "string"]) + } finally { + globalThis.fetch = realFetch + } +}) diff --git a/packages/devin/package.json b/packages/devin/package.json index a2f58b8..5ac41e8 100644 --- a/packages/devin/package.json +++ b/packages/devin/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-devin-auth", - "version": "0.1.23", + "version": "0.1.24", "description": "Devin subscriptions (the devin CLI's account) in OpenCode and magpie", "type": "module", "main": "./index.mjs",