Skip to content

Commit d01ba80

Browse files
authored
Merge pull request DeusData#2244 from lorenzozanee/fix/windows-unicode-agent-detection
fix(cli): support non-ASCII Windows agent paths
2 parents a3831c9 + b4fb1e3 commit d01ba80

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

‎src/cli/cli.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "daemon/runtime.h"
2121
#include "daemon/version_cohort.h"
2222
#include "foundation/compat.h"
23+
#include "foundation/compat_fs.h"
2324
#include "foundation/platform.h"
2425
#include "foundation/constants.h"
2526
#include "foundation/json_writer.h"
@@ -2718,12 +2719,8 @@ int cbm_remove_zed_mcp_owned(const char *binary_path, const char *config_path) {
27182719
/* ── Agent detection ──────────────────────────────────────────── */
27192720

27202721
static bool dir_exists(const char *path) {
2721-
struct stat st;
2722-
#ifndef _WIN32
2723-
return lstat(path, &st) == 0 && S_ISDIR(st.st_mode);
2724-
#else
2725-
return stat(path, &st) == 0 && S_ISDIR(st.st_mode);
2726-
#endif
2722+
cbm_path_info_t info = {0};
2723+
return cbm_path_info_utf8(path, &info) == CBM_PATH_INFO_OK && info.is_directory;
27272724
}
27282725

27292726
/* Resolve the Claude Code config dir.

‎tests/test_cli.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15281,6 +15281,29 @@ TEST(cli_detect_agents_finds_zed_in_roaming_appdata) {
1528115281
}
1528215282
#endif
1528315283

15284+
#ifdef _WIN32
15285+
/* #2145: a profile path outside the ANSI code page must stay visible to agent
15286+
* detection. The directory is created with th_mkdir_p, which goes through the
15287+
* wide-char API: test_mkdirp uses cbm_mkdir, the narrow _mkdir on Windows,
15288+
* which would create a code-page-mangled name instead of this one. Cursor is
15289+
* detected by its directory alone, so the assertion goes through dir_exists. */
15290+
TEST(cli_detect_agents_handles_non_ascii_windows_profile) {
15291+
char home[1024];
15292+
snprintf(home, sizeof(home), "%s/cbm-用户-profile", cbm_tmpdir());
15293+
test_rmdir_r(home);
15294+
char cursor_dir[1024];
15295+
snprintf(cursor_dir, sizeof(cursor_dir), "%s/.cursor", home);
15296+
if (th_mkdir_p(cursor_dir) != 0)
15297+
FAIL("could not create non-ASCII Windows profile path");
15298+
15299+
cbm_detected_agents_t agents = cbm_detect_agents(home);
15300+
test_rmdir_r(home);
15301+
if (!agents.cursor)
15302+
FAIL("agent detection must support non-ASCII Windows profile paths");
15303+
PASS();
15304+
}
15305+
#endif
15306+
1528415307
TEST(cli_detect_agents_finds_antigravity) {
1528515308
char tmpdir[256];
1528615309
snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-detect-XXXXXX");
@@ -19351,6 +19374,7 @@ SUITE(cli) {
1935119374
#endif
1935219375
#ifdef _WIN32
1935319376
RUN_TEST(cli_detect_agents_finds_zed_in_roaming_appdata);
19377+
RUN_TEST(cli_detect_agents_handles_non_ascii_windows_profile);
1935419378
#endif
1935519379
RUN_TEST(cli_detect_agents_finds_antigravity);
1935619380
RUN_TEST(cli_detect_agents_finds_kilocode);

0 commit comments

Comments
 (0)