Files
software-mansion__argent/packages/tool-server/test/chromium-server-navigation.test.ts
filip131311 f288a461b0 refactor: rename the Electron device platform to "chromium" (CDP) (#332)
## Summary

The Electron support added in #247 is **generic Chromium/CDP under the
hood**. The discovery layer probes the Chromium-default CDP port
(`9222`) and any `ARGENT_*_PORTS` entries; the connection picks the
first non-devtools page target; describe is a plain in-page DOM walker;
input/screenshot/screencast/navigation/JS-debugger are all straight CDP.
Nothing in that path is Electron-specific — the only Electron-specific
piece is the *launcher* (`boot-electron.ts`, which resolves and spawns
an Electron binary).

So any Chromium-family runtime exposing a CDP endpoint — an Electron
app, **or** Chrome/Brave/Edge/WebView2 launched with
`--remote-debugging-port` — is discoverable and drivable through the
same tool surface. This PR renames the platform discriminator (and
everything keyed off it) from `electron` to `chromium` so the naming
matches reality.

## What changed

**Public/contract surface (clean hard rename, no back-compat aliases):**
- Platform discriminator `"electron"` → `"chromium"`; device id
`electron-cdp-<port>` → `chromium-cdp-<port>`.
- `ToolCapability.electron` → `.chromium`; the capability-gate rejection
now reads `Tool 'X' is not supported on chromium app`.
- Env `ARGENT_ELECTRON_PORTS`(`_FILE`) →
`ARGENT_CHROMIUM_PORTS`(`_FILE`); ports cache
`~/.argent/electron-cdp-ports.json` → `chromium-cdp-ports.json`; HTTP
surface `/electron-server/` → `/chromium-server/`.

**Files / dirs / symbols:**
- `src/electron-server/` → `src/chromium-server/`; blueprints
`electron-cdp` / `electron-js-runtime-debugger` → `chromium-*`;
`describe`/`open-url`/`launch-app` `platforms/electron.ts` →
`chromium.ts`; `keyboard/electron-keys` → `chromium-keys`;
`utils/electron-discovery` → `chromium-discovery`.
-
`ElectronServer`/`ElectronCdpApi`/`ElectronJsRuntimeDebugger`/`describeElectron`/`discoverElectronDevices`/`ELECTRON_ID_PREFIX`/…
→ `Chromium*` / `CHROMIUM_*`. Tests renamed to match.

**Stays "electron" (the Electron-specific launcher):**
- `boot-device` keeps the `electronAppPath` / `electronPort` /
`electronArgs` inputs, and `boot-electron.ts` still resolves & spawns an
Electron binary. It just yields a `chromium` device now (an Electron app
*is* a Chromium/CDP runtime).

**Skills:** `argent-device-interact`, `argent-metro-debugger`,
`rules/argent.md`, and the RN-workflow reference were reframed to
describe **Chromium (CDP)** availability — Electron apps *plus* any
Chromium browser over CDP (auto-discovered on `9222` /
`ARGENT_CHROMIUM_PORTS`) — instead of Electron only.

## Test plan
- [x] `tsc --build` clean
- [x] `typecheck:tests` clean
- [x] **1116 vitest cases pass (126 files)**
- [x] prettier clean on all changed/renamed files
- [x] Full-repo sweep: every remaining "electron" mention is intentional
(the launcher path + skill prose explaining Electron as one kind of
Chromium/CDP app); `electronic` in LICENSE/COC untouched.
2026-06-15 11:03:23 +02:00

69 lines
2.5 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import { goBack, goForward, navigate, reload } from "../src/chromium-server/navigation";
import type { CDPClient } from "../src/utils/debugger/cdp-client";
function stubCdp(history?: {
currentIndex: number;
entries: Array<{ id: number; url: string; title: string }>;
}) {
const send = vi.fn().mockImplementation((method: string) => {
if (method === "Page.getNavigationHistory" && history) return Promise.resolve(history);
return Promise.resolve({});
});
return { send } as unknown as CDPClient;
}
describe("chromium-server/navigation", () => {
it("navigate: forwards to Page.navigate", async () => {
const cdp = stubCdp();
await navigate(cdp, "https://example.com");
const send = (cdp as unknown as { send: ReturnType<typeof vi.fn> }).send;
expect(send).toHaveBeenCalledWith("Page.navigate", { url: "https://example.com" });
});
it("reload: forwards ignoreCache flag", async () => {
const cdp = stubCdp();
await reload(cdp, true);
const send = (cdp as unknown as { send: ReturnType<typeof vi.fn> }).send;
expect(send).toHaveBeenCalledWith("Page.reload", { ignoreCache: true });
});
it("goBack: at the oldest entry returns false without navigating", async () => {
const cdp = stubCdp({
currentIndex: 0,
entries: [{ id: 1, url: "about:blank", title: "" }],
});
expect(await goBack(cdp)).toBe(false);
const send = (cdp as unknown as { send: ReturnType<typeof vi.fn> }).send;
// Only the history-query was called — no navigateToHistoryEntry.
const navs = send.mock.calls.filter((c) => c[0] === "Page.navigateToHistoryEntry");
expect(navs.length).toBe(0);
});
it("goBack: walks one entry and navigates to its id", async () => {
const cdp = stubCdp({
currentIndex: 2,
entries: [
{ id: 1, url: "/a", title: "" },
{ id: 2, url: "/b", title: "" },
{ id: 3, url: "/c", title: "" },
],
});
expect(await goBack(cdp)).toBe(true);
const send = (cdp as unknown as { send: ReturnType<typeof vi.fn> }).send;
expect(send).toHaveBeenCalledWith("Page.navigateToHistoryEntry", { entryId: 2 });
});
it("goForward: at the newest entry returns false", async () => {
const cdp = stubCdp({
currentIndex: 2,
entries: [
{ id: 1, url: "/a", title: "" },
{ id: 2, url: "/b", title: "" },
{ id: 3, url: "/c", title: "" },
],
});
expect(await goForward(cdp)).toBe(false);
});
});