Files
openidea/e2e/agentVersion.spec.ts
T
Mr0Bread a83a1a54e5 fix(agents): refresh stale agent versions after CLI updates (#3538)
The New Task page reused a probe cached for the whole session, so an updated CLI kept showing its old version. The selected agent is probed again (initialize only, no session) when the page is shown or the window regains focus, without overlapping probes.

Co-authored-by: Mr0Bread <55754540+Mr0Bread@users.noreply.github.com>
2026-11-15 22:35:21 +08:00

76 lines
2.7 KiB
TypeScript

import { expect, test } from "./fixtures";
test.beforeEach(async ({ workbench: page }) => {
await page.evaluate(async () => {
// Load the IPC module in Vite's browser realm, not Playwright's Node process.
const ipcPath = "/src/platform/ipc.ts";
const { commands } = await import(ipcPath);
const provider = {
id: "omp",
name: "OMP",
command: "omp acp",
program: "omp",
args: ["acp"],
defaultProgram: null,
defaultArgs: [],
loginHint: null,
commandOverridden: false,
commandEditable: true,
commandReadOnlyReason: null,
installed: true,
env: {},
commands: [],
source: { kind: "custom" },
config: [],
thoughtLevels: {},
};
let installed = "18.20.0";
let cached = installed;
window.addEventListener("test:agent-upgraded", () => {
installed = "18.20.2";
});
commands.agentProviders = async () => ({ status: "ok", data: [provider] });
commands.agentProbe = async (id: string, refresh: boolean) => {
if (refresh) cached = installed;
return {
status: "ok",
data: { provider: id, name: "omp", version: cached, protocol: "ACP v1", error: null },
};
};
commands.agentRefreshModels = async () => ({
status: "ok",
data: {
provider: "omp",
config: [],
thoughtLevels: {},
refreshing: false,
refreshedAtMs: Date.now(),
retryAtMs: null,
error: null,
},
});
});
await page.getByRole("button", { name: "Agents", exact: true }).click();
await page.getByRole("button", { name: "New Agent Task", exact: true }).click();
await expect(page.getByText("omp · 18.20.0 · ACP v1", { exact: true })).toBeVisible();
});
test("refreshes an upgraded agent's version on window focus without losing the draft", async ({ workbench: page }) => {
const message = page.getByRole("textbox", { name: "Message", exact: true });
await message.focus();
await page.keyboard.insertText("Keep this unsent draft");
await page.evaluate(() => {
window.dispatchEvent(new Event("test:agent-upgraded"));
window.dispatchEvent(new Event("focus"));
});
await expect(page.getByText("omp · 18.20.2 · ACP v1", { exact: true })).toBeVisible();
await expect(message).toHaveText("Keep this unsent draft");
});
test("refreshes an upgraded agent's version when New Task is reopened", async ({ workbench: page }) => {
await page.getByRole("button", { name: "Close Tab", exact: true }).click();
await page.evaluate(() => window.dispatchEvent(new Event("test:agent-upgraded")));
await page.getByRole("button", { name: "New Agent Task", exact: true }).click();
await expect(page.getByText("omp · 18.20.2 · ACP v1", { exact: true })).toBeVisible();
});