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
test: sanitizer-keyed budgets and a causality-based httpd interruption proof
Martin Vogelb98f6a99c491
diff --git a/Makefile.cbm b/Makefile.cbmindex 65f73a394..97d56a8fd 100644--- a/Makefile.cbm+++ b/Makefile.cbm@@ -67,8 +67,18 @@ EDITOR_TEST_DEFINES = -DCBM_JSON_LIKE_ENABLE_TEST_API=1 \-DCBM_TOML_EDIT_ENABLE_TEST_API=1 -DCBM_YAML_ENABLE_TEST_API=1 \-DCBM_TEXT_EDIT_ENABLE_TEST_API=1 -DCBM_CLI_ENABLE_TEST_API=1 \-DCBM_DIAGNOSTICS_ENABLE_TEST_API=1-CFLAGS_TEST = $(CFLAGS_COMMON) $(EDITOR_TEST_DEFINES) -g -O1 $(SANITIZE)-CXXFLAGS_TEST = $(CXXFLAGS_COMMON) -g -O1 $(SANITIZE)+# The build system is the single source of truth for "is this binary+# instrumented": compiler-specific probes (__SANITIZE_ADDRESS__) miss+# clang's feature-check spelling and every non-ASan sanitizer, so the+# trap-UBSan leg once ran NATIVE timing budgets on an instrumented+# binary. Any non-empty SANITIZE ⇒ sanitized budgets everywhere.+ifneq ($(strip $(SANITIZE)),)+SANITIZED_DEFINE = -DCBM_SANITIZED_BUILD=1+else+SANITIZED_DEFINE =+endif+CFLAGS_TEST = $(CFLAGS_COMMON) $(EDITOR_TEST_DEFINES) $(SANITIZED_DEFINE) -g -O1 $(SANITIZE)+CXXFLAGS_TEST = $(CXXFLAGS_COMMON) $(SANITIZED_DEFINE) -g -O1 $(SANITIZE)# TSan (can't combine with ASan)TSAN_SANITIZE = -fsanitize=thread -fno-omit-frame-pointerdiff --git a/src/ui/httpd.c b/src/ui/httpd.cindex b5b3ebb14..9677bb285 100644--- a/src/ui/httpd.c+++ b/src/ui/httpd.c@@ -63,6 +63,7 @@ struct cbm_httpd {struct cbm_http_conn *active;bool interrupted;int send_buffer_for_test;+ int send_deadline_for_test_ms;};struct cbm_http_conn {@@ -311,6 +312,17 @@ bool cbm_httpd_close(cbm_httpd_t *d) {return true;}+void cbm_httpd_set_send_deadline_for_test(cbm_httpd_t *d, int ms) {+ /* Lets a test pin the send deadline far above (or below) the default so+ * an observed abort has exactly ONE possible cause — the interruption+ * tests once discriminated interrupt-abort from deadline-abort by wall+ * clock, which sanitizer slowdown turns into a lottery. */+ if (!d) {+ return;+ }+ d->send_deadline_for_test_ms = ms;+}+void cbm_httpd_set_send_buffer_for_test(cbm_httpd_t *d, int bytes) {if (!d)return;@@ -374,7 +386,8 @@ cbm_http_conn_t *cbm_httpd_accept(cbm_httpd_t *d, int timeout_ms) {}c->fd = cfd;c->owner = d;- c->send_deadline_ms = CBM_HTTP_SEND_DEADLINE_MS;+ c->send_deadline_ms = d->send_deadline_for_test_ms > 0 ? d->send_deadline_for_test_ms+ : CBM_HTTP_SEND_DEADLINE_MS;atomic_init(&c->response_started, false);cbm_mutex_lock(&d->active_mutex);diff --git a/src/ui/httpd.h b/src/ui/httpd.hindex 7e1afdfcc..dccfbe072 100644--- a/src/ui/httpd.h+++ b/src/ui/httpd.h@@ -90,6 +90,7 @@ cbm_httpd_activity_t cbm_httpd_activity_for_test(cbm_httpd_t *d);/* Caps SO_SNDBUF on subsequently accepted sockets so a non-reading peer* produces a deterministic backpressure point on every platform. */void cbm_httpd_set_send_buffer_for_test(cbm_httpd_t *d, int bytes);+void cbm_httpd_set_send_deadline_for_test(cbm_httpd_t *d, int ms);/* ── Connection handling ──────────────────────────────────────── */diff --git a/tests/test_cs_lsp_bench.c b/tests/test_cs_lsp_bench.cindex bed176678..2a7ee2915 100644--- a/tests/test_cs_lsp_bench.c+++ b/tests/test_cs_lsp_bench.c@@ -238,7 +238,7 @@ TEST(cslsp_bench_resolution_ratio) {/* Time budget. ASan+UBSan instrumentation slows the parse ~5-10×, so* scale the budget when a sanitizer is active. Native: 200 ms for a* ~260-line fixture; sanitized: 2000 ms. */-#ifdef __SANITIZE_ADDRESS__+#if defined(CBM_SANITIZED_BUILD) || defined(__SANITIZE_ADDRESS__)ASSERT(ms < 2000.0);#elseASSERT(ms < 200.0);diff --git a/tests/test_httpd.c b/tests/test_httpd.cindex 997499e22..5f18696e3 100644--- a/tests/test_httpd.c+++ b/tests/test_httpd.c@@ -1566,7 +1566,9 @@ typedef struct {static void *th_http_stop_watchdog(void *opaque) {th_http_stop_watchdog_t *watchdog = opaque;- for (int elapsed_ms = 0; elapsed_ms < 1500; elapsed_ms += 10) {+ /* Hang detector, not a latency assertion: sized for the slowest+ * sanitizer/loaded-runner tail (see AGENTS.md, CI determinism). */+ for (int elapsed_ms = 0; elapsed_ms < 10000; elapsed_ms += 10) {if (atomic_load(&watchdog->stop_finished) ||(watchdog->operation_finished && atomic_load(watchdog->operation_finished)))return NULL;@@ -1608,6 +1610,11 @@ TEST(httpd_interrupt_unblocks_nonreading_large_response_within_one_second) {cbm_httpd_t *listener = cbm_httpd_listen(0);ASSERT_NOT_NULL(listener);cbm_httpd_set_send_buffer_for_test(listener, 64 * 1024);+ /* Deadline pinned far out of reach: the only remaining way the blocked+ * 8 MB send can end is the interrupt, so the join itself proves+ * interrupt causality — no wall-clock discrimination needed (the old+ * elapsed<500ms check was a lottery under sanitizer slowdown). */+ cbm_httpd_set_send_deadline_for_test(listener, 60 * 1000);th_httpd_large_reply_t reply = {.listener = listener};atomic_init(&reply.accepted, 0);atomic_init(&reply.finished, 0);@@ -1630,17 +1637,16 @@ TEST(httpd_interrupt_unblocks_nonreading_large_response_within_one_second) {cbm_thread_t watchdog_thread;ASSERT_EQ(cbm_thread_create(&watchdog_thread, 0, th_http_stop_watchdog, &watchdog), 0);- uint64_t started = cbm_now_ms();cbm_httpd_interrupt(listener);ASSERT_EQ(cbm_thread_join(&reply_thread), 0);- uint64_t elapsed = cbm_now_ms() - started;atomic_store(&watchdog.stop_finished, 1);ASSERT_EQ(cbm_thread_join(&watchdog_thread), 0);(void)th_sock_shutdown(socket);th_sock_close(socket);ASSERT_TRUE(cbm_httpd_close(listener));- ASSERT_LT(elapsed, 500);+ /* The 60 s deadline cannot have fired, so the join above is the proof+ * of interrupt delivery; the watchdog is purely a hang detector. */ASSERT_EQ(atomic_load(&watchdog.watchdog_fired), 0);PASS();}diff --git a/tests/test_py_lsp_bench.c b/tests/test_py_lsp_bench.cindex 67e3f9dfd..9b6bfd41b 100644--- a/tests/test_py_lsp_bench.c+++ b/tests/test_py_lsp_bench.c@@ -258,7 +258,7 @@ TEST(pylsp_bench_resolution_ratio) {/* Time budget. ASan+UBSan instrumentation slows the parse ~5-10×, so* scale the budget when a sanitizer is active. Native: 150 ms for a* ~200-line fixture; sanitized: 1500 ms. */-#ifdef __SANITIZE_ADDRESS__+#if defined(CBM_SANITIZED_BUILD) || defined(__SANITIZE_ADDRESS__)ASSERT(ms < 1500.0);#elseASSERT(ms < 150.0);