Files
magpie/internal/gui/tests/aside-native.test.cjs
T
yetone d0fcb8bcdf agent: an agent uninstalled with its folder left behind shows "CLI not found" with no live settings, Hermes and the shared-folder agents too (#2177, mengyianx; #2173, SkyTodInfi)
Detection goes by an agent's folder, and an uninstall leaves the folder
behind. Before this commit, Hermes with only its 37-byte
~/.hermes/config.yaml (custom_providers: [], mcp_servers: {}) was listed as
installed in `magpie ls`, the GUI and the TUI, with model and effort pickers
that no program reads. CLIMissing (#843) covered only agents that have an
install command and their own folder. Hermes and the agents whose folder
something else keeps too (claude, codex, cline, opencode, goose) were never
gone.

What changes:
- internal/agent/gone.go adds cliHeld, which asks whether anything here still
  reads the folder:
  - the CLI on PATH or in proc.FindTool's folders (for goose, a binary that
    isn't pressly's Go goose);
  - its desktop app (HasApp) or sign;
  - the vendor installer's own place: ~/.claude/local, ~/.opencode/bin,
    ~/.codex/packages/standalone, Hermes' <home>/hermes-agent checkout;
  - for the shared folders, an editor extension under
    ~/.<editor>/extensions (anthropic.claude-code, openai.chatgpt,
    saoudrizwan.claude-dev), Claude.app or Claude Desktop, OpenCode.app or
    Goose.app on a Mac, a JetBrains IDE's settings (its agents bring their
    own program) or Zed's external_agents.
  When magpie can't tell, the agent is never gone. That covers OpenCode and
  Goose off a Mac, Gemini (its folder is Antigravity's and Code Assist's
  too), agents with their own detect, and WSL and plugin agents. It also
  covers Bin agents with no install command, except Hermes (cliOnly), since
  their installers' paths aren't verified.
- GUI: a gone row shows "CLI not found" and none of its settings, and the
  tag's tip says why. It offers no Apply again. While it is still wired it
  keeps its switch and Disconnect. Once it isn't wired it folds under Not
  set up, and Get started doesn't offer it (connectKind is "no"; the sandbox
  run showed Hermes offered there before). The panel shows the words only.
  The new tip is translated into zh, zh-TW, ja and de.
- The TUI leaves the agent out. `magpie ls` says "CLI not found" beside its
  path.
- docs/subsystems/agent-wiring.md describes all of the above.
- aside-native.test.cjs drops cliMissing from an Aside fixture. That state
  can't happen (Aside has no install command and isn't in cliOnly), and
  that test is about runtime_unavailable.

What was run:
- Sandbox HOME holding only the reporter's ~/.hermes/config.yaml (37 bytes)
  and a bare ~/.codex, with env -i and PATH=/usr/bin:/bin:
  - `magpie ls` at base 331c27703 lists "Hermes Agent — · effort —".
  - The fix lists "Hermes Agent  CLI not found  ~/.hermes/config.yaml".
  - Codex stays listed, because this Mac has ChatGPT.app's Codex (HasApp),
    so a really installed agent is kept.
- `magpie web` from the same sandbox, screenshot in Chromium: the Hermes row
  shows "CLI not found" and no pickers. That run found Get started still
  offering Hermes, which this commit fixes.
- go test ./internal/agent (2255s under load ~250 on 14 cores) and
  ./internal/cli and ./internal/tui pass. ./internal/gui fails only
  TestMainWindowCorners/macOS_26_SDK, killed at its 40s deadline under the
  same load. That is #1936; it has nothing from this change in its path, and
  it passed on base once and failed on it twice.
- GUI in Chromium and WebKit:
  - agent-cli-missing.test.cjs covers 5 languages, widths 1100 and 420, and
    the panel.
  - getting-started.test.cjs adds a gone Hermes to the fixture; the chips
    stay codex, claude and opencode.
  - Also run: i18n-keys, aside-native, agent-*, panel-* and click-scroll.
- gofmt -l is clean. go vet passes on darwin, linux (-tags nogui) and
  windows for the touched packages.

Broken by hand, and the tests went red each time:
- Dropping the openai.chatgpt check made TestCLIMissingSharedFolders' codex
  case red.
- Dropping the hermes-agent case made TestCLIMissingHermes red.
- Dropping the GUI gone branch, or the agentUsed change ("the one not
  connected stayed up"), made agent-cli-missing red.
- Dropping connectKind's cliMissing line made getting-started red
  (30 of 60 failed: chips gained hermes).

Not covered:
- library.Targets (Skills/MCP) still lists a gone agent as a place to give
  skills to.
2026-10-14 22:50:46 +08:00

179 lines
12 KiB
JavaScript

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');
for (const engine of ['chromium', 'webkit']) {
for (const lang of ['en', 'zh']) {
test(`${engine} ${lang}: Aside provider connection is independent of model selection`, async (t) => {
const browser = await (engine === 'webkit' ? webkit.launch() : chromium.launch({ channel: 'chromium' }));
t.after(() => browser.close());
const page = await browser.newPage({ viewport: { width: 980, height: 760 }, reducedMotion: 'reduce' });
const posts = [], errors = [];
page.on('pageerror', (e) => errors.push(e.message));
const a = {
id: 'aside', name: 'Aside', icon: 'aside', path: '~/.aside/u/0/settings.json',
native: { provider: 'disconnected', runtime: 'applied', fields: { image: { value: 'magpie/art/gpt-image-1', status: 'unverified', detail: "Image generation is configured, but Aside's image provider support has not been verified" } } },
fields: [
{ key: 'model', label: 'model', value: 'minimax/native', options: [{ value: 'minimax/native', label: 'Native MiniMax' }, { value: 'magpie/relay/m1', ref: 'relay/m1', label: 'Magpie model' }] },
{ key: 'image', label: 'image', value: 'magpie/art/gpt-image-1', options: [{ value: 'magpie/art/gpt-image-1', ref: 'art/gpt-image-1', label: 'GPT image' }] },
],
};
const state = () => ({ agents: [a], profiles: [], settings: { lang, theme: 'light' } });
await page.route('**/*', async (route) => {
const req = route.request(), url = new URL(req.url()), p = url.pathname;
if (req.method() === 'POST') posts.push(p);
if (p === '/boot.js') return route.fulfill({ contentType: 'text/javascript', body: `window.bootPrefs=${JSON.stringify({ lang, theme: 'light', web: true })}` });
if (p === '/api/state') return route.fulfill({ json: state() });
if (p === '/api/agents/connect/aside') { a.wired = true; a.native.provider = 'connected'; return route.fulfill({ json: { ...state(), connected: { how: 'joined' } } }); }
if (p === '/api/agents/preview/aside') return route.fulfill({ json: { revision: "provider-plan", changes: [{ path: '~/.aside/u/0/models.json', lines: [{ op: '-', text: 'providers.magpie' }] }] } });
if (p === '/api/agents/disconnect/aside') { a.wired = false; a.native.provider = 'disconnected'; return route.fulfill({ json: state() }); }
if (p === '/api/providers') return route.fulfill({ json: { providers: [], presets: [], gateway: { running: true } } });
if (p === '/api/groups') return route.fulfill({ json: { groups: [] } });
if (p === '/api/plugins') return route.fulfill({ json: { plugins: [] } });
if (p === '/api/usage/quotas') return route.fulfill({ json: [] });
if (p === '/api/agents/cli') return route.fulfill({ json: { agents: {}, pending: false } });
if (p.startsWith('/api/')) return route.fulfill({ json: {} });
const file = path.join(assets, p === '/' ? 'index.html' : p);
return route.fulfill({ body: await fs.readFile(file), contentType: { '.js': 'text/javascript', '.html': 'text/html', '.css': 'text/css', '.svg': 'image/svg+xml' }[path.extname(file)] });
});
await page.goto('http://magpie.test/?view=agents');
const row = page.locator('.row.agent[data-id="aside"]');
await row.locator('.ag-start').waitFor();
assert.match(await row.locator('.ag-start').textContent(), /Native MiniMax/);
await row.locator('.ag-conn').click();
await page.waitForFunction(() => document.querySelector('[data-id="aside"] .ag-conn')?.getAttribute('aria-checked') === 'true');
assert.match(await row.locator('.ag-start').textContent(), /Native MiniMax/);
assert.equal(await row.locator('.ag-fix').count(), 0, 'image warning does not offer a provider reconnect');
await row.locator('.ag-link').click();
await row.locator('.ag-exp').waitFor();
assert.match(await row.locator('.ag-exp').textContent(), lang === 'zh' ? /已配置图片生成/ : /Image generation is configured/);
assert.deepEqual(posts, ['/api/agents/connect/aside'], 'opening details sends no mutation');
await row.locator('.ag-conn').click();
const ask = page.locator('.disconnect-ask');
await ask.waitFor();
await ask.locator('.bar button').last().click();
await ask.waitFor({ state: 'detached' });
assert.match(await row.locator('.ag-start').textContent(), /Native MiniMax/);
assert.deepEqual(posts, ['/api/agents/connect/aside', '/api/agents/disconnect/aside']);
assert.deepEqual(errors, []);
});
}
}
for (const engine of ['chromium', 'webkit']) {
for (const lang of ['en', 'zh']) {
test(`${engine} ${lang}: unavailable operation requires a separate offline confirmation`, async (t) => {
const browser = await (engine === 'webkit' ? webkit.launch() : chromium.launch({ channel: 'chromium' }));
t.after(() => browser.close());
const page = await browser.newPage({ viewport: { width: 980, height: 760 } });
page.setDefaultTimeout(5000);
const posts = [], errors = [];
page.on('pageerror', e => errors.push(e.message));
let failure = { error: 'Aside settings could not be read', code: 'runtime_unavailable', offline: 'stage' };
let revision = 'confirmed-plan';
let failPreview = false, releasePreview = null, blockPreview = false;
const a = {
id: 'aside', name: 'Aside', icon: 'aside', wired: true, path: '~/.aside/u/0/settings.json',
native: { provider: 'connected', runtime: 'applied', fields: {} },
fields: [{ key: 'model', label: 'model', value: 'native/current', options: [{ value: 'native/current', label: 'Current model' }, { value: 'magpie/relay/m1', ref: 'relay/m1', label: 'New model' }] }],
};
const current = () => ({ agents: [a], profiles: [], settings: { lang, theme: 'light' } });
await page.route('**/*', async route => {
const req = route.request(), p = new URL(req.url()).pathname;
if (req.method() === 'POST') posts.push({ path: p, body: req.postDataJSON() });
if (p === '/boot.js') return route.fulfill({ contentType: 'text/javascript', body: `window.bootPrefs=${JSON.stringify({ lang, theme: 'light', web: true })}` });
if (p === '/api/state') return route.fulfill({ json: current() });
if (p === '/api/set') return route.fulfill({ status: 400, json: failure });
if (p === '/api/agents/stage/aside') { a.fields[0].value = req.postDataJSON().value; return route.fulfill({ json: current() }); }
if (p === '/api/agents/preview/aside') {
if (blockPreview) await new Promise(resolve => { releasePreview = resolve; });
return route.fulfill({ json: failPreview ? { error: 'No restore point' } : { revision, changes: [{ path: a.path, lines: [{ op: '~', text: 'native/current', was: 'magpie/relay/m1' }] }] } });
}
if (p === '/api/agents/disconnect/aside') return route.fulfill({ status: 400, json: { error: 'Aside unavailable', code: 'runtime_unavailable', offline: 'disconnect' } });
if (p === '/api/agents/disconnect-offline/aside') {
if (req.postDataJSON().revision !== revision) return route.fulfill({ status: 400, json: { error: 'Disconnect preview changed; preview it again' } });
a.wired = false; a.native.provider = 'disconnected'; return route.fulfill({ json: current() });
}
if (p === '/api/providers') return route.fulfill({ json: { providers: [], presets: [], gateway: { running: true } } });
if (p === '/api/groups') return route.fulfill({ json: { groups: [] } });
if (p === '/api/plugins') return route.fulfill({ json: { plugins: [] } });
if (p === '/api/usage/quotas') return route.fulfill({ json: [] });
if (p === '/api/agents/cli') return route.fulfill({ json: { agents: {}, pending: false } });
if (p.startsWith('/api/')) return route.fulfill({ json: {} });
const file = path.join(assets, p === '/' ? 'index.html' : p);
return route.fulfill({ body: await fs.readFile(file), contentType: { '.js': 'text/javascript', '.html': 'text/html', '.css': 'text/css', '.svg': 'image/svg+xml' }[path.extname(file)] });
});
await page.goto('http://magpie.test/?view=agents');
const row = page.locator('.row.agent[data-id="aside"]');
await row.locator('.ag-start').waitFor();
const pick = () => page.evaluate(() => setPick(state.agents[0], state.agents[0].fields[0], 'magpie/relay/m1'));
await pick();
const ask = page.locator('.disconnect-ask');
await ask.waitFor();
assert.equal(posts.filter(p => p.path.includes('/stage/')).length, 0);
await ask.locator('.bar button').first().click();
await ask.waitFor({ state: 'detached' });
assert.match(await row.locator('.ag-start').textContent(), /Current model/);
await pick();
await ask.waitFor();
await page.keyboard.press('Escape');
await ask.waitFor({ state: 'detached' });
assert.equal(posts.filter(p => p.path.includes('/stage/')).length, 0);
failure = { error: 'Generic refusal' };
await pick();
assert.equal(await ask.count(), 0, 'generic refusal offers no fallback');
failure = { error: 'Effort unavailable', code: 'runtime_unavailable', offline: '' };
await pick();
assert.equal(await ask.count(), 0, 'unsupported action offers no fallback');
failure = { error: 'Offline', code: 'runtime_unavailable', offline: 'stage' };
await pick();
await ask.waitFor();
await ask.locator('.bar button').last().click();
await ask.waitFor({ state: 'detached' });
assert.deepEqual(posts.filter(p => p.path.includes('/stage/')), [{ path: '/api/agents/stage/aside', body: { field: 'model', value: 'magpie/relay/m1' } }]);
const disconnect = async () => {
await page.evaluate(() => askDisconnect(state.agents[0]));
await ask.waitFor();
const go = ask.locator('.bar button').last();
await page.waitForFunction(() => !document.querySelector('.disconnect-ask .bar button:last-child').disabled);
await go.click();
await page.waitForFunction(() => document.querySelector('.disconnect-ask')?.textContent.includes('Close Aside') || document.querySelector('.disconnect-ask')?.textContent.includes('关闭 Aside'));
};
blockPreview = true;
await page.evaluate(() => askDisconnect(state.agents[0]));
await ask.waitFor();
assert.equal(await ask.locator('.bar button').last().isDisabled(), true, 'wait for successful preview');
while (!releasePreview) await new Promise(resolve => setTimeout(resolve, 10));
blockPreview = false; releasePreview();
await page.waitForFunction(() => !document.querySelector('.disconnect-ask .bar button:last-child').disabled);
await ask.locator('.bar button').first().click();
await ask.waitFor({ state: 'detached' });
await disconnect();
await ask.locator('.bar button').first().click();
await ask.waitFor({ state: 'detached' });
assert.equal(posts.filter(p => p.path.includes('/disconnect-offline/')).length, 0);
await disconnect();
revision = 'changed-plan';
await ask.locator('.bar button').last().click();
await page.waitForFunction(() => !document.querySelector('.disconnect-ask .bar button:last-child').disabled);
assert.equal(a.wired, true, 'stale preview retains provider');
await ask.locator('.bar button').first().click();
await ask.waitFor({ state: 'detached' });
failPreview = true;
await page.evaluate(() => askDisconnect(state.agents[0]));
await page.waitForFunction(() => document.querySelector('.disconnect-ask')?.textContent.includes('No restore point'));
assert.equal(await ask.locator('.bar button').last().isDisabled(), true);
await ask.locator('.bar button').first().click();
failPreview = false;
await disconnect();
await ask.locator('.bar button').last().click();
await ask.waitFor({ state: 'detached' });
assert.equal(a.wired, false, 'offline execution works with missing CLI');
assert.deepEqual(errors, []);
});
}
}