Files
magpie/internal/mcpauth
yetone 21f8ef61c4 provider: a complete Qwen AI platform sign-in is taken, and no sign-in error quotes a token (@imthe99galaxy on X)
On v0.1.4159 the Qwen AI platform's sign-in (qwen-token-plan) was
approved, and magpie failed it with "the Qwen AI platform answered in a
form magpie doesn't know: {"Data":{"Status":"complete","Credentials":
{"User":{"Id":"…"},"ExpireTime":"…","AccessToken":"RACv…"…". Two bugs:

1. qianwenWait decoded the device/token reply into a struct.
   encoding/json matches a name whatever its case and fails the whole
   reply on a value of another type (a number Id, an accessToken or user
   field beside AccessToken/User, a BOM), where the QianWen CLI 1.10.0
   (ul and ll in @qianwenai/qianwen-cli's dist/bin/qianwen.js, read from
   the npm tarball) looks up the names it wants and ignores the rest.
   readQianwenReply now reads it as the CLI does: Data.Status ?? status
   ?? authorization_pending; Data.Credentials.AccessToken ??
   credentials.access_token; ExpireTime ?? expire_time; User{Id, Email}
   ?? user{id, email}; by exact name, a value of a type it doesn't expect
   taken as absent. A RefreshToken is ignored, present or not: the CLI
   has no refresh, the user signs in again when the token runs out.
   The reporter's reply was quoted only to its first 300 characters, so
   which field failed it is not known; every type and case mismatch
   that could is covered, and the CLI's other (lowercase) form is read.

2. The error quoted the reply, live access token included, and the user
   posted it publicly. QuotedReply (quoted_reply.go) scrubs a reply
   before it is quoted (redact.ScrubJSON: a field named for a secret
   wholly, a key-shaped value anywhere). The class:
   - volcHead, every Volcengine / Alibaba Cloud / Tencent Cloud / Qwen
     AI platform error that quotes a reply, the Qwen sign-in's and its
     console token mint's ("gave no token") among them;
   - apiError's fallback for a body of no known shape (APIError, every
     upstream refusal and token endpoint that uses it);
   - Copilot Auto's "picked no model" (its reply carries session_token);
   - mcpauth's dynamic client registration failure (may carry a
     client_secret; it was quoted whole and unbounded, now cut at 300);
   - signInFlow.finish, where every built-in and plugin sign-in ends:
     its Error goes through redact.Scrub, so a plugin's or vendor's
     error text quoting a token leaves it there; the Qwen flow's own
     failure likewise.

Tests (internal/provider/qianwen_plan_test.go):
- TestQianwenSignInReadsEveryCompleteForm: the reporter's head with and
  without a RefreshToken, a number Id/ExpireTime, a like-named field of
  another type, the CLI's lowercase form, a BOM. Red on the old code
  (3 forms failed with the reporter's message, the lowercase one never
  ended), green now.
- TestQianwenErrorsQuoteNoToken: unreadable replies' errors, volcHead,
  APIError and QuotedReply never hold the token, and still say the
  words of a plain error (Throttling, RequestId). Red on the old code
  (sign-in errors and 8 quotes held it).
- TestSignInFailureQuotesNoToken: finish's Error. Red with the Scrub
  line taken out by hand, green with it.

Run:
- on magpie-desktop (WSL, mote's load was over 40 to 135) at this tree:
  gofmt -l clean; go vet -tags nogui and GOOS=windows go vet on
  internal/provider and internal/mcpauth ok;
  go test -run 'Qianwen|SignInFailure|SignIn|APIError|Volc|Alibaba|
  Tencent|CopilotAuto' ./internal/provider ./internal/mcpauth: ok.
- Full go test -tags nogui -timeout 45m ./... was started there at this
  tree and was still running at push (pushed on the coordinator's ask);
  its result goes in a follow-up note.

Not tried: a real sign-in to the Qwen AI platform. The owner's browser
has no platform session (it asks for a phone sign-in), so the complete
reply's tail past the reporter's 300 characters was not seen; a live
device/code + device/token poll answered as the fake does
({"Data":{"Status":"authorization_pending"},"RequestId":…,"Success":true}).
darwin go vet: mote's load was over 100 for the whole run; the files
have no darwin-only code, and linux and windows vet are ok.
2026-11-14 19:09:35 +08:00
..