mirror of
https://github.com/software-mansion/argent.git
synced 2026-09-14 19:27:14 +08:00
f288a461b0
## 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.
70 lines
2.6 KiB
TypeScript
70 lines
2.6 KiB
TypeScript
import { describe, it, expect, vi } from "vitest";
|
|
import { gestureDragTool } from "../src/tools/gesture-drag";
|
|
import { assertSupported, UnsupportedOperationError } from "../src/utils/capability";
|
|
import { resolveDevice } from "../src/utils/device-info";
|
|
|
|
// gesture-drag is the third chromium verb: swipe = touch (ios/android),
|
|
// scroll = wheel (chromium), drag = left-button mouse drag (chromium).
|
|
// These tests pin the press → interpolated moves → release sequence and
|
|
// the chromium-only capability fence.
|
|
|
|
const chromiumDevice = resolveDevice("chromium-cdp-19222");
|
|
const iosDevice = resolveDevice("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA");
|
|
const androidDevice = resolveDevice("emulator-5554");
|
|
|
|
function fakeChromiumApi() {
|
|
return {
|
|
getViewport: () => ({ width: 800, height: 600, devicePixelRatio: 2 }),
|
|
dispatchMouseEvent: vi.fn().mockResolvedValue(undefined),
|
|
};
|
|
}
|
|
|
|
describe("gesture-drag", () => {
|
|
it("presses at the start, interpolates moves, releases at the end (viewport px)", async () => {
|
|
const api = fakeChromiumApi();
|
|
const result = await gestureDragTool.execute(
|
|
{ chromium: api } as never,
|
|
{
|
|
udid: "chromium-cdp-19222",
|
|
fromX: 0.25,
|
|
fromY: 0.5,
|
|
toX: 0.75,
|
|
toY: 0.5,
|
|
durationMs: 64,
|
|
} as never
|
|
);
|
|
expect(result.dragged).toBe(true);
|
|
|
|
const calls = api.dispatchMouseEvent.mock.calls.map((c) => c[0] as Record<string, unknown>);
|
|
expect(calls[0]).toMatchObject({ type: "mousePressed", x: 0.25 * 800, y: 0.5 * 600 });
|
|
expect(calls[calls.length - 1]).toMatchObject({
|
|
type: "mouseReleased",
|
|
x: 0.75 * 800,
|
|
y: 0.5 * 600,
|
|
});
|
|
|
|
const moves = calls.slice(1, -1);
|
|
expect(moves.length).toBeGreaterThan(0);
|
|
for (const move of moves) {
|
|
expect(move.type).toBe("mouseMoved");
|
|
expect(move.button).toBe("left");
|
|
// Every interpolated point stays on the straight line between the ends.
|
|
expect(move.x as number).toBeGreaterThan(0.25 * 800);
|
|
expect(move.x as number).toBeLessThan(0.75 * 800);
|
|
expect(move.y).toBeCloseTo(0.5 * 600, 5);
|
|
}
|
|
});
|
|
|
|
it("is chromium-only: capability gate rejects iOS and Android targets", () => {
|
|
expect(() =>
|
|
assertSupported("gesture-drag", gestureDragTool.capability!, chromiumDevice)
|
|
).not.toThrow();
|
|
expect(() => assertSupported("gesture-drag", gestureDragTool.capability!, iosDevice)).toThrow(
|
|
UnsupportedOperationError
|
|
);
|
|
expect(() =>
|
|
assertSupported("gesture-drag", gestureDragTool.capability!, androidDevice)
|
|
).toThrow(UnsupportedOperationError);
|
|
});
|
|
});
|