Skip to content

Commit 7950359

Browse files
Ufuk Altinokalfonso-magic-context
andcommitted
Fix non-hermetic Pi config test that passed locally but failed CI (XDG_CONFIG_HOME)
The Pi config loader resolves the user config base as (XDG_CONFIG_HOME ?? <HOME>/.config)/cortexkit/..., but loadPiConfig's tests wrote the user fixture under <HOME>/.config and set only HOME — never pinning XDG_CONFIG_HOME. On a dev machine where XDG_CONFIG_HOME is unset the fallback hits the temp HOME and the tests pass; on CI (which exports its own XDG_CONFIG_HOME) the loader looks there instead, finds no fixture, and reads schema defaults, so ctx_reduce_enabled/memory.enabled/env-substitution assertions failed. This was introduced with the CortexKit config-location cutover and only surfaced in CI (the local full gate was a false green because this machine has XDG unset). withHome() now also pins XDG_CONFIG_HOME to <HOME>/.config and afterEach restores it. The OpenCode config test already pinned XDG; this brings Pi to parity. Verified the suite passes with XDG_CONFIG_HOME both set (CI shape) and unset. Co-authored-by: Alfonso [Magic Context] <288211368+alfonso-magic-context@users.noreply.github.com>
1 parent b6619b4 commit 7950359

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

packages/pi-plugin/src/config/index.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { loadPiConfig, loadPiConfigDetailed } from "./index";
88

99
const tempRoots: string[] = [];
1010
const originalHome = process.env.HOME;
11+
const originalXdgConfigHome = process.env.XDG_CONFIG_HOME;
1112

1213
function makeTempRoot(prefix: string): string {
1314
const path = mkdtempSync(join(tmpdir(), prefix));
@@ -17,6 +18,12 @@ function makeTempRoot(prefix: string): string {
1718

1819
function withHome(home: string): void {
1920
process.env.HOME = home;
21+
// The user config base is `(XDG_CONFIG_HOME ?? <HOME>/.config)/cortexkit/...`.
22+
// writeUserConfig() writes under `<HOME>/.config`, so pin XDG_CONFIG_HOME to
23+
// match — otherwise a CI runner that exports its own XDG_CONFIG_HOME makes the
24+
// loader look elsewhere and these tests read schema defaults (the green-on-my-
25+
// machine / red-in-CI hermeticity gap this guards against).
26+
process.env.XDG_CONFIG_HOME = join(home, ".config");
2027
}
2128

2229
function writeConfig(path: string, text: string): void {
@@ -55,6 +62,11 @@ afterEach(() => {
5562
} else {
5663
process.env.HOME = originalHome;
5764
}
65+
if (originalXdgConfigHome === undefined) {
66+
delete process.env.XDG_CONFIG_HOME;
67+
} else {
68+
process.env.XDG_CONFIG_HOME = originalXdgConfigHome;
69+
}
5870

5971
for (const path of tempRoots.splice(0)) {
6072
rmSync(path, { recursive: true, force: true });

0 commit comments

Comments
 (0)