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(cli): stop a negative probe from spending 15s proving silence
Martin Vogelfa99ff64eb65
diff --git a/scripts/run-test-wave.py b/scripts/run-test-wave.pyindex d24f80815..ce7e3d344 100755--- a/scripts/run-test-wave.py+++ b/scripts/run-test-wave.py@@ -26,7 +26,19 @@ SUITE_NAME = re.compile(r"^[a-z0-9_]+$")SUMMARY = re.compile(r"^ (?P<passed>[0-9]+) passed")FAILED = re.compile(r"(?:^|, )(?P<failed>[0-9]+) failed")SKIPPED = re.compile(r"(?:^|, )(?P<skipped>[0-9]+) skipped")-SLOW_SUITES = frozenset(("incremental", "store_arch", "daemon_runtime"))+# Suites whose honest runtime does not fit the default per-suite budget, and so+# get --slow-timeout instead. This is a statement about SIZE, never about+# flakiness: every suite here is deterministic and simply long, and a racy suite+# must be made deterministic rather than given more clock.+#+# `cli` joined the list because the classification had gone stale, not because+# anything regressed. It spends 497s of the 900s default on macos-14 -- the+# FASTEST macOS runner -- while the macos-15-intel runner in the same matrix is+# 2.4-3.6x slower on comparable suites (daemon_runtime 842s vs 349s,+# stack_overflow_b 277s vs 76s). 497s at that ratio cannot fit, so the suite was+# killed at 900s and reported as hung. daemon_runtime, at 842s on that same+# runner, survives only because it was already listed here.+SLOW_SUITES = frozenset(("incremental", "store_arch", "daemon_runtime", "cli"))POLL_SECONDS = 0.05# WHY: the Windows descendant probe below is a cold `powershell.exe` + CIMdiff --git a/tests/test_cli.c b/tests/test_cli.cindex 4f427be3a..4b3234ad4 100644--- a/tests/test_cli.c+++ b/tests/test_cli.c@@ -1522,6 +1522,27 @@ TEST(cli_install_recovers_markerless_stale_rendezvous) {#define CLI_SCOPE_READY_TIMEOUT_MS 90000U#define CLI_SCOPE_HOST_REAP_TIMEOUT_MS 60000U#define CLI_SCOPE_HOST_SERVING_TIMEOUT_MS 15000U+/* Teardown budget for a child the activation ALREADY drained: its service is+ * gone, so each free/release succeeds immediately and this is only the+ * give-up point if one unexpectedly does not. The undrained path keeps the+ * full 2 x CLI_SCOPE_TIMEOUT_MS, which is where a wedged teardown is real. */+#define CLI_SCOPE_CLEANUP_DRAINED_MS 1000U+/* Budget for probing that an ALREADY-drained host has stopped serving.+ *+ * The generous CLI_SCOPE_HOST_SERVING_TIMEOUT_MS exists for the POSITIVE+ * question -- "is this daemon still up?" -- where a slow reply on a loaded+ * runner must not be misread as drained. Asked in the negative it inverts:+ * there is no reply coming, so the whole budget is spent proving silence, and+ * the assertion is decided by a timeout expiring rather than by the system's+ * own behaviour. That was 15 s of the drain test's wall clock and the largest+ * single idle block in the cli suite.+ *+ * The drain is proven POSITIVELY elsewhere in that test: install returns 0+ * only after the activation completed, and the host child exits with+ * CLI_SCOPE_HOST_DRAINED. By the time this probe runs the daemon is already+ * gone, so a short budget confirms the same fact a long one would -- it just+ * stops charging the suite for the wait. */+#define CLI_SCOPE_HOST_DRAINED_PROBE_MS 2000Utypedef struct {char tmpdir[256];@@ -1588,7 +1609,16 @@ static _Noreturn void cli_scope_host_child(const cli_scope_fixture_t *fixture, ibreak;}}- uint64_t cleanup_deadline = cbm_now_ms() + 2U * CLI_SCOPE_TIMEOUT_MS;+ /* A DRAINED child has already had its service torn down by the activation,+ * so every teardown below succeeds on the first attempt; the long deadline+ * exists for the wedged case, where we keep retrying before giving up. On+ * the drained path that budget was pure wall clock -- the parent sits in+ * cli_scope_reap_host waiting for this exit, and it was the single largest+ * idle block in the whole cli suite. Behaviour at the deadline is+ * unchanged (give up and _exit); it is simply reached sooner when there is+ * nothing wedged to wait for. */+ uint64_t cleanup_deadline =+ cbm_now_ms() + (drained ? CLI_SCOPE_CLEANUP_DRAINED_MS : 2U * CLI_SCOPE_TIMEOUT_MS);if (service) {if (!drained) {(void)cbm_daemon_runtime_service_stop(service, CLI_SCOPE_TIMEOUT_MS);@@ -1752,19 +1782,24 @@ static bool cli_scope_fixture_start(cli_scope_fixture_t *fixture, const char *tareturn fixture->client != NULL;}+static bool cli_scope_host_serving_within(const cli_scope_fixture_t *fixture,+ uint32_t timeout_ms) {+ cbm_daemon_runtime_status_t status = {0};+ return fixture->endpoint &&+ cbm_daemon_runtime_request_status(fixture->endpoint, &fixture->identity, timeout_ms,+ &status) &&+ !status.stopping && status.committed_clients == 1;+}+/* Ask the host daemon itself: still running, not stopping, and the parent's* committed client still admitted. */static bool cli_scope_host_serving(const cli_scope_fixture_t *fixture) {- cbm_daemon_runtime_status_t status = {0};/* A generous, bounded status deadline: a foreign-namespace install leaves* this daemon serving, so a slow response on a loaded runner must not be* misread as "drained" (the flaky failure this fixture showed). The call* still fails cleanly — a genuinely drained daemon is unreachable or* reports stopping — it just no longer decides survival on a 5 s budget. */- return fixture->endpoint &&- cbm_daemon_runtime_request_status(fixture->endpoint, &fixture->identity,- CLI_SCOPE_HOST_SERVING_TIMEOUT_MS, &status) &&- !status.stopping && status.committed_clients == 1;+ return cli_scope_host_serving_within(fixture, CLI_SCOPE_HOST_SERVING_TIMEOUT_MS);}static int cli_scope_install(cli_scope_fixture_t *fixture, const char *home, const char *cache,@@ -1902,7 +1937,10 @@ TEST(cli_install_into_host_namespace_still_drains_host_cohort) {int install_rc =ready ? cli_scope_install(&fixture, fixture.host_home, fixture.host_cache, host_bin, false): -1;- bool host_serving = ready && cli_scope_host_serving(&fixture);+ /* Negative probe: see CLI_SCOPE_HOST_DRAINED_PROBE_MS. The drain itself is+ * asserted positively below via host_exit == CLI_SCOPE_HOST_DRAINED. */+ bool host_serving = ready && cli_scope_host_serving_within(&fixture,+ CLI_SCOPE_HOST_DRAINED_PROBE_MS);const char *events = read_test_file(activation_log);bool drained_in_log = events && strstr(events, "cohort drained") != NULL &&strstr(events, "\"daemon_active_clients\":1") != NULL;