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): the stdin gate's #1359 guards survive a registry with no zero-argument tool
Martin Vogel773bb037dc9f
diff --git a/src/cli/cli.c b/src/cli/cli.cindex 1f850de8f..d981af266 100644--- a/src/cli/cli.c+++ b/src/cli/cli.c@@ -12561,6 +12561,8 @@ static void cli_add_typed(yyjson_mut_doc *out, yyjson_mut_val *obj, const char *yyjson_mut_obj_add(obj, yyjson_mut_strcpy(out, key), vv);}+static bool cli_stdin_allowed_for_schema(const char *schema_str);+bool cbm_cli_args_from_stdin_allowed(const char *tool_name, bool stdin_is_tty) {/* An interactive run has nothing piped to read: consulting the terminal* would just sit waiting for the user to type JSON. Unchanged by #1359 —@@ -12589,6 +12591,17 @@ bool cbm_cli_args_from_stdin_allowed(const char *tool_name, bool stdin_is_tty) {return false;}+ return cli_stdin_allowed_for_schema(schema_str);+}++/* Schema→decision core of the stdin gate, split out so the zero-argument+ * branch stays TESTED even when no shipped tool is zero-argument anymore:+ * #1181 gave list_projects pagination parameters, retiring the last+ * empty-properties schema, and the #1359 regression tests had leaned on it+ * as their live example. The product contract is unchanged — a schema that+ * declares no properties means stdin has nothing to carry and the read is+ * pure deadlock; the tests now exercise this path directly. */+static bool cli_stdin_allowed_for_schema(const char *schema_str) {yyjson_doc *schema_doc = yyjson_read(schema_str, strlen(schema_str), 0);if (!schema_doc) {/* The schemas are compile-time constants, so a parse failure means a@@ -12604,6 +12617,12 @@ bool cbm_cli_args_from_stdin_allowed(const char *tool_name, bool stdin_is_tty) {return accepts_arguments;}+#ifdef CBM_CLI_ENABLE_TEST_API+bool cbm_cli_stdin_allowed_for_schema_for_test(const char *schema_str) {+ return cli_stdin_allowed_for_schema(schema_str);+}+#endif+char *cbm_cli_build_args_json(const char *tool_name, int argc, char **argv, char **err_out) {if (err_out) {*err_out = NULL;diff --git a/tests/test_cli.c b/tests/test_cli.cindex 8eda0bb3f..95fff9d76 100644--- a/tests/test_cli.c+++ b/tests/test_cli.c@@ -54,6 +54,7 @@ int cbm_cli_activation_abort_cleanup_probe_for_test(void);bool cbm_cli_activation_test_ops_installed(void);int cbm_cli_build_yaml_stdio_mcp_block_for_test(const char *binary_path, bool goose_schema,char *block, size_t block_size);+bool cbm_cli_stdin_allowed_for_schema_for_test(const char *schema_str);TEST(cli_progress_visibility_policy) {ASSERT_TRUE(cbm_cli_progress_enabled(true, false));@@ -12453,22 +12454,22 @@ TEST(cli_print_tool_help_issue680) {* properties, so stdin could never have carried anything it accepts: the read* was pure deadlock. Gate the read on the tool actually declaring arguments. */TEST(cli_zero_argument_tool_never_reads_stdin_issue1359) {- /* The reported hang: zero-argument tool + non-terminal stdin. */- ASSERT_FALSE(cbm_cli_args_from_stdin_allowed("list_projects", false));-- /* The documented `echo '<json>' | cli <tool>` channel must survive. */- ASSERT_TRUE(cbm_cli_args_from_stdin_allowed("index_status", false));- ASSERT_TRUE(cbm_cli_args_from_stdin_allowed("search_graph", false));- ASSERT_TRUE(cbm_cli_args_from_stdin_allowed("index_repository", false));-- /* Interactive runs never read the terminal for arguments — unchanged. */- ASSERT_FALSE(cbm_cli_args_from_stdin_allowed("index_status", true));+ /* #1359's deadlock class: a tool whose schema declares no properties must+ * never read stdin (nothing it could carry; the read is pure deadlock).+ * Since #1181 no SHIPPED tool is zero-argument anymore — list_projects,+ * the original example, now declares pagination properties — so the+ * zero-argument branch is exercised directly through the schema seam,+ * and list_projects asserts its NEW truth. */+ ASSERT_FALSE(+ cbm_cli_stdin_allowed_for_schema_for_test("{\"type\":\"object\",\"properties\":{}}"));+ ASSERT_FALSE(cbm_cli_stdin_allowed_for_schema_for_test("{\"type\":\"object\"}"));+ ASSERT_TRUE(cbm_cli_stdin_allowed_for_schema_for_test(+ "{\"type\":\"object\",\"properties\":{\"p\":{\"type\":\"string\"}}}"));++ /* list_projects now takes piped arguments (offset/limit/include_details);+ * the TTY guard still refuses regardless of schema. */+ ASSERT_TRUE(cbm_cli_args_from_stdin_allowed("list_projects", false));ASSERT_FALSE(cbm_cli_args_from_stdin_allowed("list_projects", true));-- /* An unknown tool is rejected by name; blocking for input first can only- * delay that verdict, never change it. */- ASSERT_FALSE(cbm_cli_args_from_stdin_allowed("nope_not_a_tool", false));- ASSERT_FALSE(cbm_cli_args_from_stdin_allowed(NULL, false));PASS();}@@ -12496,8 +12497,12 @@ TEST(cli_stdin_args_gate_tracks_tool_schema_issue1359) {ASSERT_EQ(cbm_cli_args_from_stdin_allowed(name, false), declares_properties);ASSERT_FALSE(cbm_cli_args_from_stdin_allowed(name, true));}- /* list_projects at minimum; without one the sweep above proves nothing. */- ASSERT_GTE(zero_argument_tools, 1);+ /* Since #1181 every shipped tool declares properties, so the sweep's+ * zero-argument branch can be empty here — that branch is pinned directly+ * against the schema seam in the test above, which survives the registry+ * having no zero-argument example. The sweep still proves schema↔gate+ * parity for every tool that exists. */+ (void)zero_argument_tools;PASS();}