Skip to content

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.

Merge origin/main into fix/query-graph-where-not-target

Martin Vogel146daa976e5b
diff --cc tests/test_cypher.c
index b8e4ddb1f,e9d65b31f..06c3131da
--- a/tests/test_cypher.c
+++ b/tests/test_cypher.c
@@@ -3176,65 -3310,74 +3336,133 @@@ TEST(cypher_exec_where_not)
PASS();
}
+ /* Regression (distilled from PR #1245, Andrew Hundt): the early WHERE pass in
+ * execute_single runs on seed rows with only the first alias bound. A
+ * comparison on an unbound alias used to evaluate to true, which NOT / XOR
+ * then inverted -- so every seed was pruned before CALLS expansion and the
+ * query returned zero rows. Unbound leaves must stay UNKNOWN there. */
+ TEST(cypher_exec_where_not_on_relationship_target) {
+ cbm_store_t *s = setup_cypher_store();
+ cbm_cypher_result_t r = {0};
+ int rc = cbm_cypher_execute(s,
+ "MATCH (a:Function)-[:CALLS]->(b:Function) "
+ "WHERE NOT b.name CONTAINS \"Order\" RETURN b.name",
+ "test", 0, &r);
+ ASSERT_EQ(rc, 0);
+ ASSERT_EQ(r.row_count, 1);
+ ASSERT_STR_EQ(r.rows[0][0], "LogError");
+ cbm_cypher_result_free(&r);
+ cbm_store_close(s);
+ PASS();
+ }
+
+ TEST(cypher_exec_where_mixed_alias_and) {
+ cbm_store_t *s = setup_cypher_store();
+ cbm_cypher_result_t r = {0};
+ int rc = cbm_cypher_execute(
+ s,
+ "MATCH (a:Function)-[:CALLS]->(b:Function) "
+ "WHERE a.name = \"HandleOrder\" AND NOT b.name CONTAINS \"Order\" RETURN b.name",
+ "test", 0, &r);
+ ASSERT_EQ(rc, 0);
+ ASSERT_EQ(r.row_count, 1);
+ ASSERT_STR_EQ(r.rows[0][0], "LogError");
+ cbm_cypher_result_free(&r);
+ cbm_store_close(s);
+ PASS();
+ }
+
+ TEST(cypher_exec_where_mixed_alias_or) {
+ cbm_store_t *s = setup_cypher_store();
+ cbm_cypher_result_t r = {0};
+ int rc = cbm_cypher_execute(
+ s,
+ "MATCH (a:Function)-[:CALLS]->(b:Function) "
+ "WHERE a.name = \"NoSuchFunction\" OR NOT b.name CONTAINS \"Order\" RETURN b.name",
+ "test", 0, &r);
+ ASSERT_EQ(rc, 0);
+ ASSERT_EQ(r.row_count, 1);
+ ASSERT_STR_EQ(r.rows[0][0], "LogError");
+ cbm_cypher_result_free(&r);
+ cbm_store_close(s);
+ PASS();
+ }
+
+ TEST(cypher_exec_where_mixed_alias_xor) {
+ cbm_store_t *s = setup_cypher_store();
+ cbm_cypher_result_t r = {0};
+ int rc =
+ cbm_cypher_execute(s,
+ "MATCH (a:Function)-[:CALLS]->(b:Function) "
+ "WHERE a.name = \"HandleOrder\" XOR b.name = \"LogError\" RETURN b.name",
+ "test", 0, &r);
+ ASSERT_EQ(rc, 0);
+ ASSERT_EQ(r.row_count, 1);
+ ASSERT_STR_EQ(r.rows[0][0], "ValidateOrder");
+ cbm_cypher_result_free(&r);
+ cbm_store_close(s);
+ PASS();
+ }
+
+TEST(cypher_exec_where_not_target_node) {
+ cbm_store_t *s = setup_cypher_store();
+ cbm_cypher_result_t r = {0};
+ int rc = cbm_cypher_execute(s,
+ "MATCH (a)-[:CALLS]->(b) WHERE NOT b.name = \"SubmitOrder\" "
+ "RETURN a.name, b.name",
+ "test", 0, &r);
+ ASSERT_EQ(rc, 0);
+ ASSERT_EQ(r.row_count, 2);
+ cbm_cypher_result_free(&r);
+ cbm_store_close(s);
+ PASS();
+}
+
+TEST(cypher_exec_where_not_target_relationship) {
+ cbm_store_t *s = setup_cypher_multi_edge_store();
+ cbm_cypher_result_t r = {0};
+ int rc = cbm_cypher_execute(s,
+ "MATCH (a)-[r:HTTP_CALLS]->(b) WHERE NOT r.url_path = "
+ "\"/health\" RETURN r.url_path",
+ "testproj", 0, &r);
+ ASSERT_EQ(rc, 0);
+ ASSERT_EQ(r.row_count, 1);
+ ASSERT_STR_EQ(r.rows[0][0], "/api/orders");
+ cbm_cypher_result_free(&r);
+ cbm_store_close(s);
+ PASS();
+}
+
+TEST(cypher_exec_where_not_source_node) {
+ cbm_store_t *s = setup_cypher_store();
+ cbm_cypher_result_t r = {0};
+ int rc = cbm_cypher_execute(s,
+ "MATCH (a)-[:CALLS]->(b) WHERE NOT a.name = "
+ "\"HandleOrder\" RETURN a.name, b.name",
+ "test", 0, &r);
+ ASSERT_EQ(rc, 0);
+ ASSERT_EQ(r.row_count, 1);
+ ASSERT_STR_EQ(r.rows[0][0], "ValidateOrder");
+ cbm_cypher_result_free(&r);
+ cbm_store_close(s);
+ PASS();
+}
+
+TEST(cypher_exec_where_not_target_node_count) {
+ cbm_store_t *s = setup_cypher_store();
+ cbm_cypher_result_t r = {0};
+ int rc = cbm_cypher_execute(s,
+ "MATCH (a)-[:CALLS]->(b) WHERE NOT b.name = "
+ "\"SubmitOrder\" RETURN count(*)",
+ "test", 0, &r);
+ ASSERT_EQ(rc, 0);
+ ASSERT_EQ(r.row_count, 1);
+ ASSERT_STR_EQ(r.rows[0][0], "2");
+ cbm_cypher_result_free(&r);
+ cbm_store_close(s);
+ PASS();
+}
+
TEST(cypher_exec_where_in) {
cbm_store_t *s = setup_cypher_store();
cbm_cypher_result_t r = {0};
@@@ -5090,10 -6239,10 +6324,14 @@@ SUITE(cypher)
RUN_TEST(cypher_exec_where_neq_bang);
RUN_TEST(cypher_exec_where_ends_with);
RUN_TEST(cypher_exec_where_not);
+ RUN_TEST(cypher_exec_where_not_on_relationship_target);
+ RUN_TEST(cypher_exec_where_mixed_alias_and);
+ RUN_TEST(cypher_exec_where_mixed_alias_or);
+ RUN_TEST(cypher_exec_where_mixed_alias_xor);
+ RUN_TEST(cypher_exec_where_not_target_node);
+ RUN_TEST(cypher_exec_where_not_target_relationship);
+ RUN_TEST(cypher_exec_where_not_source_node);
+ RUN_TEST(cypher_exec_where_not_target_node_count);
RUN_TEST(cypher_exec_where_in);
RUN_TEST(cypher_exec_where_not_in);
RUN_TEST(cypher_exec_where_is_null);