gui: Image recognition says where a custom provider's model is marked as seeing (nexnull)

nexnull on Discord: a model of a provider added by its address isn't
offered for Image recognition until something says it takes images, and
nothing said so. /api/settings now has visionNotMarked: the providers
(AddedByAddress, ready) with a model left out of visionModels only
because nothing answered whether it takes images (ImageInput nil); one
its list or the user marked off (ModelImages) isn't counted. Settings ›
Models says under Image recognition "Models of {providers} aren't
listed until marked in their provider's Names & levels › Accepts
images", using the editor's own strings for the section and checkbox
(名称与推理档位 › 支持图片输入 in Chinese). Not shown with Image
recognition off. zh, zh-TW, ja, de.

Run at base 61b92529e plus the two commits before (this tree):
- TestVisionNotMarked (gui, through Handler under a temp HOME): a relay's
  unknown model is named, marked on it is a vision model, marked off it
  isn't named. ok.
- vision-not-marked.test.cjs (new; five languages, 1000 and 360px, both
  engines; fits its row, no side scroll, no stripe; none or Off says
  nothing): 32/32. Named NotMarked, not Unmarked: the Routing plugin's
  own word is Unmarked, and i18n-keys fails a core file that holds it.
- images-missing, i18n-keys: pass.
- Full GUI suite (both engines): 11767 run with the next commit at load
  ~150-250, 62 red in 21 files; those files again at concurrency 2:
  10 red. mobile-web #2658, quota-count-wrap and quota-name-translated
  #2228, s3-sync #2448, usage-agents-hide and usage-fold #2399,
  usage-checkin #2549/#3091, usage-ledger #3104, routing-rule-remove
  #3094/#3096: each red on origin/main 8278fd9b0 too. The tenth,
  provider-levels-scroll, was this change's (below), fixed here; then
  every provider*, name*, model*, vision*, editor*, settings-proxy* and
  i18n* file, both engines: 1228 pass, 0 fail.
- gofmt -l clean; go vet darwin, linux nogui, windows: ok.
- After rebasing the three commits on origin/main 7aad6a50e, at this tree
  (4342276a0, first committed as f4a95e9fa): go test -timeout 45m ./...
  (darwin) every package ok, the run before it caught
  TestSettingsSaveKeepsWhatItDoesNotSend (ProxyCustom, fixed in the
  first commit) and TestCoreScriptBudget (raised in the second); gofmt
  -l clean; go vet darwin, linux nogui, windows ok; every provider*,
  name*, model*, vision*, settings*, editor*, i18n* and images* GUI
  file, both engines: 1420 pass, 0 fail.

Broken by hand, each red, then put back:
- no ImageInput == nil check: TestVisionNotMarked red ("marked false:
  told [My Relay]").
- the line never drawn: vision-not-marked 11 of 16 red in chromium.

Not tried: a real custom provider in the real app; the picker itself
(the line is under the row, not in the menu).
This commit is contained in:
yetone
2026-10-23 03:08:08 +08:00
parent d41670e9db
commit 79856727f5
5 changed files with 182 additions and 0 deletions
+9
View File
@@ -407,6 +407,10 @@ type settingsJSON struct {
// the Vision the user picked when magpie can't find it any more:
// VisionAuto describes in its place, and the row says so
VisionMissing string `json:"visionMissing,omitempty"`
// VisionNotMarked are the custom providers (AddedByAddress) with a model left
// out of VisionModels only because nothing says it takes images: the
// user can say so in the provider's Names & levels (nexnull on Discord)
VisionNotMarked []string `json:"visionNotMarked,omitempty"`
// the reasoning levels of the model that describes images now, and the
// one it is asked at when one is picked (VisionEffort fitted to them)
VisionEfforts []string `json:"visionEfforts,omitempty"`
@@ -651,6 +655,11 @@ func settingsState() settingsJSON {
m.Provider, m.PName = "", e.Group
}
s.VisionModels = append(s.VisionModels, m)
} else if e.Group == "" && !e.Images && e.ImageInput == nil && e.Provider.AddedByAddress() && e.Provider.Ready() &&
!slices.Contains(s.VisionNotMarked, cmp.Or(e.Provider.Name, e.Provider.ID)) {
// unknown, not answered: one its list or the user said no to
// (ModelImages) isn't counted
s.VisionNotMarked = append(s.VisionNotMarked, cmp.Or(e.Provider.Name, e.Provider.ID))
}
}
s.TitleModels = []modelRef{}
+5
View File
@@ -21145,6 +21145,11 @@ function renderImages(s, keep) {
if (gone) who.append(el("div", "sub err vision-missing", s.visionAuto
? t("{model}, picked here, isn't set up any more: its provider was removed or turned off, or no longer has it. {auto}, the automatic choice, describes images in its place. Pick another model here.", { model: v, auto: named(s.visionAuto) })
: t("{model}, picked here, isn't set up any more: its provider was removed or turned off, or no longer has it. No other model sees, so images are turned away. Pick another model here.", { model: v })));
// a custom provider's model nothing says takes images isn't offered: say
// where it is marked, by the editor's own words (nexnull on Discord)
const notMarked = s.visionNotMarked || [];
if (notMarked.length && v !== "off") who.append(el("div", "sub vision-not-marked", t("Models of {providers} aren’t listed until marked in their provider’s {names} › {images}",
{ providers: notMarked.join(", "), names: t("Names & levels"), images: t("Accepts images") })));
// a routing group (no provider of its own) goes with the others, as in
// an agent's picker, not in a group of its own with its own rail button
const opt = (x) => ({ value: x.id, label: x.name || x.id, note: x.providerName, icon: x.icon, group: x.provider ? x.providerName : ROUTING_GROUPS, ref: x.id });
+4
View File
@@ -2189,6 +2189,7 @@ const I18N = {
"{id} is called {name}": "{id} 已改名为 {name}",
"{id} has its own name again": "{id} 已恢复默认名称",
"Accepts images": "支持图片输入",
"Models of {providers} aren’t listed until marked in their provider’s {names} › {images}": "{providers} 的模型需在供应商的「{names}」›「{images}」中勾选后才会列出",
"Whether agents are told {id} can see images": "是否告诉 Agent {id} 能看图片",
"{id} accepts images": "{id} 支持图片输入",
"{id} does not accept images": "{id} 不支持图片输入",
@@ -6033,6 +6034,7 @@ const I18N = {
"{id} is called {name}": "{id} 已改名為 {name}",
"{id} has its own name again": "{id} 已恢復預設名稱",
"Accepts images": "支援圖片輸入",
"Models of {providers} aren’t listed until marked in their provider’s {names} › {images}": "{providers} 的模型需在供應商的「{names}」›「{images}」中勾選後才會列出",
"Whether agents are told {id} can see images": "是否告訴 Agent {id} 能看圖片",
"{id} accepts images": "{id} 支援圖片輸入",
"{id} does not accept images": "{id} 不支援圖片輸入",
@@ -9896,6 +9898,7 @@ const I18N = {
"{id} is called {name}": "{id} の名前を {name} にしました",
"{id} has its own name again": "{id} は元の名前に戻りました",
"Accepts images": "画像入力に対応",
"Models of {providers} aren’t listed until marked in their provider’s {names} › {images}": "{providers} のモデルは、プロバイダの「{names}」›「{images}」にチェックを入れると表示されます",
"Whether agents are told {id} can see images": "{id} が画像を扱えることをエージェントに伝えるかどうか",
"{id} accepts images": "{id} は画像入力に対応しています",
"{id} does not accept images": "{id} は画像入力に対応していません",
@@ -13769,6 +13772,7 @@ const I18N = {
"{id} is called {name}": "{id} heißt jetzt {name}",
"{id} has its own name again": "{id} trägt wieder seinen eigenen Namen",
"Accepts images": "Akzeptiert Bilder",
"Models of {providers} aren’t listed until marked in their provider’s {names} › {images}": "Modelle von {providers} erscheinen erst, wenn sie in „{names}“ › „{images}“ ihres Anbieters markiert sind",
"Whether agents are told {id} can see images": "Ob Agenten mitgeteilt wird, dass {id} Bilder sehen kann",
"{id} accepts images": "{id} akzeptiert Bilder",
"{id} does not accept images": "{id} akzeptiert keine Bilder",
@@ -0,0 +1,103 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// nexnull on Discord: a custom provider's model that nobody has said takes
// images is not among Image recognition's models, and nothing said why or
// where to change it. Under the row a line now names those providers and
// says the model is marked in its provider's Names & levels › Accepts
// images, in the editor's own words. None such, or Image recognition off,
// no line. Every language; wide and at a phone's width, nothing running
// off to the side; no backend, the API is faked here.
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 settingsPayload(lang, over) {
return {
theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd", textSize: 100,
dock: false, dockWindow: false, proxy: "", redact: false, redactPersonal: false, redactWords: [],
codexWarmup: "", claudeWarmup: "", codexWarmAt: "", claudeWarmAt: "", workbuddyCheckin: false, noStats: false,
trayUsage: "", trayUsageEvery: 3, vision: "", imageGen: "",
version: "0.1.400", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3425",
proxyNow: "none", proxySource: "none", login: false,
visionModels: [{ id: "codex/gpt-6.1-sol", name: "GPT-6.1 Sol", provider: "codex", providerName: "Codex", icon: "openai" }],
visionAuto: "codex/gpt-6.1-sol",
imageGenModels: [], workbuddyCheckins: [], lanURLs: [],
fx: { rate: 7.2, at: new Date().toISOString(), stale: false },
...over,
};
}
function server(lang, cur) {
return async (route) => {
const req = route.request(), 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,textSize:100};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "light", textSize: 100 }, fx: cur.fx });
if (url.pathname === "/api/settings") return json(cur);
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 });
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)];
const body = await fs.readFile(file).catch(() => null);
await (body ? route.fulfill({ body, contentType }) : route.fulfill({ status: 404, body: "" }));
};
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": Image recognition says where a custom provider's model is marked as seeing", async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const open = async (lang, cur, width) => {
const context = await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" });
const page = await context.newPage();
page.setDefaultTimeout(5000);
page.errors = [];
page.on("pageerror", (e) => page.errors.push(e.message));
await page.route("**/*", server(lang, cur));
await page.goto("http://magpie.test/?view=settings&tab=models");
await page.locator("#imagesList .row").nth(1).waitFor();
return page;
};
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
for (const width of [1000, 360]) {
await t.test(`${lang} at ${width}px: the providers are named, with where to mark a model`, async () => {
const page = await open(lang, settingsPayload(lang, { visionNotMarked: ["My Relay", "Local vLLM"] }), width);
const tr = (k, vars = {}) => page.evaluate(([k, vars]) => t(k, vars), [k, vars]);
const names = await tr("Names & levels"), images = await tr("Accepts images");
const line = page.locator("#imagesList .row").nth(0).locator(".vision-not-marked");
assert.equal(await line.isVisible(), true);
const text = await line.textContent();
assert.match(text, /My Relay, Local vLLM/);
// the checkbox and the section by the words the editor shows
assert.ok(text.includes(names) && text.includes(images), text);
if (lang !== "en") assert.ok(!/Names & levels|Accepts images|aren’t listed/.test(text), "untranslated: " + text);
if (lang === "zh") assert.ok(text.includes("名称与推理档位") && text.includes("支持图片输入"), text);
const fit = await page.evaluate(() => {
const l = document.querySelector("#imagesList .vision-not-marked"), row = l.closest(".row").getBoundingClientRect(), r = l.getBoundingClientRect();
return { inRow: r.left >= row.left - 1 && r.right <= row.right + 1, scroll: document.documentElement.scrollWidth - document.documentElement.clientWidth,
stripe: getComputedStyle(l).borderLeftWidth };
});
assert.deepEqual(fit, { inRow: true, scroll: 0, stripe: "0px" });
assert.deepEqual(page.errors, []);
await page.context().close();
});
}
await t.test(`${lang}: none unmarked, or Image recognition off, says nothing`, async () => {
for (const over of [{}, { visionNotMarked: ["My Relay"], vision: "off" }]) {
const page = await open(lang, settingsPayload(lang, over), 1000);
assert.equal(await page.locator("#imagesList .vision-not-marked").count(), 0);
assert.deepEqual(page.errors, []);
await page.context().close();
}
});
}
});
}
+61
View File
@@ -0,0 +1,61 @@
package gui
import (
"encoding/json"
"net/http/httptest"
"path/filepath"
"slices"
"testing"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
)
// nexnull on Discord: a custom provider's model nothing says takes images
// isn't one Image recognition can be given, and Settings is told which
// providers have such a model so it can say where it is marked. Marked
// there, it is among the models; marked off, it isn't said again.
func TestVisionNotMarked(t *testing.T) {
h := t.TempDir()
t.Setenv("HOME", h)
t.Setenv("USERPROFILE", h)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
if err := provider.Save(provider.Provider{ID: "relay", Name: "My Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"house-model"}}); err != nil {
t.Fatal(err)
}
srv := Handler(nil, nil)
get := func() (unmarked, vision []string) {
t.Helper()
rec := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/api/settings", nil)
r.RemoteAddr = "127.0.0.1:50000"
srv.ServeHTTP(rec, r)
var out struct {
VisionNotMarked []string `json:"visionNotMarked"`
VisionModels []struct {
ID string `json:"id"`
} `json:"visionModels"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &out); err != nil {
t.Fatalf("%d %s", rec.Code, rec.Body)
}
for _, m := range out.VisionModels {
vision = append(vision, m.ID)
}
return out.VisionNotMarked, vision
}
if u, v := get(); !slices.Equal(u, []string{"My Relay"}) || slices.Contains(v, "relay/house-model") {
t.Fatalf("not marked: told %q, models %q", u, v)
}
for _, said := range []bool{true, false} {
s := settings.Load()
s.ModelImages = map[string]bool{"relay/house-model": said}
if err := settings.Save(s); err != nil {
t.Fatal(err)
}
if u, v := get(); len(u) != 0 || slices.Contains(v, "relay/house-model") != said {
t.Fatalf("marked %v: told %q, models %q", said, u, v)
}
}
}