Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/config-home-sweep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
22 changes: 20 additions & 2 deletions test/helpers/config-home.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
import { mkdtempSync } from "node:fs";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";

const createdDirs: string[] = [];

/**
* Create an empty XDG_CONFIG_HOME for spawned hunk processes so integration tests assert
* against built-in defaults instead of the developer's ambient ~/.config/hunk/config.toml.
* hunk resolves XDG_CONFIG_HOME ahead of platform defaults, so this isolates every OS.
*
* Callers create the dir at module scope, so pair it with
* `afterAll(cleanupTestConfigHomes)` — Bun's test runner does not emit `process.on("exit")`,
* so the helper cannot sweep after itself.
*/
export function createTestConfigHome(prefix = "hunk-test-config-") {
return mkdtempSync(join(tmpdir(), prefix));
const dir = mkdtempSync(join(tmpdir(), prefix));
createdDirs.push(dir);
return dir;
}

/** Remove every config home this module created; safe to call from multiple test files. */
export function cleanupTestConfigHomes() {
while (createdDirs.length > 0) {
const dir = createdDirs.pop();
if (dir) {
rmSync(dir, { recursive: true, force: true });
}
}
}
6 changes: 4 additions & 2 deletions test/session/broker-e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { afterEach, describe, expect, test } from "bun:test";
import { afterAll, afterEach, describe, expect, test } from "bun:test";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { createServer } from "node:http";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { createTestConfigHome } from "../helpers/config-home";
import { cleanupTestConfigHomes, createTestConfigHome } from "../helpers/config-home";

const repoRoot = process.cwd();
const sourceEntrypoint = join(repoRoot, "src/main.tsx");
// Spawned hunk processes must assert built-in defaults, not the developer's ambient user config.
const testConfigHome = createTestConfigHome();

afterAll(cleanupTestConfigHomes);
const tempDirs: string[] = [];
const ttyToolsAvailable =
Bun.spawnSync(["bash", "-lc", "command -v script >/dev/null && command -v timeout >/dev/null"], {
Expand Down
6 changes: 4 additions & 2 deletions test/session/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { afterEach, describe, expect, test } from "bun:test";
import { afterAll, afterEach, describe, expect, test } from "bun:test";
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { createTestConfigHome } from "../helpers/config-home";
import { cleanupTestConfigHomes, createTestConfigHome } from "../helpers/config-home";

const repoRoot = process.cwd();
const sourceEntrypoint = join(repoRoot, "src/main.tsx");
// Spawned hunk processes must assert built-in defaults, not the developer's ambient user config.
const testConfigHome = createTestConfigHome();

afterAll(cleanupTestConfigHomes);
const tempDirs: string[] = [];
const ttyToolsAvailable =
Bun.spawnSync(["bash", "-lc", "command -v script >/dev/null && command -v timeout >/dev/null"], {
Expand Down
6 changes: 4 additions & 2 deletions test/session/daemon.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { afterEach, describe, expect, test } from "bun:test";
import { afterAll, afterEach, describe, expect, test } from "bun:test";
import type { Subprocess } from "bun";
import { createServer } from "node:net";
import { createTestConfigHome } from "../helpers/config-home";
import { cleanupTestConfigHomes, createTestConfigHome } from "../helpers/config-home";

const repoRoot = process.cwd();
// Spawned hunk processes must assert built-in defaults, not the developer's ambient user config.
const testConfigHome = createTestConfigHome();

afterAll(cleanupTestConfigHomes);
const spawned: Subprocess[] = [];

async function reserveLoopbackPort() {
Expand Down
6 changes: 4 additions & 2 deletions test/smoke/tty.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { afterEach, describe, expect, setDefaultTimeout, test } from "bun:test";
import { afterAll, afterEach, describe, expect, setDefaultTimeout, test } from "bun:test";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { createTestConfigHome } from "../helpers/config-home";
import { cleanupTestConfigHomes, createTestConfigHome } from "../helpers/config-home";

const repoRoot = process.cwd();
const sourceEntrypoint = join(repoRoot, "src/main.tsx");
// Spawned hunk processes must assert built-in defaults, not the developer's ambient user config.
const testConfigHome = createTestConfigHome();

afterAll(cleanupTestConfigHomes);
const tempDirs: string[] = [];
const enableTtySmokeTests = process.env.HUNK_RUN_TTY_SMOKE === "1";
if (enableTtySmokeTests) {
Expand Down