Skip to content

Commit 07f78e8

Browse files
committed
Fix userconfig test on Windows: use APPDATA instead of XDG_CONFIG_HOME
cbm_app_config_dir() reads APPDATA on Windows, not XDG_CONFIG_HOME. Test now sets the platform-appropriate env var and restores it after.
1 parent 616a430 commit 07f78e8

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

tests/test_userconfig.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ TEST(userconfig_project_basic) {
5656
/* ── Tests: global config ────────────────────────────────────────── */
5757

5858
TEST(userconfig_global_via_env) {
59-
/* Point XDG_CONFIG_HOME to a temp dir */
60-
char xdg_dir[256];
61-
snprintf(xdg_dir, sizeof(xdg_dir), "%s/uctest_global_xdg", cbm_tmpdir());
59+
/* Point config dir to a temp dir via the platform-appropriate env var:
60+
* XDG_CONFIG_HOME on Linux/macOS, APPDATA on Windows. */
61+
char cfg_dir[256];
62+
snprintf(cfg_dir, sizeof(cfg_dir), "%s/uctest_global_xdg", cbm_tmpdir());
6263

6364
char app_dir[512];
64-
snprintf(app_dir, sizeof(app_dir), "%s/codebase-memory-mcp", xdg_dir);
65+
snprintf(app_dir, sizeof(app_dir), "%s/codebase-memory-mcp", cfg_dir);
6566
cbm_mkdir_p(app_dir, 0755);
6667

6768
char global_path[768];
@@ -70,10 +71,23 @@ TEST(userconfig_global_via_env) {
7071
write_json(global_path, "{\"extra_extensions\":{\".twig\":\"html\"}}"),
7172
0);
7273

73-
/* Set env var, load, restore */
74-
cbm_setenv("XDG_CONFIG_HOME", xdg_dir, 1);
74+
#ifdef _WIN32
75+
char old_appdata[512] = "";
76+
cbm_safe_getenv("APPDATA", old_appdata, sizeof(old_appdata), NULL);
77+
cbm_setenv("APPDATA", cfg_dir, 1);
78+
#else
79+
cbm_setenv("XDG_CONFIG_HOME", cfg_dir, 1);
80+
#endif
7581
cbm_userconfig_t *cfg = cbm_userconfig_load(NULL); /* no project dir */
82+
#ifdef _WIN32
83+
if (old_appdata[0]) {
84+
cbm_setenv("APPDATA", old_appdata, 1);
85+
} else {
86+
cbm_unsetenv("APPDATA");
87+
}
88+
#else
7689
cbm_unsetenv("XDG_CONFIG_HOME");
90+
#endif
7791

7892
ASSERT_NOT_NULL(cfg);
7993
ASSERT_EQ(cbm_userconfig_lookup(cfg, ".twig"), CBM_LANG_HTML);

0 commit comments

Comments
 (0)