mirror of
https://github.com/software-mansion/argent.git
synced 2026-09-14 19:27:14 +08:00
7400179b5b
## What Makes Argent run on Windows. iOS Simulator is macOS-only (Apple), so on Windows that means the **Android + Chromium** host control plane. The blocker was twofold: (1) no Windows `simulator-server` binary, and (2) POSIX-only assumptions in the tool-server. Companion radon PR builds the binary and runs the Android emulator E2E on Windows: software-mansion/radon#134. ## Changes **Windows-aware tool-server / resolver / bundling** - New shared `commandOnPath()` helper — `where` on Windows, `command -v` via `/bin/sh` on POSIX. `android-binary`, `check-deps`, and `vega-cli` previously hardcoded `/bin/sh`, which never matches on Windows. - `android-binary`: append `.exe` to `adb`/`emulator` in the `$ANDROID_HOME` fallback; probe `%LOCALAPPDATA%\Android\Sdk` (Android Studio's Windows default). - simulator-server resolver + dispatcher + `bundle-tools` + `download-simulator-server.sh`: ship and resolve `simulator-server.exe` on `win32` (new `simulatorServerBinaryName()`), add `win32` to the bundled host keys, add the `simulator-server-argent-windows.exe` download target with PE arch validation. - `stop-metro`: resolve listening PIDs via `netstat -ano` on Windows (`lsof` is POSIX-only and threw ENOENT). - `adb.ts`: AVD root resolution used `$HOME` + `startsWith("/")` (rejects `C:\…`); now `os.homedir()` + `path.isAbsolute()`. - **`boot-device`**: the emulator was spawned `detached` with `stdio:"ignore"`; on Windows a detached emulator with NUL stdout/stderr never reaches `sys.boot_completed` (verified on `windows-latest`: the identical flag set boots fine with real handles, hangs with NUL). Redirect the detached emulator's output to a temp log file on win32. POSIX keeps `"ignore"`. **Tests** — cross-platform unit coverage for `commandOnPath` (both branches), win32 `.exe` Android resolution, win32 `.exe` simulator-server resolution, and a win32 AVD drive-path case; dep-gate tests now mock at the `commandOnPath` boundary so they're platform-agnostic. **CI** — `windows-e2e.yml` (`windows-chromium` on `windows-latest`): runs the resolver/dep unit tests natively on Windows, confirms `adb.exe` resolution via the SDK root, then drives a **real headless Chrome over CDP** through the tool-server (discover → screenshot → describe → tap → observe the DOM mutation). Flow in `scripts/ci/windows-chromium-e2e.mjs` (also runnable locally / in Docker). The `simulator-server.exe` build + the full **Android-emulator E2E on Windows** live in radon CI (the binary's source is the private radon repo). ## Verification (all green) - **Chromium control plane on real Windows** (`windows-latest`): `✓ discovered chromium-cdp-9222 → ✓ screenshot → ✓ describe → ✓ gesture-tap → ✓ DOM mutation observed`. Resolver/dep unit tests run natively; `adb.exe` resolves via the SDK root (it's *not* on PATH on the runner — the gap the resolver closes). - **Android emulator on real Windows** (radon#134, `windows-latest` / WHPX): the real Argent path — `boot-device` → `{ booted: true }` → screenshot via `simulator-server.exe` → gesture-tap — all green. (The boot-device fix above is what makes the detached emulator reach `boot_completed`.) - **Local clean-room E2E**: the Chromium flow runs green in a headless Linux Docker container (fresh `npm ci`, no host pollution). - **No regressions**: full tool-server suite (1624) + native-devtools-ios (16); ESLint/Prettier/typecheck clean; **Wayland E2E** (Linux AVD boot) and **Vega VVD E2E** still pass (they exercise the changed `adb.ts` / `boot-device.ts` / `vega-cli.ts` paths). ## Notes Android-emulator E2E needs WHPX nested virtualization — confirmed available on the current hosted `windows-latest` image (Server 2025); the emulator boots hardware-accelerated in ~3 min. --------- Co-authored-by: Ignacy Łątka <claude-hubert.gancarczyk@swmansion.com> Co-authored-by: Ignacy Łątka <latekvo@users.noreply.github.com>
98 lines
3.5 KiB
TypeScript
98 lines
3.5 KiB
TypeScript
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
|
|
// `probe()` resolves PATH deps (xcrun, etc.) through `commandOnPath`, which
|
|
// abstracts the `command -v` (POSIX) / `where` (Windows) difference. Mock it so
|
|
// these tests stay platform-agnostic instead of asserting a `/bin/sh` shape
|
|
// that wouldn't run on a Windows host.
|
|
const commandOnPathMock = vi.fn();
|
|
vi.mock("../src/utils/command-on-path", () => ({
|
|
commandOnPath: (name: string) => commandOnPathMock(name),
|
|
}));
|
|
|
|
// `probe()` now special-cases adb / emulator to use `resolveAndroidBinary`
|
|
// (which adds an `$ANDROID_HOME` fallback on top of PATH). Mock the resolver
|
|
// so each test controls availability per-dep instead of fighting the host's
|
|
// real $ANDROID_HOME — otherwise a dev machine with the SDK installed would
|
|
// always report adb/emulator as available regardless of `stubProbe`.
|
|
const resolveAndroidBinaryMock = vi.fn();
|
|
vi.mock("../src/utils/android-binary", () => ({
|
|
resolveAndroidBinary: (name: "adb" | "emulator") => resolveAndroidBinaryMock(name),
|
|
__resetAndroidBinaryCacheForTesting: () => {},
|
|
}));
|
|
|
|
import {
|
|
DependencyMissingError,
|
|
__resetDepCacheForTests,
|
|
ensureDep,
|
|
ensureDeps,
|
|
} from "../src/utils/check-deps";
|
|
|
|
/**
|
|
* `commandOnPath` returns the resolved absolute path on a hit, or `null` on a
|
|
* miss. Both the PATH probe (xcrun) and the Android resolver follow that
|
|
* contract, so model them the same way: `null` for a dep the test wants
|
|
* treated as missing, an absolute path otherwise.
|
|
*/
|
|
function stubProbe(missing: readonly string[]): void {
|
|
commandOnPathMock.mockImplementation(async (name: string) =>
|
|
missing.includes(name) ? null : `/usr/bin/${name}`
|
|
);
|
|
resolveAndroidBinaryMock.mockImplementation(async (name: string) => {
|
|
return missing.includes(name) ? null : `/usr/bin/${name}`;
|
|
});
|
|
}
|
|
|
|
describe("check-deps", () => {
|
|
beforeEach(() => {
|
|
__resetDepCacheForTests();
|
|
commandOnPathMock.mockReset();
|
|
resolveAndroidBinaryMock.mockReset();
|
|
});
|
|
|
|
it("returns without throwing when all deps are on PATH", async () => {
|
|
stubProbe([]);
|
|
await expect(ensureDeps(["xcrun", "adb"])).resolves.toBeUndefined();
|
|
});
|
|
|
|
it("throws DependencyMissingError listing only the missing deps", async () => {
|
|
stubProbe(["adb"]);
|
|
await expect(ensureDeps(["xcrun", "adb"])).rejects.toMatchObject({
|
|
name: "DependencyMissingError",
|
|
missing: ["adb"],
|
|
});
|
|
});
|
|
|
|
it("reports all missing deps in a single error message when both are absent", async () => {
|
|
stubProbe(["adb", "xcrun"]);
|
|
try {
|
|
await ensureDeps(["xcrun", "adb"]);
|
|
expect.fail("expected ensureDeps to reject");
|
|
} catch (err) {
|
|
expect(err).toBeInstanceOf(DependencyMissingError);
|
|
const e = err as DependencyMissingError;
|
|
expect(e.missing).toEqual(expect.arrayContaining(["adb", "xcrun"]));
|
|
expect(e.message).toMatch(/xcode-select --install/);
|
|
expect(e.message).toMatch(/android-platform-tools/);
|
|
}
|
|
});
|
|
|
|
it("caches probe results within the TTL so a burst of calls shells out once per dep", async () => {
|
|
stubProbe([]);
|
|
await ensureDeps(["xcrun"]);
|
|
await ensureDeps(["xcrun"]);
|
|
await ensureDeps(["xcrun"]);
|
|
expect(commandOnPathMock).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("is a no-op when the deps array is empty", async () => {
|
|
stubProbe([]);
|
|
await ensureDeps([]);
|
|
expect(commandOnPathMock).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("ensureDep is the single-dep form of ensureDeps", async () => {
|
|
stubProbe(["xcrun"]);
|
|
await expect(ensureDep("xcrun")).rejects.toBeInstanceOf(DependencyMissingError);
|
|
});
|
|
});
|