Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Phone screen tests: read the fake phone's control bytes on a timer, since macOS can drop the watch event

Brett Hamlin05d0eb0afc28
diff --git a/server/memory-dream-timeout.test.ts b/server/memory-dream-timeout.test.ts
index dad296ae90..26ea331db6 100644
--- a/server/memory-dream-timeout.test.ts
+++ b/server/memory-dream-timeout.test.ts
@@ -1,4 +1,4 @@
-import { existsSync, mkdtempSync, rmSync, watch } from "node:fs";
+import { existsSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
@@ -38,7 +38,8 @@ it("lets a Claude dream outlive the helper's default minute, but still stops it
const timer = realTimeout(() => reject(new Error("Claude background CLI never started")), 10_000);
ready = () => { realClearTimeout(timer); resolve(); };
});
- const watcher = watch(scratch, () => { if (existsSync(dump)) ready(); });
+ // macOS fs.watch (FSEvents) can drop a change made just after the watcher is created, so this polls instead.
+ const polling = setInterval(() => { if (existsSync(dump)) ready(); }, 10);
vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
let settled = false;
const dream = loop.dream(bot.id).then((report) => { settled = true; return report; });
@@ -52,7 +53,7 @@ it("lets a Claude dream outlive the helper's default minute, but still stops it
await vi.advanceTimersByTimeAsync(1_000);
expect(await dream).toMatchObject({ conversations: 2, note: "The dream did not answer in time." });
} finally {
- watcher.close();
+ clearInterval(polling);
await vi.advanceTimersByTimeAsync(180_000);
await dream;
vi.useRealTimers();
diff --git a/server/phone-screen/session.test.ts b/server/phone-screen/session.test.ts
index 6a9a064c98..43f0fb7349 100644
--- a/server/phone-screen/session.test.ts
+++ b/server/phone-screen/session.test.ts
@@ -1,4 +1,4 @@
-import { chmodSync, copyFileSync, existsSync, mkdtempSync, readFileSync, watch, writeFileSync } from "node:fs";
+import { chmodSync, copyFileSync, existsSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
import { connect } from "node:net";
import { tmpdir } from "node:os";
import { join } from "node:path";
@@ -70,10 +70,11 @@ describe("openPhoneSession", () => {
const look = () => {
const received = phone.controlBytes();
if (received.length < bytes * 2) return;
- changes.close();
+ clearInterval(polling);
resolve(received);
};
- const changes = watch(dir, look);
+ // macOS fs.watch (FSEvents) can drop a change made just after the watcher is created, so this polls instead.
+ const polling = setInterval(look, 10);
look();
}),
serverPid: () => Number(read("server.pid")),
diff --git a/server/testing/fake-phone.ts b/server/testing/fake-phone.ts
index c63ef37223..eb78d0d6c6 100644
--- a/server/testing/fake-phone.ts
+++ b/server/testing/fake-phone.ts
@@ -1,4 +1,4 @@
-import { chmodSync, copyFileSync, existsSync, mkdtempSync, readFileSync, watch, writeFileSync } from "node:fs";
+import { chmodSync, copyFileSync, existsSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
import { connect } from "node:net";
import { tmpdir } from "node:os";
import { join } from "node:path";
@@ -53,10 +53,11 @@ export function fakePhone({ mode = "", video = SCRCPY_VIDEO, devices = "", under
const look = () => {
const received = existsSync(join(dir, "control.hex")) ? read("control.hex") : "";
if (received.length < bytes * 2) return;
- changes.close();
+ clearInterval(polling);
resolve(received);
};
- const changes = watch(dir, look);
+ // macOS fs.watch (FSEvents) can drop a change made just after the watcher is created, so this polls instead.
+ const polling = setInterval(look, 10);
look();
}),
/** More video on the running session's socket; settles once the phone has passed all of it on. */