Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
fix(platform): cbm_env_dup answers through the settings resolver (#221)
Martin Vogel788dbe075ea6
diff --git a/src/foundation/platform.c b/src/foundation/platform.cindex ee407e258..d11df686e 100644--- a/src/foundation/platform.c+++ b/src/foundation/platform.c@@ -478,6 +478,12 @@ char *cbm_env_dup(const char *name) {if (!name || !name[0]) {return NULL;}+ /* The same view cbm_safe_getenv gives: the startup settings resolver+ * answers first, and a handled NULL masks the variable. */+ const char *resolved = NULL;+ if (environment_resolver && environment_resolver(name, &resolved)) {+ return resolved ? cbm_mem_strdup(CBM_MEM_CLASS_OTHER, resolved) : NULL;+ }#ifdef _WIN32/* Same wide route as cbm_safe_getenv: _environ holds ANSI-code-page bytes,* so a non-ASCII PATH would arrive mojibake'd or with '?' substituted --diff --git a/src/foundation/platform.h b/src/foundation/platform.hindex aa3536b96..40b020222 100644--- a/src/foundation/platform.h+++ b/src/foundation/platform.h@@ -157,7 +157,9 @@ const char *cbm_native_getenv(const char *name, char *buf, size_t buf_sz, const* cbm_free(CBM_MEM_CLASS_OTHER, ptr), never free(). NULL when the variable is* unset or cannot be read; a variable that exists but is empty yields "".* On Windows the value is read with the wide API and converted, the same route- * cbm_safe_getenv takes, so a non-ASCII value survives intact. */+ * cbm_safe_getenv takes, so a non-ASCII value survives intact. Like+ * cbm_safe_getenv, an installed settings resolver answers before the process+ * environment does. */char *cbm_env_dup(const char *name);/* Read an environment variable as a whole number.diff --git a/tests/test_platform.c b/tests/test_platform.cindex d1434c2ee..8b18a4884 100644--- a/tests/test_platform.c+++ b/tests/test_platform.c@@ -7,6 +7,7 @@#include "../src/foundation/compat_regex.h"#include "../src/foundation/constants.h"#include "../src/foundation/compat_thread.h"+#include "../src/foundation/mem_core.h"#include "../src/foundation/platform.h"#include "../src/foundation/platform_internal.h"#include "../src/foundation/system_info_internal.h"@@ -895,6 +896,52 @@ TEST(platform_env_long_refuses_what_it_cannot_read) {PASS();}+/* cbm_env_dup (#221) gives the same environment view as cbm_safe_getenv: an+ * installed settings resolver answers first, a handled NULL masks the+ * variable, and an unhandled name falls through to the process environment. */+static bool platform_env_dup_test_resolver(const char *name, const char **value) {+ if (strcmp(name, "CBM_TEST_ENV_DUP_RESOLVED") == 0) {+ *value = "from-settings";+ return true;+ }+ if (strcmp(name, "CBM_TEST_ENV_DUP_MASKED") == 0) {+ *value = NULL;+ return true;+ }+ return false;+}++TEST(platform_env_dup_honours_the_settings_resolver) {+ ASSERT_EQ(cbm_setenv("CBM_TEST_ENV_DUP_RESOLVED", "from-environment", 1), 0);+ ASSERT_EQ(cbm_setenv("CBM_TEST_ENV_DUP_MASKED", "from-environment", 1), 0);+ ASSERT_EQ(cbm_setenv("CBM_TEST_ENV_DUP_NATIVE", "from-environment", 1), 0);++ cbm_set_environment_resolver(platform_env_dup_test_resolver);+ char *resolved = cbm_env_dup("CBM_TEST_ENV_DUP_RESOLVED");+ char *masked = cbm_env_dup("CBM_TEST_ENV_DUP_MASKED");+ char *native = cbm_env_dup("CBM_TEST_ENV_DUP_NATIVE");+ char safe[64];+ const char *safe_value = cbm_safe_getenv("CBM_TEST_ENV_DUP_RESOLVED", safe, sizeof(safe), NULL);+ cbm_set_environment_resolver(NULL);++ bool safe_ok = safe_value && strcmp(safe_value, "from-settings") == 0;+ bool resolved_ok = resolved && strcmp(resolved, "from-settings") == 0;+ bool masked_ok = masked == NULL;+ bool native_ok = native && strcmp(native, "from-environment") == 0;+ cbm_free(CBM_MEM_CLASS_OTHER, resolved);+ cbm_free(CBM_MEM_CLASS_OTHER, masked);+ cbm_free(CBM_MEM_CLASS_OTHER, native);+ (void)cbm_unsetenv("CBM_TEST_ENV_DUP_RESOLVED");+ (void)cbm_unsetenv("CBM_TEST_ENV_DUP_MASKED");+ (void)cbm_unsetenv("CBM_TEST_ENV_DUP_NATIVE");++ ASSERT_TRUE(safe_ok);+ ASSERT_TRUE(resolved_ok);+ ASSERT_TRUE(masked_ok);+ ASSERT_TRUE(native_ok);+ PASS();+}+#ifdef _WIN32/* cbm_safe_getenv reads Windows' wide environment as UTF-8. Its matching* setter must update that same wide environment; _putenv_s alone interprets@@ -1420,6 +1467,7 @@ SUITE(platform) {RUN_TEST(platform_default_workers_env_unset);RUN_TEST(platform_env_long_reads_a_clean_number);RUN_TEST(platform_env_long_refuses_what_it_cannot_read);+ RUN_TEST(platform_env_dup_honours_the_settings_resolver);RUN_TEST(platform_system_info);RUN_TEST(regex_compile_refuses_oversized_expansion);RUN_TEST(regex_compile_accepts_expansion_under_budget);