myduso on Discord asked for an exclusive mode on Claude's subscription: switch the credentials locally and proxy no traffic, since Claude Code is used on its own and the SDK run magpie's bridge makes spends more of the allowance than the interactive client. The switch-only setting Codex has (#1907) now also takes claude. On it, Provider.KeptToAgent is true and On() false, so the gateway, catalog, groups, fallbacks, search, draw and embeddings serve nothing on the Claude accounts, and a request naming them is refused 404 saying they are kept to Claude Code's own sign-in and how to undo it (switchedOff). Switching Claude Code's sign-in when an account is used up, and reading usage, go on: both are gated by leftAlone on the raw Off, which this doesn't set. Groups magpie found keep their Claude members (heldOffEntries). Nothing is sent as Claude Code: magpie only writes and restores Claude Code's own credentials as it already did. GUI: the tick under Claude's accounts, shown with one account too, drawn by the block Codex's tick had (one block now, its strings picked by agent). app.js stays under its budget with no raise (1,311,711 of 1,311,735). CLI: magpie accounts switch-only <codex|claude> [on|off]. Docs: reference.md, subsystems/providers-accounts.md. Run on mote at this tree on 06950fbbb; then rebased onaeacc6358(two app.js comments shorter) and go test -run TestCoreScriptBudget ./internal/gui run again at the pushed head: ok. - gofmt -l internal: clean. GOOS=linux go vet -tags nogui ./internal/... and GOOS=windows go vet ./internal/...: ok. - go test -tags nogui -count=1 -timeout 45m ./internal/provider ./internal/gateway ./internal/cli ./internal/gui: all ok. - node --test (Chromium + WebKit, every language the file covers): claude-switch-only (new), switch-only, keep-login, i18n-keys, gui-ja, gui-de, gui-zh-tw: 85 of 93 in one run beside other sessions' full GUI suites (load 23-73); the 8 reds (claude-switch-only chromium en/zh, gui-de and gui-ja in both engines) were not captured, and those files then passed alone twice (35 of 35 each run). - Earlier, at ecbd694a2 (onddf31ca30): internal/agent ok; add-sheet, api-key-usage pass; account-models and account-proxy 40/40 alone after 8 browserType.launch timeouts at load 40-70 from other sessions. Broken by hand, watched red: - On() without the KeptToAgent term: TestClaudeSwitchOnlyServesNothing- AndStillSwitches and TestClaudeKeptToClaudeCodeServesNothing fail (the gateway ran Claude Code through the bridge, 200). - SetSwitchOnly refusing claude: both fail. - app.js without the claude branch: claude-switch-only 16/16 red in Chromium, switch-only (Codex) 16/16 green. Not tried: real Claude accounts or a real Claude Code (the switch itself is the existing path, tested with a fake claude in a sandbox HOME); the whole GUI suite (only the files that open Claude's or a provider's editor, plus the i18n ones); Linux and Windows test runs (vet only).
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package gateway
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// myduso on Discord: Claude's subscription kept to Claude Code, magpie
|
|
// only switching its sign-in. A request naming the Claude accounts runs
|
|
// no Claude Code through the bridge and is told why, with how to undo it;
|
|
// unticked, it is served again.
|
|
func TestClaudeKeptToClaudeCodeServesNothing(t *testing.T) {
|
|
claudeMadeFirst(t, false)
|
|
s := New()
|
|
t.Cleanup(s.subscription.abortAll)
|
|
calls := filepath.Join(t.TempDir(), "calls")
|
|
claudeRefuses(t, calls, "tok-none") // no account refused
|
|
|
|
if err := provider.SetSwitchOnly("claude", true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
rec := askClaudeModel(s, "hi")
|
|
if rec.Code != 404 || !strings.Contains(rec.Body.String(), "kept to Claude Code's own sign-in") {
|
|
t.Fatalf("kept to Claude Code: %d %s", rec.Code, rec.Body.String())
|
|
}
|
|
if b, _ := os.ReadFile(calls); len(b) != 0 {
|
|
t.Fatalf("Claude Code run through the bridge: %q", b)
|
|
}
|
|
|
|
if err := provider.SetSwitchOnly("claude", false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if rec := askClaudeModel(s, "again"); rec.Code != 200 || !strings.Contains(rec.Body.String(), "healthy account") {
|
|
t.Fatalf("unticked: %d %s", rec.Code, rec.Body.String())
|
|
}
|
|
}
|