A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
test(windows): add test suite and CI
Fabian-202678815b57026a
diff --git a/.github/workflows/windows-ci.yml b/.github/workflows/windows-ci.ymlnew file mode 100644index 00000000..9d24f80f--- /dev/null+++ b/.github/workflows/windows-ci.yml@@ -0,0 +1,67 @@+name: Windows CI++# Type-checks and tests the Windows app on every pull request that touches it.+# Nothing is packed and nothing is published: releases stay in windows.yml,+# which only runs on tags.++on:+ pull_request:+ paths:+ - 'windows/**'+ - '.github/workflows/windows-ci.yml'+ push:+ branches: [main]+ paths:+ - 'windows/**'+ - '.github/workflows/windows-ci.yml'++permissions:+ contents: read++jobs:+ test:+ runs-on: windows-latest+ defaults:+ run:+ working-directory: windows++ steps:+ - uses: actions/checkout@v4+ with:+ persist-credentials: false++ # The tests run the TypeScript sources directly, which needs Node 22.18+ # or newer; 24 is the version they are run with locally.+ - uses: actions/setup-node@v4+ with:+ node-version: 24+ cache: npm+ cache-dependency-path: windows/package-lock.json++ - name: Cache cargo+ uses: actions/cache@v4+ with:+ path: |+ ~/.cargo/registry+ ~/.cargo/git+ windows/target+ key: windows-ci-cargo-${{ hashFiles('windows/Cargo.lock') }}+ restore-keys: windows-ci-cargo-++ - name: Install dependencies+ run: npm ci++ - name: Type check+ run: npx tsc --noEmit++ - name: Island tests+ run: npm test++ # The app bundles target/release/coucou-hook.exe as a resource, and its+ # build script refuses to run until that file exists. One command per+ # step: PowerShell carries on after a failed command in the same step.+ - name: Build the relay+ run: cargo build --release -p coucou-hook++ - name: Rust tests+ run: cargo test --workspace --lockeddiff --git a/windows/package.json b/windows/package.jsonindex 22931d9b..659b85e4 100644--- a/windows/package.json+++ b/windows/package.json@@ -7,6 +7,7 @@"dev": "vite","build": "tsc --noEmit && vite build","preview": "vite preview",+ "test": "node --import ./tests/setup.mjs --test \"tests/**/*.test.mjs\"","icons": "node scripts/gen-icons.mjs","tauri": "tauri","predev": "cargo build --release -p coucou-hook",diff --git a/windows/tests/fsm.test.mjs b/windows/tests/fsm.test.mjsnew file mode 100644index 00000000..efb50267--- /dev/null+++ b/windows/tests/fsm.test.mjs@@ -0,0 +1,164 @@+// Island open/close state machine (src/island/fsm.ts).++import { afterEach, beforeEach, mock, test } from "node:test";+import assert from "node:assert/strict";+import { IslandStateMachine } from "../src/island/fsm.ts";++let fsm;+let transitions;++beforeEach(() => {+ mock.timers.enable({ apis: ["setTimeout"] });+ fsm = new IslandStateMachine();+ transitions = [];+ fsm.onTransition = (from, to) => transitions.push(`${from}>${to}`);+});++afterEach(() => mock.timers.reset());++const seconds = (n) => mock.timers.tick(n * 1000);++test("starts hidden and opens on the greeting at launch", () => {+ assert.equal(fsm.state, "hidden");+ fsm.launch();+ assert.equal(fsm.state, "coucou");+ assert.deepEqual(transitions, ["hidden>coucou"]);+});++test("the greeting collapses to the compact island 0.6 s after it ends", () => {+ fsm.launch();+ fsm.greetComplete();+ seconds(0.5);+ assert.equal(fsm.state, "coucou");+ seconds(0.1);+ assert.equal(fsm.state, "petit");+});++test("a hovered greeting stays for 10 s, whatever the animation does", () => {+ fsm.launch();+ fsm.mouseEntered();+ fsm.greetComplete();+ seconds(9.9);+ assert.equal(fsm.state, "coucou");+ seconds(0.1);+ assert.equal(fsm.state, "petit");+});++test("leaving the greeting collapses it at once", () => {+ fsm.launch();+ fsm.mouseEntered();+ fsm.mouseLeft();+ assert.equal(fsm.state, "petit");+});++test("the mouse wakes a hidden island, which stays while it is hovered", () => {+ fsm.mouseEntered();+ assert.equal(fsm.state, "petit");+ seconds(600);+ assert.equal(fsm.state, "petit");+});++test("the compact island hides 60 s after the mouse leaves", () => {+ fsm.mouseEntered();+ fsm.mouseLeft();+ seconds(59);+ assert.equal(fsm.state, "petit");+ seconds(1);+ assert.equal(fsm.state, "hidden");+});++test("coming back before the 60 s are up cancels the hide", () => {+ fsm.mouseEntered();+ fsm.mouseLeft();+ seconds(59);+ fsm.mouseEntered();+ seconds(600);+ assert.equal(fsm.state, "petit");+});++test("a click opens the compact island, and only the compact island", () => {+ fsm.click();+ assert.equal(fsm.state, "hidden");+ fsm.mouseEntered();+ fsm.click();+ assert.equal(fsm.state, "home");+ fsm.click();+ assert.equal(fsm.state, "home");+ assert.deepEqual(transitions, ["hidden>petit", "petit>home"]);+});++test("the open island collapses 15 s after the mouse leaves", () => {+ fsm.forceHome();+ fsm.mouseLeft();+ seconds(14);+ assert.equal(fsm.state, "home");+ seconds(1);+ assert.equal(fsm.state, "petit");+});++test("coming back to the open island cancels the collapse", () => {+ fsm.forceHome();+ fsm.mouseLeft();+ seconds(14);+ fsm.mouseEntered();+ seconds(600);+ assert.equal(fsm.state, "home");+});++test("a pinned island stays open when the mouse leaves", () => {+ fsm.forceHome();+ fsm.pinned = true;+ fsm.mouseLeft();+ seconds(600);+ assert.equal(fsm.state, "home");+});++test("the collapse delay is the configured one", () => {+ fsm.homeToPetitDelay = 5;+ fsm.forceHome();+ fsm.mouseLeft();+ seconds(5);+ assert.equal(fsm.state, "petit");+});++test("reveal shows the compact island from hidden and hides it again after 60 s", () => {+ fsm.reveal();+ assert.equal(fsm.state, "petit");+ seconds(60);+ assert.equal(fsm.state, "hidden");+});++test("reveal leaves an island that is already showing alone", () => {+ fsm.forceHome();+ fsm.reveal();+ assert.equal(fsm.state, "home");+ assert.deepEqual(transitions, ["hidden>home"]);+});++test("forcing the island open cancels a pending hide", () => {+ fsm.reveal();+ fsm.forceHome();+ seconds(600);+ assert.equal(fsm.state, "home");+});++test("an explicit close goes to the compact island and cancels the collapse", () => {+ fsm.forceHome();+ fsm.mouseLeft();+ fsm.forcePetit();+ assert.equal(fsm.state, "petit");+ seconds(600);+ assert.equal(fsm.state, "petit");+});++test("forceHidden hides from any state", () => {+ fsm.forceHome();+ fsm.forceHidden();+ assert.equal(fsm.state, "hidden");+});++test("a transition to the current state is not reported", () => {+ fsm.forceHome();+ fsm.forceHome();+ assert.deepEqual(transitions, ["hidden>home"]);+});diff --git a/windows/tests/setup.mjs b/windows/tests/setup.mjsnew file mode 100644index 00000000..5af51b2e--- /dev/null+++ b/windows/tests/setup.mjs@@ -0,0 +1,21 @@+// Loaded before every test file (see the `test` script in package.json).+// Node runs the island's TypeScript as it is; this only supplies what the+// webview and the bundler normally would.++import { registerHooks } from "node:module";+import { internals } from "./tauri.mjs";++// The sources import each other without an extension, which Vite resolves.+registerHooks({+ resolve(specifier, context, nextResolve) {+ const ours = !context.parentURL?.includes("/node_modules/");+ if (ours && specifier.startsWith(".") && !/\.[cm]?[jt]s$/.test(specifier)) {+ return nextResolve(`${specifier}.ts`, context);+ }+ return nextResolve(specifier, context);+ },+});++// The island reaches timers and Tauri through `window`.+globalThis.window = globalThis;+globalThis.__TAURI_INTERNALS__ = internals;diff --git a/windows/tests/tauri.mjs b/windows/tests/tauri.mjsnew file mode 100644index 00000000..0a0025d1--- /dev/null+++ b/windows/tests/tauri.mjs@@ -0,0 +1,32 @@+// A stand-in for the object Tauri injects into the webview. The island talks to+// Rust through it, so the tests see every command the island sends and can fire+// the events Rust would emit — through the real bridge, with no source changes.++/** Every command the island invoked, oldest first: [name, args]. */+export const calls = [];++const listeners = new Map();++export const internals = {+ transformCallback: (callback) => callback,+ invoke: async (cmd, args) => {+ if (cmd === "plugin:event|listen") {+ listeners.set(args.event, args.handler);+ return listeners.size;+ }+ calls.push([cmd, args]);+ return null;+ },+};++/** Fires an event the way the Rust side would. */+export function emit(event, payload) {+ const handler = listeners.get(event);+ if (!handler) throw new Error(`nothing listens to "${event}"`);+ handler({ event, id: 0, payload });+}++/** The commands invoked under one name, as a list of their arguments. */+export function sent(cmd) {+ return calls.filter(([name]) => name === cmd).map(([, args]) => args);+}