Files
magpie/internal/provider/workbuddy_refused_test.go
T
yetone 091593f7d3 gateway, gui: a WorkBuddy account the vendor restricted (403 11140) rests 2 hours as restricted, and Routing names the appeal as the way back (#1849)
WorkBuddy answers an account it restricted for unusual activity with
403 {"code":11140,"msg":"request illegal","displayMsg":{"en":"Your
account has been restricted due to unusual activity",...}}. failure()
read it as an unknown failure, so the account rested 1-10 minutes and
was asked again, refused, all day.

What changed:
- provider: WBRestricted knows the refusal by code 11140 (top level,
  data or error; number or string; whole, so 111400 isn't it) or by its
  displayMsg words. wbExplain ends the built-in's error with
  WBRestrictedHint.
- gateway: a new failRestricted ("restricted") rests restrictedRest, 2h:
  one refused request per account per 2h, and a lifted restriction (or a
  misread refusal) comes back the same afternoon; Unrest lifts it at
  once. It is read from the hint in the error (restrictedSaid; both the
  built-in and the plugin translate the vendor's body before failure()
  sees it, so the raw JSON never reaches it in a chat try), or from the
  raw body only for a WorkBuddy candidate (restrictedRefused,
  isWorkBuddy), since another vendor's 11140 is its own. Bare "request
  illegal" is not matched. 11128 stays promptRefused and rests nobody.
  The stale-allowance shortcut skips it, as it does model refusals.
  drawsWorkBuddy now uses isWorkBuddy.
- plugin: @magpie-community/opencode-workbuddy-auth 0.1.17 (plugins
  caf3908) ends the error with the same hint; the mover's min is 0.1.17
  so keepMovedCurrent brings moved users to it.
- gui: Routing labels the try "account restricted by the vendor", says it
  rests because only the vendor lifting it brings it back and to appeal,
  shows the hint translated, and the account's row has "The restriction
  is lifted — try it again" (POST /api/gateway/unrest). en, zh, zh-TW, ja,
  de.
- docs/subsystems/gateway-routing.md says the above.

Run: gofmt -l (clean); go vet darwin, GOOS=linux -tags nogui, GOOS=windows
on gateway, provider, gui; go test ./internal/gateway ./internal/provider
./internal/gui (ok). New Go tests use the reporter's literal body through
the vendor's shape, the built-in's and the plugin's, a string code and the
words alone; another vendor's 11140, a non-WorkBuddy account with the same
body, 11128/14018/111400 not restricted; an e2e through the fake plugin
host where the restricted account is skipped by the next request.
Broken by hand, each went red: rest case removed, restrictedSaid removed,
the match unscoped, the raw match removed, the provider hint removed.
GUI: routing-wb-restricted (chromium and webkit x en/zh/zh-TW/ja/de x
1100/420px, 20 pass), routing-wb-refused, i18n-keys; after the rebase
every GUI test of the Routing page (107 files, both engines): 103 green.
The 4 red ones fail the same in WebKit on origin/main 689edbd6b run
alone and are filed: group-member-info (#1745), routing-sessions
(#1307, #1672), routing-steady (#1804, passed on this head on a rerun),
routing-group-fold's group-of-eight (#1672).
Rebased onto 2c30e5cee (with #1672's test fixes) and run again: vet x3,
go test ./internal/gateway ./internal/provider ok. On the final base
5756651e3 (only GUI assets and READMEs changed since): routing-wb-restricted
20/20, routing-wb-refused, i18n-keys, routing-held-dot, mono-icon-redraw,
routing-sessions 38/38, routing-group-fold 40/40; routing-steady's WebKit
case red again, the flake filed as #1804.
 Not tried against a real restricted account;
plugin users on <0.1.17 rest by minutes until their plugin updates.
2026-10-13 04:32:09 +08:00

44 lines
2.0 KiB
Go

package provider
import (
"path/filepath"
"strings"
"testing"
"time"
)
// Both WorkBuddy builds (the CodeBuddy plan) refuse a chat whose system
// prompt is Codex's or Claude Code's as "from an unapproved channel"
// (#182); the error says what to do about it, and other errors don't.
func TestWorkBuddyRefusedHint(t *testing.T) {
home := signIn(t)
future := time.Now().Add(24 * time.Hour).UnixMilli()
for _, f := range []string{wbAuthFile(home), filepath.Join(filepath.Dir(wbAuthFile(home)), "workbuddy-desktop-ai.info")} {
writeFile(t, f, map[string]any{
"account": map[string]any{"uid": "u1", "nickname": "me"},
"auth": map[string]any{"accessToken": "a", "refreshToken": "r", "expiresAt": future, "refreshExpiresAt": future},
})
}
refused := []byte(`{"code":11101,"msg":"Illegal API invocation from an unapproved channel"}`)
for _, id := range []string{"workbuddy", WorkBuddyAIID} {
p, ok := find(All(), id)
if !ok {
t.Fatalf("%s not signed in", id)
}
if got := p.Explain(p.Name+": Illegal API invocation from an unapproved channel", 400, refused); !strings.HasSuffix(got, " — "+WBRefusedHint) {
t.Errorf("%s: %q", id, got)
}
if got := p.Explain(p.Name+": bad", 400, []byte(`{"code":1,"msg":"first message is not system prompt"}`)); got != p.Name+": bad" {
t.Errorf("%s, another error: %q", id, got)
}
// an account WorkBuddy restricted (#1849), its 403 as it came
restricted := []byte(`{"code":11140,"msg":"request illegal","displayMsg":{"en":"Your account has been restricted due to unusual activity","zh":"账号存在异常行为,已被限制使用"}}`)
if got := p.Explain(p.Name+": request illegal", 403, restricted); got != p.Name+": request illegal — "+WBRestrictedHint {
t.Errorf("%s, restricted: %q", id, got)
}
if got := p.Explain(p.Name+": Illegal API invocation from an unapproved channel", 400, refused); strings.Contains(got, WBRestrictedHint) {
t.Errorf("%s: 11128 told as restricted: %q", id, got)
}
}
}