Skip to content

Commit bc3594b

Browse files
committed
fix(test): pin XDG_CONFIG_HOME in the three env-coupled cli tests
The parallel runner's isolated-process execution exposed three cli tests that were passing for the wrong reason on Linux: cbm_zed_config_dir (and the VS Code/vendor path resolvers) prefer $XDG_CONFIG_HOME over $HOME/.config, CI runners export it, and an isolated `test-runner cli` process therefore resolved config paths OUTSIDE the test fixture — the tests only stayed green in the all-suites single process because an earlier suite's env mutations leaked into them (hidden cross-suite coupling, deterministic failure in isolation, macOS unaffected since its resolvers do not consult XDG). - cli_detect_agents_finds_zed: save/set XDG_CONFIG_HOME to the fixture's .config for the detection call, restore after. - cli_vscode_profile_mcp_uninstall: same pin alongside its existing HOME/PATH/APPDATA handling. - cli_durable_profiles_follow_current_vendor_paths: XDG_CONFIG_HOME joins its unset-and-restore env list. All 222 cli tests pass locally with a hostile XDG_CONFIG_HOME exported. No production code changed; no assertion weakened. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 95659b3 commit bc3594b

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

‎tests/test_cli.c‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,10 @@ TEST(cli_vscode_profile_mcp_uninstall) {
14131413
char *saved_home = save_test_env("HOME");
14141414
char *saved_path = save_test_env("PATH");
14151415
char *saved_appdata = save_test_env("APPDATA");
1416+
char *saved_xdg = save_test_env("XDG_CONFIG_HOME");
1417+
char xdg_dir[640];
1418+
snprintf(xdg_dir, sizeof(xdg_dir), "%s/.config", tmpdir);
1419+
cbm_setenv("XDG_CONFIG_HOME", xdg_dir, 1); /* Linux resolvers prefer XDG */
14161420
cbm_setenv("HOME", tmpdir, 1);
14171421
cbm_setenv("PATH", tmpdir, 1);
14181422
#ifdef _WIN32
@@ -1432,6 +1436,7 @@ TEST(cli_vscode_profile_mcp_uninstall) {
14321436
restore_test_env("HOME", saved_home);
14331437
restore_test_env("PATH", saved_path);
14341438
restore_test_env("APPDATA", saved_appdata);
1439+
restore_test_env("XDG_CONFIG_HOME", saved_xdg);
14351440
test_rmdir_r(tmpdir);
14361441
if (rc != 0 || !removed)
14371442
FAIL("VS Code uninstall must remove MCP entries from every existing profile");
@@ -2953,8 +2958,20 @@ TEST(cli_durable_profiles_follow_current_vendor_paths) {
29532958
FAIL("cbm_mkdtemp failed");
29542959

29552960
const char *const env_names[] = {
2956-
"HOME", "PATH", "CLAUDE_CONFIG_DIR", "CODEX_HOME", "QWEN_HOME",
2957-
"COPILOT_HOME", "CLINE_DATA_DIR", "KIRO_HOME", "VIBE_HOME", "OPENCODE_CONFIG",
2961+
"HOME",
2962+
"PATH",
2963+
"CLAUDE_CONFIG_DIR",
2964+
"CODEX_HOME",
2965+
"QWEN_HOME",
2966+
"COPILOT_HOME",
2967+
"CLINE_DATA_DIR",
2968+
"KIRO_HOME",
2969+
"VIBE_HOME",
2970+
"OPENCODE_CONFIG",
2971+
/* Linux path resolvers prefer $XDG_CONFIG_HOME over $HOME/.config;
2972+
* CI runners export it, so an isolated-process run resolved OUTSIDE
2973+
* the fixture home (green only via env leaked from earlier suites). */
2974+
"XDG_CONFIG_HOME",
29582975
};
29592976
char *saved_env[sizeof(env_names) / sizeof(env_names[0])];
29602977
for (size_t i = 0U; i < sizeof(env_names) / sizeof(env_names[0]); i++) {
@@ -7786,7 +7803,12 @@ TEST(cli_detect_agents_finds_zed) {
77867803
#endif
77877804
test_mkdirp(dir);
77887805

7806+
char *saved_xdg = save_test_env("XDG_CONFIG_HOME");
7807+
char xdg_dir[640];
7808+
snprintf(xdg_dir, sizeof(xdg_dir), "%s/.config", tmpdir);
7809+
cbm_setenv("XDG_CONFIG_HOME", xdg_dir, 1); /* Linux resolver prefers XDG */
77897810
cbm_detected_agents_t agents = cbm_detect_agents(tmpdir);
7811+
restore_test_env("XDG_CONFIG_HOME", saved_xdg);
77907812
ASSERT_TRUE(agents.zed);
77917813

77927814
test_rmdir_r(tmpdir);

0 commit comments

Comments
 (0)