-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathsetup.ts
More file actions
35 lines (32 loc) · 1.46 KB
/
Copy pathsetup.ts
File metadata and controls
35 lines (32 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Vitest setup: quarantine SENPI_CODING_AGENT_DIR so the test suite never
* writes session JSONLs into the user's real `~/.senpi/agent/sessions/`.
*
* Many tests call `SessionManager.create(tempDir)` without an explicit
* sessionDir. That falls back to `getDefaultSessionDir(cwd)` → `getAgentDir()`,
* which reads this env var. If unset, it resolves to the developer's real
* $HOME and leaves faux-provider JSONLs there permanently, where downstream
* tools (e.g. tokscale) then mis-count them as real usage.
*/
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
for (const key of ["PI_RULES_DISABLED", "PI_RULES_MAX_RULE_CHARS", "PI_RULES_MAX_RESULT_CHARS"] as const) {
delete process.env[key];
}
// Guarded so an explicit `SENPI_CODING_AGENT_DIR=...` env (CI / opt-in) wins.
if (!process.env.SENPI_CODING_AGENT_DIR) {
const sharedQuarantineRoot = process.env.SENPI_VITEST_QUARANTINE_ROOT;
const quarantineRoot = sharedQuarantineRoot ?? mkdtempSync(join(tmpdir(), "senpi-vitest-"));
const workerRoot = sharedQuarantineRoot
? mkdtempSync(join(sharedQuarantineRoot, `worker-${process.pid}-`))
: quarantineRoot;
const quarantineDir = join(workerRoot, "agent");
mkdirSync(quarantineDir, { recursive: true });
process.env.SENPI_CODING_AGENT_DIR = quarantineDir;
if (!sharedQuarantineRoot) {
process.once("exit", () => {
rmSync(quarantineRoot, { recursive: true, force: true });
});
}
}