Files
magpie/internal/gui/tests/hermes-profiles.test.cjs
T
yetone 34d38ed669 hermes: each profile picks its own model on the Agents page
dongshanfengdongshizhcn on Discord: "我的 hermes 有多个 profile,但现在
agent 的配置里面,似乎只能配置默认的 profile". magpie gave Hermes one model
picker, for the connected profile's config.yaml. A bot under
<root>/profiles/<name> could only follow it or keep its own model.

Hermes's layout comes from its own source (hermes-agent e5ea5fd9,
hermes_cli/profiles.py and main.py): named profiles live in
<root>/profiles/<name> (PROFILE_ID_RE, a .deleted tombstone, the identity
files), active_profile is the sticky one, "default" is the root, and a
profile's model is model.default/model.model under model.provider. magpie
already found these profiles (hermesProfiles/hermesOthers).

Now each profile other than the connected one has a field,
"profile:<name>" (hermesProfileFields). The opened Hermes row draws them as
Other profiles, one line per profile: its name, the app's model picker, and
`hermes -p <name>`. They are never a square of the row's own, and with one
profile only nothing new shows. Nothing needs setting up:
- a magpie model stashes the profile's own provider and model, then puts
  magpie's provider and the model into that profile only;
- a model of its own is written as model.default and gives back the stashed
  provider;
- Default puts back the profile's model from before magpie, or keeps the one
  it has. Disconnect sends the same empty value, so a profile never loses
  its model;
- a bot picked there is recorded (hermes:<path>:picked) and doesn't follow
  the connected config's next model (hermesFollow);
- a sync keeps magpie's provider current in a bot on magpie while the
  connected config isn't on it.
app.js stays under its budget through the previous commit; no budget was
raised. New string: "Other profiles" (zh, zh-TW, ja, de).

Run:
- go test ./internal/agent ./internal/gui ./internal/profile ./internal/tui
  ./internal/cli (-count=1). gui, profile and cli are ok. Two reds were already
  filed: TestFolderVarsAreListed (CARGO_HOME, fixed on main by 3116b8f58,
  which this is rebased on) and TestTUIFetchesSubscriptionModels/agent
  (#3919). Neither touches Hermes.
- TestHermes* ok after the rebase. gofmt -l is clean. go vet and GOOS=windows
  go vet pass on agent, gui and profile. GOOS=linux go vet passes on agent and
  profile; gui needs cgo for wails and doesn't cross-vet from macOS.
- GUI: new hermes-profiles.test.cjs (en, zh, zh-TW, ja, de; 1100px and 560px;
  chromium and webkit; 20/20) plus i18n-keys, claude-auto-mode,
  claude-subagents-pick, claude-subagent-effort-row, tier-effort,
  click-scroll, every agent-*.test.cjs, and the previous commit's Settings
  files: 899 of 900. The one red is the known #3897.

Broken by hand:
- origin/main's hermes.go fails TestHermesProfileModels ("pickers []").
- Without the picked guard in hermesFollow, coder followed main to
  deepseek/max.
- With Default deleting model.default, writer lost gpt-5.5.
- With the sync of bots on magpie turned off, writer's provider lacked a new
  model.
- origin/main's app.js fails hermes-profiles.test.cjs 10 of 10 in chromium.

Not tried: a real Hermes. By rule it isn't run under a sandbox
HERMES_HOME, since that rewrites the live ~/.hermes launcher. The layout was
read from Hermes's source, and the configs were written as its
_seed_model_config does. profile.yaml's display_name is not used; the line
shows the folder name, which is what `hermes -p` takes.
2026-10-28 00:17:40 +08:00

128 lines
8.0 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// Hermes keeps more than one profile (hermes -p <name>), each with its own
// config.yaml, and magpie's Hermes row picked the model of one of them only
// (dongshanfengdongshizhcn on Discord). Each other profile comes as a field
// keyed "profile:<name>": connected, the opened row has an Other profiles
// section with one line per profile (its name, its model picker, the
// command that runs it), and no square of the row's own. A click opens the
// app's model picker with Default first, noted as putting back what the
// profile had before magpie; a model picked is posted for that profile
// alone. With one profile only there is no section. No click scrolls the
// page. In every language, at a normal and a narrow width, in both engines.
// 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");
const models = [{ value: "magpie/v/glm", label: "GLM", ref: "v/glm" }, { value: "magpie/v/flash", label: "Flash", ref: "v/flash" }];
const hermes = (id, bots) => ({
id, name: "Hermes", path: "/test/.hermes/config.yaml", icon: "hermes", wired: true,
fields: [
{ key: "model", label: "model", value: "magpie/v/glm", options: models },
...bots.map((b) => ({ key: "profile:" + b, label: b, value: b === "coder" ? "kimi-k3.5" : "magpie/v/glm", quiet: true, options: [{ value: "kimi-k3.5" }, ...models] })),
],
});
const fresh = () => ({ agents: [hermes("hermes", ["a-profile-with-a-long-name", "coder"]), hermes("hermes-one", [])], profiles: [] });
function server(lang, sets) {
let cur = fresh();
return async (route) => {
const req = route.request(), url = new URL(req.url());
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 route.fulfill({ json: { ...cur, settings: { lang, theme: "light" } } });
if (url.pathname === "/api/set") {
const body = req.postDataJSON();
sets.push(body);
cur = JSON.parse(JSON.stringify(cur));
cur.agents.find((a) => a.id === body.agent).fields.find((f) => f.key === body.field).value = body.value;
return route.fulfill({ json: { ...cur, settings: { lang, theme: "light" } } });
}
if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] });
if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } });
if (url.pathname === "/api/agents/cli") return route.fulfill({ json: { agents: {}, pending: false } });
if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } });
if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } });
if (url.pathname.startsWith("/api/")) return route.fulfill({ 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 });
};
}
// the words as i18n.js has them
const W = {
en: { head: "Other profiles", def: "Default", note: "put back what Hermes had before magpie" },
zh: { head: "其他 profile", def: "默认", note: "还原 Hermes 接入 magpie 之前的设置" },
"zh-TW": { head: "其他 profile", def: "預設", note: "還原 Hermes 接入 magpie 之前的設定" },
ja: { head: "ほかのプロファイル", def: "デフォルト", note: "Hermes を magpie 接続前の設定に戻す" },
de: { head: "Weitere Profile", def: "Standard", note: "Stand von Hermes vor magpie wiederherstellen" },
};
const row = '.row.agent[data-id="hermes"]';
const one = '.row.agent[data-id="hermes-one"]';
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of Object.keys(W)) {
for (const width of [1100, 560]) {
test(`${engine} ${lang} ${width}px: each Hermes profile picks its own model`, async (t) => {
const w = W[lang];
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await browser.newPage({ viewport: { width, height: 800 } });
page.setDefaultTimeout(5000);
const errors = [], sets = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, sets));
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}-${width}-hermes-profiles.png`) });
}
await browser.close();
});
await page.goto("http://magpie.test/");
await page.locator(row).waitFor();
// no profile picker in the row itself
assert.equal(await page.locator(`${row} > * .field[data-key^="profile:"]`).count(), 0);
// one profile only: no section
await page.locator(`${one} .ag-link`).click();
await page.locator(`${one} .ag-exp`).waitFor();
assert.equal(await page.locator(`${one} .ag-exp`).innerText().then((s) => s.includes(w.head)), false);
assert.equal(await page.locator(`${one} .field[data-key^="profile:"]`).count(), 0);
await page.locator(`${row} .ag-link`).click();
await page.locator(`${row} .ag-exp`).waitFor();
assert.ok((await page.locator(`${row} .ag-exp`).innerText()).includes(w.head));
const keys = await page.locator(`${row} .ag-exp .field.ag-pick[data-key^="profile:"]`).evaluateAll((es) => es.map((e) => e.dataset.key));
assert.deepEqual(keys, ["profile:a-profile-with-a-long-name", "profile:coder"]);
const pick = page.locator(`${row} .ag-exp .field.ag-pick[data-key="profile:coder"]`);
const line = pick.locator("xpath=..");
assert.equal(await line.locator(".ag-tier").textContent(), "coder");
assert.equal(await line.locator(".ag-hint").textContent(), "hermes -p coder");
assert.equal(await pick.locator(".v").textContent(), "kimi-k3.5");
// a long name is cut short, not pushing its picker out
const long = page.locator(`${row} .ag-exp .field.ag-pick[data-key="profile:a-profile-with-a-long-name"]`).locator("xpath=..").locator(".ag-tier");
assert.ok(await long.evaluate((e) => e.scrollWidth > e.clientWidth && getComputedStyle(e).textOverflow === "ellipsis"));
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), "the Agents view overflows");
// the app's model picker, Default first, noted as putting back the profile's own
const y = await page.evaluate(() => scrollY);
await pick.click();
await page.locator("#pop:not([hidden]) #list li").first().waitFor();
assert.equal(await page.evaluate(() => scrollY), y, "the click scrolled the page");
assert.equal(await page.locator("#pop").evaluate((e) => e.classList.contains("model-picker")), true);
const first = await page.locator("#pop #list li").first().innerText();
assert.ok(first.includes(w.def) && first.includes(w.note), first);
await page.locator("#pop #list li", { hasText: "Flash" }).first().click();
await page.waitForFunction(() => document.querySelector('.row.agent[data-id="hermes"] .ag-exp .field[data-key="profile:coder"] .v')?.textContent === "Flash");
assert.deepEqual(sets, [{ agent: "hermes", field: "profile:coder", value: "magpie/v/flash" }]);
assert.deepEqual(errors, []);
});
}
}
}