From 47cf69551f7925e90a41eb0c341d088e15e85d4f Mon Sep 17 00:00:00 2001 From: Roy Osherove <575051+royosherove@users.noreply.github.com> Date: Sun, 22 Nov 2026 08:58:22 +0200 Subject: [PATCH 1/3] test: stop telegram-split generated tests timing out on slow CI The tests that loop over hundreds of generated documents took 2-3 s on a fast machine and over 5 s on a loaded one, so vitest's default 5 s timeout failed them for speed alone (CI on ef28d1d; locally two of them timed out when the whole suite ran in parallel). Give the nine heavy generated-document tests in telegram-split and telegram-delivery an explicit 60 s timeout. Seed counts and assertions are unchanged. The splitter itself is linear (about 7.6 renders per chunk from its binary search), so there is no performance fix to make in format.ts. --- test/telegram-delivery.test.ts | 19 +++++++++++++------ test/telegram-split.test.ts | 13 ++++++++++--- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/test/telegram-delivery.test.ts b/test/telegram-delivery.test.ts index a841068..eb0fcef 100644 --- a/test/telegram-delivery.test.ts +++ b/test/telegram-delivery.test.ts @@ -29,6 +29,13 @@ import { CODE_MARK, firstDifference, flat, genDocument, rng, type Rng } from "./ const LIMIT = TELEGRAM_LIMIT; +/** + * The tests that loop over generated documents take a few seconds on a fast + * machine and several times that on a loaded CI runner. Vitest's default of + * 5 s made them fail there for speed alone, so they get their own timeout. + */ +const GENERATED_DOCS_TIMEOUT_MS = 60_000; + afterEach(() => { vi.restoreAllMocks(); }); @@ -657,7 +664,7 @@ describe("a table that is being streamed when a message fills up", () => { } // The table did straddle two messages in a good number of these runs. expect(boundaries).toBeGreaterThan(5); - }); + }, GENERATED_DOCS_TIMEOUT_MS); }); describe("a code block whose first line is longer than a message", () => { @@ -698,7 +705,7 @@ describe("delivery of generated documents", () => { const whole = htmlToVisible(markdownToTelegramHtml(md)).replace(/\n/g, ""); expect(firstDifference(flat(t.visible()), whole), `seed ${seed}`).toBeNull(); } - }); + }, GENERATED_DOCS_TIMEOUT_MS); /** The document as a model would stream it: mostly small pieces, now and then a big one */ async function* streamed(md: string, r: Rng, clock: ReturnType): AsyncIterable { @@ -731,7 +738,7 @@ describe("delivery of generated documents", () => { const whole = htmlToVisible(markdownToTelegramHtml(md)).replace(/\n/g, ""); expect(firstDifference(flat(t.visible()), whole), `seed ${seed}`).toBeNull(); } - }); + }, GENERATED_DOCS_TIMEOUT_MS); it("delivers every visible character when streaming 80 documents through rate limits", async () => { let limited = 0; @@ -760,7 +767,7 @@ describe("delivery of generated documents", () => { expect(firstDifference(flat(t.visible()), whole), `seed ${seed}`).toBeNull(); } expect(limited).toBeGreaterThan(40); - }); + }, GENERATED_DOCS_TIMEOUT_MS); it("delivers every table row of 120 documents with tables, and Telegram refuses nothing", async () => { /** The rows of the boxed tables in what a reader sees, without their padding */ @@ -793,7 +800,7 @@ describe("delivery of generated documents", () => { } } expect(rowsChecked).toBeGreaterThan(300); - }); + }, GENERATED_DOCS_TIMEOUT_MS); it("delivers every visible character when some bubbles can never be edited", async () => { let stuck = 0; @@ -826,5 +833,5 @@ describe("delivery of generated documents", () => { expect(firstDifference(strip(t.visible().join("")), whole), `seed ${seed}`).toBeNull(); } expect(stuck).toBeGreaterThan(40); - }); + }, GENERATED_DOCS_TIMEOUT_MS); }); diff --git a/test/telegram-split.test.ts b/test/telegram-split.test.ts index 27a9a9a..2650015 100644 --- a/test/telegram-split.test.ts +++ b/test/telegram-split.test.ts @@ -23,6 +23,13 @@ import { CODE_MARK, PROSE_MARK, genDocument } from "./telegram-doc-generator"; const LIMIT = TELEGRAM_MESSAGE_LIMIT; +/** + * The tests that loop over generated documents take a few seconds on a fast + * machine and several times that on a loaded CI runner. Vitest's default of + * 5 s made them fail there for speed alone, so they get their own timeout. + */ +const GENERATED_DOCS_TIMEOUT_MS = 60_000; + /** The source each chunk covers, in order */ function sources(md: string, chunks: MarkdownChunk[]): string[] { return chunks.map((c) => md.slice(c.start, c.end)); @@ -324,7 +331,7 @@ describe("splitMarkdownForTelegram — generated documents", () => { const chunks = splitMarkdownForTelegram(md); expect(splitProblem(md, chunks, LIMIT), `seed ${seed}`).toBeNull(); } - }); + }, GENERATED_DOCS_TIMEOUT_MS); it("holds its properties for 150 documents at smaller limits", () => { for (let seed = 1001; seed <= 1150; seed++) { @@ -333,7 +340,7 @@ describe("splitMarkdownForTelegram — generated documents", () => { const chunks = splitMarkdownForTelegram(md, limit); expect(splitProblem(md, chunks, limit), `seed ${seed}, limit ${limit}`).toBeNull(); } - }); + }, GENERATED_DOCS_TIMEOUT_MS); it("covers what it claims to: long documents, split code blocks, split tables, hard cuts", () => { let split = 0, reopenedFence = 0, repeatedTable = 0, hardCut = 0, longest = 0; @@ -351,7 +358,7 @@ describe("splitMarkdownForTelegram — generated documents", () => { expect(repeatedTable).toBeGreaterThan(20); expect(hardCut).toBeGreaterThan(100); expect(longest).toBeGreaterThan(30_000); - }); + }, GENERATED_DOCS_TIMEOUT_MS); }); describe("splitMarkdownForTelegram — found in review", () => { From 8be91a7d1d62d6b28f509d99878b75b25a72b2b9 Mon Sep 17 00:00:00 2001 From: Roy Osherove <575051+royosherove@users.noreply.github.com> Date: Sun, 22 Nov 2026 09:05:13 +0200 Subject: [PATCH 2/3] test: keep the suite out of the real home directory The suite wrote into the real ~/.roundhouse (telegram-pairing.json, soul.md, tools.md, crons/, memory-state/, active-topics.json, logs/), so on a machine where it had run once the next run failed: "isPairingPending returns false when no pairing file exists" found the pairing file a previous run left behind. CI passed only because its home is fresh. That test set process.env.ROUNDHOUSE_DIR, which config.ts never reads, so it was writing to the real home all along. - vitest.config.ts: a global setup points HOME/USERPROFILE at a temp dir for the whole run (spawned processes inherit it), and a setup file gives every test file its own empty HOME before any src module is imported; both are removed afterwards. - telegram-setup.test.ts: the pairing tests isolate through HOME instead of the ignored ROUNDHOUSE_DIR variable. - subagent-command.ts: use ROUNDHOUSE_DIR from config instead of its own copy. Production behavior is unchanged. --- .local/share/vitest/.vitest-secret-token | 1 + src/cli/subagent-command.ts | 3 +-- test/setup/global-home.ts | 27 ++++++++++++++++++++++++ test/setup/isolate-home.ts | 19 +++++++++++++++++ test/telegram-setup.test.ts | 12 +++++++---- vitest.config.ts | 9 ++++++++ 6 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 .local/share/vitest/.vitest-secret-token create mode 100644 test/setup/global-home.ts create mode 100644 test/setup/isolate-home.ts create mode 100644 vitest.config.ts diff --git a/.local/share/vitest/.vitest-secret-token b/.local/share/vitest/.vitest-secret-token new file mode 100644 index 0000000..9d9434e --- /dev/null +++ b/.local/share/vitest/.vitest-secret-token @@ -0,0 +1 @@ +3ca8a7e8-b7b8-442a-83ba-7991db61895e diff --git a/src/cli/subagent-command.ts b/src/cli/subagent-command.ts index 6652efc..e6882bb 100644 --- a/src/cli/subagent-command.ts +++ b/src/cli/subagent-command.ts @@ -8,12 +8,11 @@ import { readFileSync } from "node:fs"; import { join } from "node:path"; -import { homedir } from "node:os"; +import { ROUNDHOUSE_DIR } from "../config"; import { SubAgentOrchestratorImpl } from "../subagents/orchestrator"; import { validateRunId } from "../subagents/run-store"; import type { SpawnSpec, SubAgentRole, RoutingInfo } from "../subagents/types"; -const ROUNDHOUSE_DIR = join(homedir(), ".roundhouse"); function loadGatewayConfig(): { notifyChatIds: (string | number)[] } { try { diff --git a/test/setup/global-home.ts b/test/setup/global-home.ts new file mode 100644 index 0000000..c0a705d --- /dev/null +++ b/test/setup/global-home.ts @@ -0,0 +1,27 @@ +/** + * Vitest global setup: run the whole suite with HOME pointing at a throwaway + * directory, so nothing (tests, the processes they spawn, tools they shell out + * to) can read or write the real ~/.roundhouse, ~/.pi or ~/.mcporter. + * Runs in the main process before any worker starts; workers inherit the env. + */ +import { mkdtempSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; + +export default function setup(): () => void { + const realHome = process.env.HOME; + const realUserProfile = process.env.USERPROFILE; + const root = mkdtempSync(join(tmpdir(), "roundhouse-test-home-")); + process.env.HOME = root; + process.env.USERPROFILE = root; + process.env.ROUNDHOUSE_TEST_HOME_ROOT = root; + + return () => { + if (realHome === undefined) delete process.env.HOME; + else process.env.HOME = realHome; + if (realUserProfile === undefined) delete process.env.USERPROFILE; + else process.env.USERPROFILE = realUserProfile; + delete process.env.ROUNDHOUSE_TEST_HOME_ROOT; + rmSync(root, { recursive: true, force: true }); + }; +} diff --git a/test/setup/isolate-home.ts b/test/setup/isolate-home.ts new file mode 100644 index 0000000..768d53b --- /dev/null +++ b/test/setup/isolate-home.ts @@ -0,0 +1,19 @@ +/** + * Vitest setup file: every test file gets its own empty HOME, set before the + * test file (and so any src module) is imported. Paths such as ROUNDHOUSE_DIR + * are computed from homedir() at import time, so state written by one file can + * never be seen by another file or by the next run. + */ +import { mkdtempSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { afterAll } from "vitest"; + +const parent = process.env.ROUNDHOUSE_TEST_HOME_ROOT ?? tmpdir(); +const home = mkdtempSync(join(parent, "file-")); +process.env.HOME = home; +process.env.USERPROFILE = home; + +afterAll(() => { + rmSync(home, { recursive: true, force: true }); +}); diff --git a/test/telegram-setup.test.ts b/test/telegram-setup.test.ts index 4afa9fe..a351271 100644 --- a/test/telegram-setup.test.ts +++ b/test/telegram-setup.test.ts @@ -3,8 +3,10 @@ import { resolve } from "node:path"; import { mkdtemp, rm, readFile } from "node:fs/promises"; import { tmpdir } from "node:os"; -// Mock ROUNDHOUSE_DIR before importing pairing module -const origDir = process.env.ROUNDHOUSE_DIR; +// ROUNDHOUSE_DIR is derived from homedir() at import time, so the pairing +// tests point HOME at a fresh directory and re-import the modules. +const origHome = process.env.HOME; +const origUserProfile = process.env.USERPROFILE; describe("pairing", () => { let tempDir: string; @@ -287,14 +289,16 @@ describe("TelegramAdapter.handlePairing", () => { beforeEach(async () => { vi.resetModules(); // Clear module cache so ROUNDHOUSE_DIR is re-evaluated tempDir = await mkdtemp(resolve(tmpdir(), "roundhouse-adapter-test-")); - process.env.ROUNDHOUSE_DIR = tempDir; + process.env.HOME = tempDir; + process.env.USERPROFILE = tempDir; const { TelegramAdapter } = await import("../src/transports/telegram/telegram-adapter"); adapter = new TelegramAdapter(); }); afterEach(async () => { await rm(tempDir, { recursive: true, force: true }); - process.env.ROUNDHOUSE_DIR = origDir; + process.env.HOME = origHome; + process.env.USERPROFILE = origUserProfile; }); it("isPairingPending returns false when no pairing file exists", async () => { diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..d61dd1c --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,9 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + // Never let a test touch the real home directory (~/.roundhouse etc.). + globalSetup: ["./test/setup/global-home.ts"], + setupFiles: ["./test/setup/isolate-home.ts"], + }, +}); From de6cfd3b76590b41fbeb870b686956764b52ac5e Mon Sep 17 00:00:00 2001 From: Roy Osherove <575051+royosherove@users.noreply.github.com> Date: Sun, 22 Nov 2026 09:05:44 +0200 Subject: [PATCH 3/3] chore: remove stray vitest token file and ignore .local/ A local run with an empty HOME made vitest write .local/share/vitest/.vitest-secret-token inside the repo, and it was committed by mistake. The token is a throwaway local vitest API token; the file is deleted on the machine that made it, so the token is no longer used. --- .gitignore | 3 +++ .local/share/vitest/.vitest-secret-token | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) delete mode 100644 .local/share/vitest/.vitest-secret-token diff --git a/.gitignore b/.gitignore index 9828d84..7cdc27a 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,6 @@ gateway-sessions/ # Claude Code local state (cron lock, transcripts, etc.) .claude/ + +# Tool state written under a relative HOME (never commit) +.local/ diff --git a/.local/share/vitest/.vitest-secret-token b/.local/share/vitest/.vitest-secret-token deleted file mode 100644 index 9d9434e..0000000 --- a/.local/share/vitest/.vitest-secret-token +++ /dev/null @@ -1 +0,0 @@ -3ca8a7e8-b7b8-442a-83ba-7991db61895e