test: isolate vitest home

This commit is contained in:
Peter Steinberger
2025-12-26 11:45:16 +00:00
parent 0709586e3a
commit 54de5ad3fa
3 changed files with 42 additions and 0 deletions

View File

@@ -68,6 +68,7 @@
### Tests
- Coverage added for models config merging, WhatsApp reply context, QR login flows, auto-reply behavior, and gateway SIGTERM timeouts.
- Added gateway webhook coverage (auth, validation, and summary posting).
- Vitest now isolates HOME/XDG config roots so tests never touch a real `~/.clawdis` install.
## 2.0.0-beta2 — 2025-12-21

40
test/setup.ts Normal file
View File

@@ -0,0 +1,40 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
const originalHome = process.env.HOME;
const originalUserProfile = process.env.USERPROFILE;
const originalXdgConfigHome = process.env.XDG_CONFIG_HOME;
const originalXdgDataHome = process.env.XDG_DATA_HOME;
const originalXdgStateHome = process.env.XDG_STATE_HOME;
const originalXdgCacheHome = process.env.XDG_CACHE_HOME;
const originalTestHome = process.env.CLAWDIS_TEST_HOME;
const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), "clawdis-test-home-"));
process.env.HOME = tempHome;
process.env.USERPROFILE = tempHome;
process.env.CLAWDIS_TEST_HOME = tempHome;
process.env.XDG_CONFIG_HOME = path.join(tempHome, ".config");
process.env.XDG_DATA_HOME = path.join(tempHome, ".local", "share");
process.env.XDG_STATE_HOME = path.join(tempHome, ".local", "state");
process.env.XDG_CACHE_HOME = path.join(tempHome, ".cache");
const restoreEnv = (key: string, value: string | undefined) => {
if (value === undefined) delete process.env[key];
else process.env[key] = value;
};
process.on("exit", () => {
restoreEnv("HOME", originalHome);
restoreEnv("USERPROFILE", originalUserProfile);
restoreEnv("XDG_CONFIG_HOME", originalXdgConfigHome);
restoreEnv("XDG_DATA_HOME", originalXdgDataHome);
restoreEnv("XDG_STATE_HOME", originalXdgStateHome);
restoreEnv("XDG_CACHE_HOME", originalXdgCacheHome);
restoreEnv("CLAWDIS_TEST_HOME", originalTestHome);
try {
fs.rmSync(tempHome, { recursive: true, force: true });
} catch {
// ignore cleanup errors
}
});

View File

@@ -3,6 +3,7 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
include: ["src/**/*.test.ts", "test/format-error.test.ts"],
setupFiles: ["test/setup.ts"],
exclude: [
"dist/**",
"apps/macos/**",