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(test): stop budget-env poisoning from the backpressure test
Martin Vogel312185ca3895
diff --git a/src/foundation/mem.c b/src/foundation/mem.cindex 7238847f2..405a1bdc2 100644--- a/src/foundation/mem.c+++ b/src/foundation/mem.c@@ -234,6 +234,10 @@ size_t cbm_mem_budget(void) {return g_budget;}+void cbm_mem_set_budget_for_tests(size_t bytes) {+ g_budget = bytes;+}+bool cbm_mem_over_budget(void) {size_t rss = cbm_mem_rss();check_pressure(rss);diff --git a/src/foundation/mem.h b/src/foundation/mem.hindex 8c23c508a..db170465a 100644--- a/src/foundation/mem.h+++ b/src/foundation/mem.h@@ -29,6 +29,15 @@ size_t cbm_mem_peak_rss(void);/* Total budget in bytes. */size_t cbm_mem_budget(void);+/* TEST HOOK: overwrite the budget directly, bypassing cbm_mem_init's+ * init-once guard (a setenv+re-init dance in tests is a silent no-op once+ * some earlier init won the guard — the poisoned budget then leaks into+ * every later budget consumer in the process). Does NOT flip the init+ * guard: a later cbm_mem_init still initializes normally. Callers must+ * save cbm_mem_budget() first and restore it before their assertions.+ * Never call from production code. */+void cbm_mem_set_budget_for_tests(size_t bytes);+/* Returns true if current RSS exceeds the budget. */bool cbm_mem_over_budget(void);diff --git a/tests/test_pipeline.c b/tests/test_pipeline.cindex 9d35e33d1..fc35928a7 100644--- a/tests/test_pipeline.c+++ b/tests/test_pipeline.c@@ -6577,9 +6577,16 @@ TEST(pipeline_backpressure_futile_nap_disengages) {fclose(f);}- /* 1 MB budget: over-budget on every pull, unreclaimable by napping. */- cbm_setenv("CBM_MEM_BUDGET_MB", "1", 1);- cbm_mem_init(0);+ /* 1 MB budget: over-budget on every pull, unreclaimable by napping.+ * Set via the test hook, NOT setenv + cbm_mem_init: the init-once guard+ * makes any re-init keep whatever budget the FIRST in-process init+ * computed. The old env dance either failed to apply the 1 MB budget+ * (some earlier test's init won the guard) or applied it permanently+ * (this test's init won) — the "restore" re-init was then a silent+ * no-op and the 1 MB budget leaked into every later budget consumer+ * in the runner (mem_over_budget_low_rss went red suite-order-wide). */+ size_t saved_budget = cbm_mem_budget();+ cbm_mem_set_budget_for_tests((size_t)1024 * 1024);ASSERT_TRUE(cbm_mem_budget() > 0);ASSERT_TRUE(cbm_mem_over_budget());@@ -6589,9 +6596,8 @@ TEST(pipeline_backpressure_futile_nap_disengages) {int rc = cbm_pipeline_run(p);long cycles = cbm_pp_bp_nap_cycles();- /* Restore the tests' default budget-off state BEFORE asserting. */- cbm_unsetenv("CBM_MEM_BUDGET_MB");- cbm_mem_init(0);+ /* Restore the caller-visible budget BEFORE asserting. */+ cbm_mem_set_budget_for_tests(saved_budget);cbm_pipeline_free(p);teardown_test_repo();