codearts 0.3.14: a CodeArts Agent sign-in is kept (#998)
Signing in with "Sign in from CodeArts Agent" said ok, but the account was never stored. A host keeps an OAuth sign-in only when the result has a `refresh` field (OpenCode's CLI and magpie's host.js both test `"refresh" in result`), and the IDE method's success had none. It now has `refresh: ""`. This sign-in has no refresh token: it is renewed by reading the IDE's state file again, and every reader of the refresh token (firstOf) already skips an empty string. The IDE sign-in test now checks the field is there and empty. Ran on mica (Bun, HOME=$(mktemp -d)): bun test packages/codearts 203 pass 0 fail; bun scripts/check.mjs exit 0. Broken by hand: without the refresh line, "signing in from the CodeArts Agent: checked with its station…" goes red (202 pass, 1 fail). Not tried: a real CodeArts Agent sign-in (no account here). Reported-by: AyakaChen1 <AyakaChen1@users.noreply.github.com>
This commit is contained in:
@@ -3196,8 +3196,15 @@ export const CodeArtsAuthPlugin = async ({ client } = {}, options = {}) => {
|
||||
if (checked.error) return { type: "failed", error: checked.error }
|
||||
const cred = { ...read.cred, ...checked.fields, session_id: randomHex(16) }
|
||||
const identity = accountIdentityOf(cred)
|
||||
// refresh is here, empty, because a host keeps an OAuth
|
||||
// sign-in only when the result has one (OpenCode's CLI and
|
||||
// magpie's host.js both test `"refresh" in result`): without
|
||||
// it the sign-in said ok and nothing was stored (#998). This
|
||||
// one has no refresh token; it is renewed by reading the IDE's
|
||||
// file again.
|
||||
return {
|
||||
type: "success",
|
||||
refresh: "",
|
||||
access: JSON.stringify(cred),
|
||||
expires: expiresFromCredential(cred),
|
||||
accountId: identity.id,
|
||||
|
||||
@@ -4449,7 +4449,9 @@ test("signing in from the CodeArts Agent: checked with its station, the account
|
||||
assert.equal(r.type, "success", r.error)
|
||||
assert.equal(r.accountId, "dom1")
|
||||
assert.equal(r.uid, "dom1")
|
||||
assert.equal(r.refresh, undefined)
|
||||
// a host keeps an OAuth sign-in only when "refresh" is in the result (#998)
|
||||
assert.ok("refresh" in r, "kept by the host")
|
||||
assert.equal(r.refresh, "", "no refresh token: renewed from the IDE's file")
|
||||
assert.equal(r.expires, Date.parse("2030-01-01T00:00:00Z"))
|
||||
const cred = JSON.parse(r.access)
|
||||
assert.equal(cred.station, "international")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-codearts-auth",
|
||||
"version": "0.3.13",
|
||||
"version": "0.3.14",
|
||||
"description": "Huawei Cloud in OpenCode and magpie: CodeArts (码道) and OfficeAce (AgentArts), each from its own Huawei Cloud OAuth sign-in — models, credit rates, credit usage and the daily check-in (unofficial)",
|
||||
"type": "module",
|
||||
"main": "./opencode.mjs",
|
||||
|
||||
Reference in New Issue
Block a user