Files
magpie/internal/agent/main_test.go
T
yetone 32fc5809e1 agents: OpenMausBot gets magpie as an engine of its own, written as its own Claude endpoints are (a user on X)
A user on X asked for OpenMausBot (github.com/milind-soni/OpenMausBot,
read at 516ca75; released 0.1.145). Its bots run on engines from
`instances` in ~/.openmausbot/config.json ($OMB_DATA_DIR,
server/config.ts:713). Without this, a Claude bot reached magpie only
through ~/.claude/settings.json, and its picker listed Claude's static
models alone: OpenMausBot doesn't read the model from env
(readClaudeModelCatalog, claude.ts:296-316).

- openmausbot.go writes `instances.magpie` in the shape of OpenMausBot's
  own "Claude endpoint" (newClaudeEndpoint, claude-endpoints.ts:91-139):
  - driver claudeAgent, access custom
  - config.configDir is <data>/providers/magpie. Given that,
    OpenMausBot starts Claude Code with that CLAUDE_CONFIG_DIR and
    strips account keys the engine doesn't set (claudeEnvironment,
    claude.ts:111-136, 158-179), so the engine owns its routing.
  - requireApiKey
  - ANTHROPIC_BASE_URL, AUTH_TOKEN, API_KEY and MODEL point at the
    gateway
  - endpointModels holds magpie's models, kept to the ids
    CLAUDE_MODEL_ID accepts. One bad id makes OpenMausBot refuse the
    whole engine (claude.ts:636).
- A non-empty `instances` is the whole fleet (config.ts:1173). With
  none saved, magpie writes DEFAULT_FLEET (instance-fleets.ts) beside
  magpie, stashed as openmausbot.fleet. Off takes the fleet out again
  if the user hasn't changed it.
- What stays the user's: the engine's name, a model they picked from
  the list, their other env and an inherited `cli`.
- Check reports the base URL drifting away from the gateway.
- OpenMausBot reads config.json once at start (index.ts:780), and an
  engine edited in it writes back the fleet it holds
  (routes/instances.ts:132, config.ts:997-1012). So Set is refused
  while it runs (errOMBRunning), and the notice asks to quit it first,
  since Windows can't tell.
- ListOnly, ListsModels, OMB_DATA_DIR in agentenv. The icon is
  OpenMausBot's build/icon.svg (Apache-2.0).
- i18n in zh, zh-TW, ja and de. Docs: reference, agent-wiring, both
  READMEs.
- Codex bots use ~/.codex (codex.ts:373-386), which the Codex wiring
  already covers.
- The agent package's TestMain holds ombRunning false. An OpenMausBot
  open on the test machine refused every test that turns magpie on for
  each agent: my own sandbox OpenMausBot on mote turned
  TestSyncKeepsAnAddressOnAnotherMachine, TestListOnlyAgentsReadConnected
  and TestReverseProxyIsStillMagpie red. With a process named
  openmausbot running, they now pass. LiveAgent's, OpenPencil's and
  NewMax's running checks have the same hole and are left to #5587.

Run (all on mote):
- gofmt -l: clean
- go vet ./... on darwin, GOOS=linux -tags nogui and GOOS=windows: ok
- go build for the same three targets: ok
- go test -tags nogui ./... -timeout 45m at e1453a168 (this change on
  origin/main 30ae0e3f9): 88 packages ok, none failed. Rebased after
  it onto e932cd258, which changes internal/library and adds one GUI
  test only. At the pushed head: go vet of internal/agent and
  internal/library, and go test of internal/agent, agentenv and
  appdir, all ok.
- GUI: the 71 files this change reaches, in chromium and webkit, every
  language they cover: agent-*, agents-*, i18n-*, icon-*, gui-de,
  gui-ja, gui-zh-tw, about-notices, deprecation-notice, header-relang,
  market-icon-corners. 1145 of 1146 pass. The one red is i18n-keys'
  "a plugin's words are its own" for plugins' "Use the library's",
  "No session ID" and "View routing", the same on main and filed
  (#5332, #5426, #5482). The whole GUI suite was started too and
  stopped at 369 ok, 0 failed: at ~5h on mote it runs after this push.

Real OpenMausBot: 0.1.145's arm64 app was run on mote, its own server
(ELECTRON_RUN_AS_NODE, Resources/server/index.js) with HOME and
OMB_DATA_DIR in a sandbox, on a free port, against a config.json
magpie's Set wrote. /api/instances listed 28 engines, among them
`magpie`: access custom, claudeEndpoint at http://127.0.0.1:3425, and
models relay/glm-4.6 and relay/gpt-5.5 in its picker, with the first as
default. It read "unavailable: `claude` CLI not found" only because the
sandbox PATH had no claude. The file was left as magpie wrote it.

Broken by hand:
- The fleet not written: TestOpenMausBotEngine red.
- The model-id filter taken out: TestOpenMausBotEngine and
  TestOpenMausBotKeepsTheUsers red ("relay/glm 4.6 (beta)"). Green
  before a bad id was added to the fixture, so one was added.

Not tried:
- A bot turn through Claude Code to a gateway. No claude CLI or
  account on mote.
- The desktop app's window, Linux and Windows builds.
- An OpenMausBot running while magpie writes. The refusal is
  unit-tested only.
2026-11-07 13:13:36 +08:00

87 lines
4.2 KiB
Go

package agent
import (
"context"
"encoding/json"
"errors"
"os"
"testing"
"github.com/yetone/magpie/internal/netproxy"
"github.com/yetone/magpie/internal/testenv"
)
// TestMain gives the package a home of its own (testenv). A home an agent is
// found through can sit outside HOME — DSH_HOME does — and the package's
// tests sandbox HOME alone: left as the developer has it, a test that picks
// a model writes it into the real ~/.dsh/profiles, and dsh then refuses
// every turn with a model its provider does not list. internal/gateway,
// internal/provider and internal/usage isolate themselves the same way.
func TestMain(m *testing.M) {
if len(os.Args) == 3 && os.Args[1] == DryRunArg {
if err := DryRun(os.Args[2]); err != nil {
os.Stderr.WriteString(err.Error())
os.Exit(1)
}
os.Exit(0)
}
// whether Codex's ChatGPT account is out of its allowance is asked of
// OpenAI; never from here
codexUsedUp = func() bool { return false }
// a thread a Codex holds open is looked at again later, on its own
// goroutine, which would outlive its test; the tests about it set
// their own wait
codexThreadsAgain = func() {}
codexThreadsFor.Store(0)
// Sandboxed config writes must never write into the real OS keychain.
zedCredential = func(string) error { return nil }
// Pi's and omp's model registries are read from their installs; never
// this machine's
nodeModulesOf = func(string, []string) []string { return nil }
// Microsoft Store apps are read from the current user's AppX registry;
// never this machine's (a Windows box with the Codex app installed)
windowsStorePackages = func() []string { return nil }
// nor what an installer registered there (DeepSeek Harness Desktop's
// folder, #2279)
windowsRegisteredApp = func(string) (string, string) { return "", "" }
// nor where this Mac's Spotlight has an app (DeepSeek Harness.app
// outside /Applications, #2325)
spotlightApps = func(string) []string { return nil }
// whether OpenMausBot is open is never this machine's: one open there
// refused every test that turns magpie on for each agent; the tests
// about it say their own
ombRunning = func() bool { return false }
// a desktop app's Restart never quits or opens one of this machine's
// (the Codex app, Claude Desktop, WorkBuddy the developer runs); the
// restart tests stand in for each step
appQuit = func(context.Context, string) error { return errors.New("no app is quit in a test") }
appOpen = func(context.Context, string) error { return errors.New("no app is opened in a test") }
winProcs = func(string) []winProc { return nil }
winClose = func([]int) error { return errors.New("no app is closed in a test") }
winEnd = func(int) error { return errors.New("no app is ended in a test") }
winLaunch = func(winProc) error { return errors.New("no app is opened in a test") }
// Aside's default is changed through the aside binary, which answers for
// the account the developer is actually running: a test that picks a
// model would change the real Aside's default, and the running one would
// keep the old one, so the test would read back a file nothing had
// applied. The Aside tests stand in for it themselves.
asideSet = func(string, string) error { return errors.New("aside: no Aside in a test") }
asideRead = func(string) (map[string]json.RawMessage, error) { return nil, errors.New("aside: no Aside in a test") }
// an address an agent is pointed at is tried over the network (Drift,
// #1013); never from a test, whose reach tests stand in for it
reachProbe = func(string) bool { return true }
// nor is the way Codex goes there read from this machine's proxy
// settings, or a proxy tried; the proxy tests say both
codexProxyEnv = func(string) string { return "" }
// nor Claude Code's provider switches read from the login shell; the
// cloud tests say what one there does
claudeShellEnv = func(string) string { return "" }
codexSystemProxy = func() netproxy.Proxy { return netproxy.Proxy{} }
proxyProbe = func(string, string) bool { return true }
// nor an address of the agent's own asked whether magpie answers
// there (a reverse proxy, #1985): known, and not magpie, as for a
// relay; the proxy-kept tests answer it
magpieAt = func(string) (bool, bool) { return false, true }
os.Exit(testenv.Run(m))
}