Files
magpie/internal/gateway/agentpath_test.go
T
yetone 93a33d8174 agent: OpenBot's icon, its requests named its own, its skills in the Library (SSNQT on X)
SSNQT on X, magpie 0.1.3503 on macOS, OpenBot (611ce90d1): no icon in
the Agents list, its requests listed as OpenCode's, and no way to pick
it for skills or MCP servers in the Library.

- Icon: OpenBot's production icon (build/icon-production.png in
  nightly-labs/openbot, 128px) as icons/openbot.png, in pngIcons and in
  app.css's tile rule (a solid tile, icon-tile.test.cjs); openbot is off
  client_icons_test's generic list.
- Requests: OpenBot seals an endpoint's key and headers in safeStorage,
  which magpie can't write, and hands the endpoint to the OpenCode it
  runs, so every request came with OpenCode's User-Agent and nothing of
  OpenBot's. magpie's entry is now at <gateway>/agent/openbot/v1
  (gateway.AgentURL). lanGuard takes /agent/<id> off the path when <id>
  is an agent magpie knows (takeAgentPath), agentOf names that agent
  first, and startedByAgent never takes such a request for a script. An
  unknown id is left in the path (404 as before). An entry written at
  /v1 is rewritten at the next sync; OpenBot reads it after a restart,
  which its notice already says. Requests recorded before stay
  OpenCode's.
- Library: an openbot target with skills in ~/.agents/skills, the only
  folder OpenBot reads (home-skills.ts, HOME_SKILL_FOLDER). Its MCP
  servers are rows in its SQLite database (openbot.db,
  projection_mcp_servers), which magpie doesn't write, so it stays out
  of the MCP picker: #5896.
- Guard: TestEveryAgentInLibrary fails for a built-in agent that has no
  Library target and isn't in noLibrary with a reason. 34 agents had
  none when it landed; they are listed as "not looked at (#5897)". The
  icon guard (TestEveryClientHasNameAndIcon) and the agent-name guard
  (TestIsAgentByUserAgent) were there already.

Run (mote unless said): gofmt -l internal (clean); go vet darwin, GOOS=linux
-tags nogui, GOOS=windows on agent, gateway, library, gui: ok;
go test -count=1 ./internal/agent ./internal/gateway ./internal/library
./internal/gui ./internal/usage: all ok but internal/gui's
TestUpdateSlowDownloadOutlastsTheCheckBound (its check request hit its
deadline with four other suites on the box; passes 3 of 3 alone; the
updater isn't touched here; #5905); TestAgentInPath and
TestEveryAgentInLibrary on Windows (win-run): ok; GUI i18n-keys,
icon-tile, icon-one-tone, icon-builtin-over-address,
routing-client-icons, library-pick-remove: chromium 101/101, webkit
54/54. Real gateway (nogui build, sandbox HOME, port 3591): a POST to
/agent/openbot/v1/chat/completions with OpenCode's User-Agent was
recorded as agent openbot, the same at /v1 as opencode, and
/agent/openbot/v1/models answered the list.

Broken by hand, each red: the takeAgentPath call in lanGuard taken out
(TestAgentInPath: path kept, agent opencode); the pathAgent check in
agentOf taken out (agent opencode); the openbot case in targetOf renamed
(TestEveryAgentInLibrary: openbot has no place); Icon back to generic
(TestEveryClientHasNameAndIcon).

Not tried: real OpenBot or a real OpenCode sending to the new address
(the URL is built as `${baseURL}/chat/completions` by
@ai-sdk/openai-compatible, read in its source); the full suite (runs
after the tag).
2026-11-10 15:56:21 +08:00

61 lines
2.3 KiB
Go

package gateway
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/yetone/magpie/internal/usage"
)
// SSNQT on X: OpenBot's requests were listed as OpenCode's. OpenBot hands
// magpie's endpoint to the OpenCode it runs, keyless (its key and headers
// are sealed where magpie can't write), so the request carries OpenCode's
// User-Agent and nothing of OpenBot's. Its address names it instead:
// /agent/openbot/v1/… is served as /v1/… from OpenBot. A path naming no
// agent is left as it is.
func TestAgentInPath(t *testing.T) {
fresh(t)
t.Setenv("MAGPIE_ADDR", "")
// package agent lists the agents (usage.Agents), and isn't linked here
was := usage.PluginAgents
usage.PluginAgents = func() []usage.Known {
return []usage.Known{{ID: "openbot", Names: []string{"openbot"}}, {ID: "opencode", Names: []string{"opencode"}, UA: []string{"opencode"}}}
}
t.Cleanup(func() { usage.PluginAgents = was })
var seen *http.Request
h := lanGuard(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { seen = r }))
call := func(path string) *http.Request {
seen = nil
r := httptest.NewRequest("POST", "http://127.0.0.1:3425"+path, nil)
r.RemoteAddr = "127.0.0.1:50000"
r.Header.Set("User-Agent", "opencode/1.14.20 ai-sdk/provider-utils/3.0.20 runtime/bun/1.3.13")
h.ServeHTTP(httptest.NewRecorder(), r)
if seen == nil {
t.Fatalf("%s: not served", path)
}
return seen
}
r := call("/agent/openbot/v1/chat/completions?x=1")
if r.URL.Path != "/v1/chat/completions" || r.URL.RawQuery != "x=1" || r.RequestURI != "/v1/chat/completions?x=1" {
t.Errorf("served at %q (%q)", r.URL.Path, r.RequestURI)
}
if got := agentOf(r); got != "openbot" {
t.Errorf("agent %q, want openbot", got)
}
if startedByAgent(r, "opencode") {
t.Error("a request its path names counts as one an agent started")
}
if got := agentOf(call("/v1/chat/completions")); got != "opencode" {
t.Errorf("without the path: agent %q, want opencode", got)
}
for _, p := range []string{"/agent/nobody/v1/models", "/agent//v1/models", "/agent/"} {
if r := call(p); r.URL.Path != p || agentOf(r) != "opencode" {
t.Errorf("%s: served at %q as %q", p, r.URL.Path, agentOf(r))
}
}
if got := AgentURL("http://127.0.0.1:3425/", "openbot"); got != "http://127.0.0.1:3425/agent/openbot" {
t.Errorf("AgentURL: %q", got)
}
}