Open Code Review (github.com/alibaba/open-code-review, npm @alibaba-group/open-code-review) is a Go CLI, `ocr`, that reviews a diff with a model. Its Claude Code, Codex, Cursor, Kimi Code and OpenCode plugins and its skills all run that command, which reads ~/.opencodereview/config.json on every run. Picking one of magpie's models on its row writes a custom provider "magpie" there (protocol openai, the gateway's /v1, a key naming Open Code Review, the model) and points provider at it. The user's own provider and model are stashed and come back on Disconnect, which also drops a custom_providers left empty. A model of the user's own can be picked too (written the way `ocr config model` writes it). Check reports a hand-edited url or key, or a removed entry. The `ocr` command counts only under a folder named for Open Code Review, since other programs share the name. WSL distros get the row too (cold distros not opened). Its User-Agent, open-code-review/<version>, already counts as this agent. CLI update via npm. Docs, READMEs, site and icon (OCR's own logo, Apache-2.0). Run (mica, at 593517bf0; origin/main has one unrelated usage commit since): - go test ./internal/agent -run 'TestOCR|WSL|Wsl|TestOwnProviderNamedAsMagpies|TestHandWiredMagpieProviderSiblings|TestAgentOf|TestEveryAgentNamedByItsKey|TestMarkedLinesEveryAgent': ok - gofmt -l: clean; GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./...: ok - Broken by hand: url dropped from Check -> TestOCRWiring red; stash turned off -> red at the Disconnect restore. TestWSLColdPlaceOpensNothing went red before the row's options were given an asleep path. - Real e2e in a sandbox HOME: npm-installed ocr v1.13.10 (7e5ce06c) darwin/arm64, magpie built from this tree, a fake OpenAI upstream that calls tools. `magpie agents` lists the row with the user's deepseek/deepseek-chat; `magpie open-code-review magpie/fake/m1` wrote the entry and kept the user's keys and settings; `ocr llm test`: connection ok, tool-call round trip verified; `ocr review` on a repo with a nil dereference: 2 findings "[bug · high]" through magpie (8 /v1/chat/completions calls, UA open-code-review/v1.13.10, model m1, its six review tools); `magpie usage` counts them under Open Code Review; `magpie open-code-review default` put deepseek/deepseek-chat back and removed custom_providers. - Full suite: not run before this push (ship at once; mote was running another session's suite). It runs on mica right after, at this head. Not tried: a real vendor model behind magpie; WSL and Windows/Linux machines for real; the Claude Code / OpenCode plugin path itself (it runs the same `ocr`); an ocr installed by the curl script outside a folder named for it is found by ~/.opencodereview only.
101 lines
3.8 KiB
Go
101 lines
3.8 KiB
Go
package agent
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// An agent that spells a model provider/model, magpie's as magpie/<ref>:
|
|
// one of its own providers named as one of magpie's (its own relay, and
|
|
// magpie's relay) is its own model, not magpie's. The row isn't connected
|
|
// on it, and Disconnect from magpie puts it back and is done, rather than
|
|
// leaving the row connected on the model it went back to (#835, OpenHanako's
|
|
// own deepseek/deepseek-v4-pro).
|
|
func TestOwnProviderNamedAsMagpies(t *testing.T) {
|
|
ids := []string{"agy", "opencode", "openchamber", "mimocode", "deveco", "pi", "aside", "omo", "prime-agent", "mu", "goose", "zed", "vscode",
|
|
"crush", "dsh", "ds-bot", "commandcode", "fx", "omp", "hermes", "morph", "kimi", "empryo", "nanobot", "miniq", "paimon", "craft-agents", "minimax-code", "droid",
|
|
"qoder", "qoder-cn", "grok", "atomcode", "cline", "snow", "qwenpaw", "open-code-review"}
|
|
for _, id := range ids {
|
|
t.Run(id, func(t *testing.T) {
|
|
if id == "aside" {
|
|
asideHome(t)
|
|
} else if home := syncHome(t); id == "qwenpaw" {
|
|
qwenpawFixture(t, home)
|
|
}
|
|
a, err := Find(id)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
f := &a.Fields[0]
|
|
if id == "miniq" {
|
|
// a provider of the user's own, for its own model to be on
|
|
hanakoWrite(t, a.Path, `{"provider":{"baseUrl":"https://relay.example/v1","apiKey":"sk-own","model":"glm-4.5","apiProtocol":"auto"}}`, 0o600)
|
|
}
|
|
if id == "craft-agents" {
|
|
// Craft's own config, with a connection of the user's
|
|
hanakoWrite(t, a.Path, craftUser, 0o644)
|
|
}
|
|
if id == "open-code-review" {
|
|
// a custom provider of the user's own, for its own model
|
|
// to be on
|
|
hanakoWrite(t, a.Path, `{"custom_providers":{"relay":{"protocol":"openai","url":"https://relay.example/v1","api_key":"sk-own"}}}`, 0o600)
|
|
}
|
|
if id == "cline" {
|
|
// a model of OpenRouter's, the provider Cline is on
|
|
hanakoWrite(t, a.Path, `{"version":1,"modes":{},"providers":{},"lastUsedProvider":"openrouter"}`, 0o600)
|
|
}
|
|
if err := f.Set("relay/glm-4.6"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v := f.Get(); v != "relay/glm-4.6" {
|
|
t.Fatalf("own model reads %q", v)
|
|
}
|
|
if a.Wired() {
|
|
t.Fatal("its own relay/glm-4.6 reads as magpie's")
|
|
}
|
|
if err := a.Connect(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !a.Wired() {
|
|
t.Fatalf("not connected after Connect: %v", a.Values())
|
|
}
|
|
if err := a.Disconnect(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if a.Wired() {
|
|
t.Fatalf("still connected after Disconnect: %v", a.Values())
|
|
}
|
|
if v := f.Get(); v != "relay/glm-4.6" {
|
|
t.Errorf("Disconnect left %q, not its own relay/glm-4.6", v)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// OpenCode's own provider that sends to magpie's gateway is magpie's all
|
|
// the same (openCodeRef names a model there by it), once magpie set
|
|
// OpenCode up: before that, it is a provider the user wrote by hand and
|
|
// theirs (handWired, JFunfunfun on X).
|
|
func TestOpenCodeGatewayProviderIsMagpies(t *testing.T) {
|
|
syncHome(t)
|
|
a, err := Find("opencode")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
hanakoWrite(t, a.Path, `{"provider":{"relay":{"options":{"baseURL":"`+gatewayV1()+`"},"models":{"relay/glm-4.6":{}}}},"model":"relay/relay/glm-4.6"}`, 0o644)
|
|
if a.Wired() {
|
|
t.Fatalf("its own provider at the gateway, written by hand, reads as connected: %v", a.Values())
|
|
}
|
|
// as magpie opencode relay/glm-4.6 sets it (9b1641a49)
|
|
if err := a.Apply("model", "relay/relay/glm-4.6"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !a.Wired() {
|
|
t.Fatalf("a model through its own provider at the gateway isn't magpie's: %v (%s)", a.Values(), filepath.Base(a.Path))
|
|
}
|
|
hanakoWrite(t, a.Path, `{"provider":{"relay":{"options":{"baseURL":"https://x/v1"},"models":{"glm-4.6":{}}}},"model":"relay/glm-4.6"}`, 0o644)
|
|
if a.Wired() {
|
|
t.Fatalf("its own relay elsewhere reads as magpie's: %v", a.Values())
|
|
}
|
|
}
|