agents: "Hide all" in an agent's model list keeps its line, and an uninstalled Gemini CLI goes from the Agents page (#356, #230) — the line under an agent ("Showing 0 / N models") came only when a picker still listed one of magpie's models, so hiding them all took away the one way back; it now stays while any is hidden. Gemini CLI was taken as present from what it leaves in ~/.gemini (settings.json, .env, installation_id…), which stays after it is uninstalled, so its row stayed, offering to set up a CLI that can't run; it is now its gemini binary. TestAgentModelLineAllHidden and TestGeminiNotAntigravity fail without the change; agent-models-all-hidden.test.cjs (Chromium, WebKit, en/zh) added. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./internal/agent ./internal/gui ./internal/library ./internal/provider pass; agent-models, click-scroll, old-webkit pass.

This commit is contained in:
yetone
2026-10-01 01:03:57 +08:00
parent ee5b1b7d44
commit c47b22ee27
9 changed files with 231 additions and 62 deletions
+6 -16
View File
@@ -2,7 +2,6 @@ package agent
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
@@ -164,25 +163,16 @@ func gemini(home string) *Agent {
ID: "gemini", Name: "Gemini CLI", Icon: "geminicli-color", Aliases: []string{"gemini-cli"},
UA: []string{"geminicli", "gemini-cli"},
Bin: "gemini", Dir: dir, Path: path,
// Antigravity keeps its folders under ~/.gemini too (antigravity,
// antigravity-cli, config) and reads GEMINI.md there, so the folder
// alone is no sign of Gemini CLI (#330): only what Gemini CLI itself
// writes there, or its binary, is
// Gemini CLI is its binary. What it leaves in ~/.gemini stays when it
// is uninstalled (#230), and Antigravity keeps its folders there too
// (antigravity, antigravity-cli, config) and reads GEMINI.md (#330),
// so nothing there says Gemini CLI is here: a row for it would set
// up a CLI that can't run. The desktop app's PATH has the user's
// shell's (proc.UserPath).
detect: func() bool {
if Taken(dir) {
return false
}
for _, f := range []string{"settings.json", ".env", "google_accounts.json", "installation_id", "trustedFolders.json", "mcp-oauth-tokens.json"} {
if _, err := os.Stat(filepath.Join(dir, f)); err == nil {
return true
}
}
// a sign-in another app's OAuth client minted there isn't
// Gemini CLI's (#143)
creds := filepath.Join(dir, "oauth_creds.json")
if _, err := os.Stat(creds); err == nil && !provider.AnotherAppsGoogleSignIn(creds) {
return true
}
_, err := exec.LookPath("gemini")
return err == nil
},
+9 -21
View File
@@ -1,7 +1,6 @@
package agent
import (
"encoding/base64"
"os"
"path/filepath"
"runtime"
@@ -9,7 +8,8 @@ import (
)
// TestGeminiNotAntigravity: a ~/.gemini holding only what Antigravity keeps
// there is no Gemini CLI (#330); what Gemini CLI writes, or its binary, is.
// there is no Gemini CLI (#330), nor one holding what Gemini CLI left when
// it was uninstalled (#230); its binary is.
func TestGeminiNotAntigravity(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
@@ -27,26 +27,14 @@ func TestGeminiNotAntigravity(t *testing.T) {
t.Fatal("agy not detected from ~/.gemini/antigravity-cli")
}
// a sign-in Antigravity's OAuth client minted there isn't Gemini CLI's
creds := filepath.Join(dir, "oauth_creds.json")
claims := base64.RawURLEncoding.EncodeToString([]byte(`{"azp":"other.apps.googleusercontent.com","aud":"other.apps.googleusercontent.com"}`))
os.WriteFile(creds, []byte(`{"refresh_token":"r","id_token":"e30.`+claims+`.sig"}`), 0o600)
// what Gemini CLI leaves behind when it is uninstalled (#230): its
// settings, its sign-in, its ids, all of it
os.WriteFile(filepath.Join(dir, "oauth_creds.json"), []byte(`{"refresh_token":"r"}`), 0o600)
for _, f := range []string{"settings.json", ".env", "google_accounts.json", "installation_id", "trustedFolders.json", "mcp-oauth-tokens.json"} {
os.WriteFile(filepath.Join(dir, f), []byte("{}"), 0o644)
}
if gemini(home).Detected() {
t.Fatal("another app's sign-in taken for Gemini CLI")
}
os.WriteFile(creds, []byte(`{"refresh_token":"r"}`), 0o600)
if !gemini(home).Detected() {
t.Fatal("Gemini CLI's sign-in not detected")
}
os.Remove(creds)
for _, f := range []string{"settings.json", ".env", "google_accounts.json", "installation_id"} {
p := filepath.Join(dir, f)
os.WriteFile(p, []byte("{}"), 0o644)
if !gemini(home).Detected() {
t.Fatalf("%s not taken for Gemini CLI", f)
}
os.Remove(p)
t.Fatal("an uninstalled Gemini CLI's leftovers taken for it")
}
if runtime.GOOS == "windows" {
+30
View File
@@ -50,6 +50,36 @@ func takesCatalog(fields []fieldJSON) bool {
return false
}
// agentFields are an agent's pickers as the Agents page draws them.
func agentFields(a *agent.Agent, vals map[string]string) []fieldJSON {
out := []fieldJSON{}
for _, f := range a.Fields {
opts := f.Options(vals)
if opts == nil {
opts = []agent.Option{}
}
out = append(out, fieldJSON{Key: f.Key, Label: f.Label, Value: vals[f.Key], Options: opts})
}
return out
}
// agentModelCount is the line under an agent's name, nil for an agent that
// doesn't pick among the catalog. Its pickers list only the models shown, so
// with every one taken out they have no catalog entry left, yet the line is
// the one way to put them back (#356): it stays while any is hidden.
func agentModelCount(id string, fields []fieldJSON) *modelCountJSON {
if takesCatalog(fields) {
return modelCount(id)
}
if len(provider.HiddenModels(id)) == 0 {
return nil
}
if c := modelCount(id); c.Shown < c.Listed {
return c
}
return nil
}
func modelCount(id string) *modelCountJSON {
listed, _ := provider.ListedFor(id)
off := provider.HiddenModels(id)
+44
View File
@@ -10,6 +10,7 @@ import (
"strings"
"testing"
"github.com/yetone/magpie/internal/agent"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
)
@@ -75,3 +76,46 @@ func TestAgentModelsAPI(t *testing.T) {
t.Fatalf("%+v", got.Count)
}
}
// Every model taken out of an agent's lists leaves its pickers no catalog
// entry, yet the line under its name stays, "Showing 0 / N", as the way to
// put them back (#356).
func TestAgentModelLineAllHidden(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
t.Setenv("CODEX_HOME", filepath.Join(home, ".codex"))
os.MkdirAll(filepath.Join(home, ".codex"), 0o755)
os.WriteFile(filepath.Join(home, ".codex", "config.toml"), []byte("model = \"gpt-5.5\"\n"), 0o600)
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m1", "m2"}}); err != nil {
t.Fatal(err)
}
a, err := agent.Find("codex")
if err != nil {
t.Fatal(err)
}
line := func() *modelCountJSON { return agentModelCount(a.ID, agentFields(a, a.Values())) }
c := line()
if c == nil || c.Shown != c.Listed || c.Listed < 2 {
t.Fatalf("all shown: %+v", c)
}
var all []string
listed, _ := provider.ListedFor("codex")
for _, e := range listed {
all = append(all, e.ID)
}
if err := provider.SetHiddenModels("codex", all); err != nil {
t.Fatal(err)
}
if takesCatalog(agentFields(a, a.Values())) {
t.Fatal("a picker still lists a catalog entry; the case isn't reached")
}
if c := line(); c == nil || c.Shown != 0 || c.Listed != len(all) {
t.Fatalf("all hidden: %+v", c)
}
provider.SetHiddenModels("codex", nil)
if c := line(); c == nil || c.Shown != c.Listed {
t.Fatalf("put back: %+v", c)
}
}
+2 -11
View File
@@ -728,17 +728,8 @@ func state() stateJSON {
}
for _, a := range agent.Detected() {
vals := a.Values()
aj := agentJSON{ID: a.ID, Name: a.Name, Icon: a.Icon, Path: tilde(a.Path), Fields: []fieldJSON{}}
for _, f := range a.Fields {
opts := f.Options(vals)
if opts == nil {
opts = []agent.Option{}
}
aj.Fields = append(aj.Fields, fieldJSON{Key: f.Key, Label: f.Label, Value: vals[f.Key], Options: opts})
}
if takesCatalog(aj.Fields) {
aj.Models = modelCount(a.ID)
}
aj := agentJSON{ID: a.ID, Name: a.Name, Icon: a.Icon, Path: tilde(a.Path), Fields: agentFields(a, vals)}
aj.Models = agentModelCount(a.ID, aj.Fields)
aj.Drift = a.Drift()
if a.Import != nil {
aj.Import, aj.Added = a.Import(), a.Added != nil && a.Added()
+8 -1
View File
@@ -52,6 +52,13 @@ it and over no other icon (the browser's tooltip put Devin's name on ZCode's
Z), moves at once to the next icon, and goes on a click, on leaving, and when
Esc closes the picker; a rail icon focused from the keyboard is named too.
`agent-models-all-hidden.test.cjs` takes every model out of DeepSeek
Harness's lists with "Hide all" (#356): the line under its name reads
"Showing 0 / 3 models" (显示 0 / 3 个模型), stays once the list is closed and
the agents are drawn again from the state, and opens the list again, where
"Show all" puts them back; no click moves the page. Chromium and WebKit,
English and Chinese.
`agent-models.test.cjs` opens Codex's model list from the line under its
name, in Chromium and WebKit, English and Chinese: the line reads "Showing 8 /
31 models" under the name, opening it moves nothing and puts it on the screen
@@ -464,7 +471,7 @@ and the next stop is the lowest level. Chromium and WebKit.
With Node.js and Playwright available:
```sh
node --test internal/gui/tests/menu-scroll.test.cjs internal/gui/tests/click-scroll.test.cjs internal/gui/tests/panel-fold.test.cjs internal/gui/tests/panel-routing.test.cjs internal/gui/tests/gateway-fold.test.cjs internal/gui/tests/routing-kind.test.cjs internal/gui/tests/balance-fix.test.cjs internal/gui/tests/cli-update.test.cjs internal/gui/tests/login-import.test.cjs internal/gui/tests/agy-launch.test.cjs internal/gui/tests/currency.test.cjs internal/gui/tests/usage-ledger.test.cjs internal/gui/tests/update-check.test.cjs internal/gui/tests/omarchy.test.cjs internal/gui/tests/brand.test.cjs node --test internal/gui/tests/signin-callback.test.cjs internal/gui/tests/routing-steady.test.cjs internal/gui/tests/old-webkit.test.cjs internal/gui/tests/session-terminal.test.cjs internal/gui/tests/text-size.test.cjs internal/gui/tests/zcode-site.test.cjs internal/gui/tests/rail-tip.test.cjs internal/gui/tests/sync-update.test.cjs internal/gui/tests/plugin-signin.test.cjs internal/gui/tests/plugin-market.test.cjs internal/gui/tests/s3-sync.test.cjs internal/gui/tests/routing-wb-refused.test.cjs internal/gui/tests/market-have.test.cjs internal/gui/tests/sessions-today.test.cjs internal/gui/tests/routing-side-calls.test.cjs internal/gui/tests/import-all-skills.test.cjs internal/gui/tests/routing-flood.test.cjs internal/gui/tests/routing-busy.test.cjs internal/gui/tests/own-skill.test.cjs internal/gui/tests/routing-manual.test.cjs internal/gui/tests/tray-usages.test.cjs internal/gui/tests/provider-remove.test.cjs internal/gui/tests/signin-link.test.cjs internal/gui/tests/tray-inuse.test.cjs internal/gui/tests/codex-auto-reset.test.cjs internal/gui/tests/routing-auto-reset.test.cjs internal/gui/tests/claude-resets.test.cjs internal/gui/tests/library-toggle-status.test.cjs internal/gui/tests/library-all.test.cjs internal/gui/tests/routing-reroute-title.test.cjs internal/gui/tests/plain-names.test.cjs internal/gui/tests/panel-effort.test.cjs
node --test internal/gui/tests/menu-scroll.test.cjs internal/gui/tests/click-scroll.test.cjs internal/gui/tests/panel-fold.test.cjs internal/gui/tests/panel-routing.test.cjs internal/gui/tests/gateway-fold.test.cjs internal/gui/tests/routing-kind.test.cjs internal/gui/tests/balance-fix.test.cjs internal/gui/tests/cli-update.test.cjs internal/gui/tests/login-import.test.cjs internal/gui/tests/agy-launch.test.cjs internal/gui/tests/currency.test.cjs internal/gui/tests/usage-ledger.test.cjs internal/gui/tests/update-check.test.cjs internal/gui/tests/omarchy.test.cjs internal/gui/tests/brand.test.cjs node --test internal/gui/tests/signin-callback.test.cjs internal/gui/tests/routing-steady.test.cjs internal/gui/tests/old-webkit.test.cjs internal/gui/tests/session-terminal.test.cjs internal/gui/tests/text-size.test.cjs internal/gui/tests/zcode-site.test.cjs internal/gui/tests/rail-tip.test.cjs internal/gui/tests/sync-update.test.cjs internal/gui/tests/plugin-signin.test.cjs internal/gui/tests/plugin-market.test.cjs internal/gui/tests/s3-sync.test.cjs internal/gui/tests/routing-wb-refused.test.cjs internal/gui/tests/market-have.test.cjs internal/gui/tests/sessions-today.test.cjs internal/gui/tests/routing-side-calls.test.cjs internal/gui/tests/import-all-skills.test.cjs internal/gui/tests/routing-flood.test.cjs internal/gui/tests/routing-busy.test.cjs internal/gui/tests/own-skill.test.cjs internal/gui/tests/routing-manual.test.cjs internal/gui/tests/tray-usages.test.cjs internal/gui/tests/provider-remove.test.cjs internal/gui/tests/signin-link.test.cjs internal/gui/tests/tray-inuse.test.cjs internal/gui/tests/codex-auto-reset.test.cjs internal/gui/tests/routing-auto-reset.test.cjs internal/gui/tests/claude-resets.test.cjs internal/gui/tests/library-toggle-status.test.cjs internal/gui/tests/library-all.test.cjs internal/gui/tests/routing-reroute-title.test.cjs internal/gui/tests/plain-names.test.cjs internal/gui/tests/panel-effort.test.cjs internal/gui/tests/agent-models-all-hidden.test.cjs
```
If Playwright is installed outside the repository, set `NODE_PATH` to the
@@ -0,0 +1,126 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// Every model taken out of an agent's lists (#356, DeepSeek Harness): the
// line under its name stays, "Showing 0 / 3 models", and opens the list to
// put them back. Its pickers then list only the agent's own models, and the
// line had gone with the catalog entries, leaving no way back.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
function fixture(lang) {
const list = ["deepseek-v4-pro", "deepseek-v4-flash", "deepseek-r2"].map((m) =>
({ id: "deepseek/" + m, name: m, group: "DeepSeek", icon: "deepseek-color", context: 1e6 }));
const posts = [];
let stateCalls = 0;
const count = () => ({ shown: list.filter((m) => !m.hidden).length, listed: list.length });
const state = () => {
stateCalls++;
// its own models, and the catalog's shown ones
const options = [{ value: "deepseek-v4-pro", label: "DeepSeek-V4-Pro", group: "DeepSeek Harness" },
...list.filter((m) => !m.hidden).map((m) => ({ value: "magpie/" + m.id, label: m.name, ref: m.id }))];
return {
agents: [{
id: "dsh", name: "DeepSeek Harness", path: "/test/.dsh/config.json", icon: "deepseek-color",
fields: [{ key: "model", label: "model", value: "deepseek-v4-pro", options }],
models: count(),
}],
profiles: [], settings: { lang, theme: "light" },
};
};
async function serve(route) {
const req = route.request();
const url = new URL(req.url());
const json = (data) => route.fulfill({ json: data });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json(state());
if (url.pathname === "/api/agent-models/dsh") {
if (req.method() === "POST") {
const { hidden } = req.postDataJSON();
posts.push(hidden);
for (const m of list) m.hidden = hidden.includes(m.id);
return json({ models: list, count: count() });
}
return json({ models: list });
}
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/groups") return json({ groups: [] });
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, window: true } });
if (url.pathname.startsWith("/api/")) return json({});
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
await route.fulfill({ body: await fs.readFile(file), contentType });
}
return { serve, posts, stateCalls: () => stateCalls };
}
const W = {
en: { all: "All 3 models", none: "Showing 0 / 3 models", hideAll: "Hide all", showAll: "Show all" },
zh: { all: "全部 3 个模型", none: "显示 0 / 3 个模型", hideAll: "全部隐藏", showAll: "全部显示" },
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh"]) {
test(`${engine} ${lang}: every model hidden, the line stays to put them back`, async (t) => {
const w = W[lang];
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await browser.newPage({ viewport: { width: 1000, height: 700 } });
page.setDefaultTimeout(5000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
const fx = fixture(lang);
await page.route("**/*", fx.serve);
t.after(async () => {
if (process.env.ARTIFACT_DIR) {
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-all-hidden.png`) });
}
await browser.close();
});
await page.goto("http://magpie.test/");
const entry = page.locator('.row.agent[data-id="dsh"] .ag-models');
await entry.waitFor();
assert.equal((await entry.innerText()).trim(), w.all);
const scroll = () => page.evaluate(() => [scrollY, document.scrollingElement.scrollTop, $("#view-agents").scrollTop]);
const was = await scroll();
await entry.click();
const pop = page.locator(".am-pop:not(.leaving)");
await pop.waitFor();
await pop.locator(".am-hide").click();
await page.waitForTimeout(150);
assert.equal(fx.posts.at(-1).length, 3);
assert.equal((await entry.innerText()).trim(), w.none);
// closed, the agents are drawn again from the state: the line stays
const before = fx.stateCalls();
await page.keyboard.press("Escape");
await pop.waitFor({ state: "detached" });
await page.waitForTimeout(300);
assert(fx.stateCalls() > before, "the state is asked for again");
await entry.waitFor();
assert.equal((await entry.innerText()).trim(), w.none);
assert.equal(await entry.locator("b").innerText(), "0");
// and opens the list to show them all again
await entry.click();
await pop.waitFor();
const showAll = pop.locator(".am-reset:not(.am-hide)");
assert.equal(await showAll.innerText(), w.showAll);
await showAll.click();
await page.waitForTimeout(150);
assert.deepEqual(fx.posts.at(-1), []);
assert.equal((await entry.innerText()).trim(), w.all);
await page.keyboard.press("Escape");
await pop.waitFor({ state: "detached" });
await page.waitForTimeout(300);
assert.equal((await entry.innerText()).trim(), w.all);
assert.deepEqual(await scroll(), was, "no click moved the page");
assert.deepEqual(errors, []);
});
}
}
+6 -1
View File
@@ -28,7 +28,12 @@ func sandbox(t *testing.T) string {
t.Setenv("HOME", h)
t.Setenv("USERPROFILE", h)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
t.Setenv("PATH", "")
// Gemini CLI is found by its binary alone
bin := filepath.Join(h, "bin")
write(t, filepath.Join(bin, "gemini"), "#!/bin/sh\n")
os.Chmod(filepath.Join(bin, "gemini"), 0o755)
write(t, filepath.Join(bin, "gemini.exe"), "")
t.Setenv("PATH", bin)
// never the machine's global node_modules
roots := piGlobalRoots
piGlobalRoots = func() []string { return nil }
-12
View File
@@ -165,18 +165,6 @@ func geminiOwnLogin() (googleAccount, bool) {
return googleAccount{app: app, user: user, auth: a, own: true}, true
}
// AnotherAppsGoogleSignIn reports whether the Google sign-in in the
// oauth_creds.json at path was minted by an OAuth client other than Gemini
// CLI's (Antigravity's, #143): the file is then no sign of Gemini CLI.
func AnotherAppsGoogleSignIn(path string) bool {
var id struct {
IDToken string `json:"id_token"`
}
readJSON(path, &id)
c := googleClientOf(id.IDToken)
return c != "" && c != geminiApp.clientID
}
// googleClientOf is the OAuth client a Google ID token was minted for, ""
// when there is none to tell.
func googleClientOf(idToken string) string {