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
feat(cypher): support label tests in WHERE — WHERE n:Label (#241)
Martin Vogelb30e6d64434c
diff --git a/scripts/smoke-test.sh b/scripts/smoke-test.shindex e107e4e24..0b577fd92 100755--- a/scripts/smoke-test.sh+++ b/scripts/smoke-test.sh@@ -176,6 +176,16 @@ if [ "$WD_ROWS" -lt 1 ]; thenfiecho "OK: query_graph WITH DISTINCT returned $WD_ROWS row(s)"+# #241 WHERE label test — f:Function is true for every Function node.+CYPHER_LBL=$(cli query_graph "{\"project\":\"$PROJECT\",\"query\":\"MATCH (f:Function) WHERE f:Function RETURN f.name\"}")+LBL_ROWS=$(echo "$CYPHER_LBL" | python3 -c "import json,sys; d=json.loads(sys.stdin.read()); print(len(d.get('rows',[])))" 2>/dev/null || echo "0")+if [ "$LBL_ROWS" -lt 1 ]; then+ echo "FAIL: query_graph WHERE label-test returned 0 rows"+ echo "$CYPHER_LBL"+ exit 1+fi+echo "OK: query_graph WHERE f:Function returned $LBL_ROWS row(s)"+# 3e: delete_project cleanupcli delete_project "{\"project\":\"$PROJECT\"}" > /dev/nulldiff --git a/src/cypher/cypher.c b/src/cypher/cypher.cindex 854959386..974f73243 100644--- a/src/cypher/cypher.c+++ b/src/cypher/cypher.c@@ -940,6 +940,20 @@ static cbm_expr_t *parse_condition_expr(parser_t *p) {cbm_condition_t c = {0};c.negated = negated;+ /* Label test: WHERE n:Label (openCypher, #241). Modelled as a leaf with+ * op="HAS_LABEL" and value=Label, evaluated against the bound node's label. */+ if (check(p, TOK_COLON)) {+ advance(p);+ const cbm_token_t *lbl = expect(p, TOK_IDENT);+ if (!lbl) {+ return NULL;+ }+ c.variable = heap_strdup(var->text);+ c.op = heap_strdup("HAS_LABEL");+ c.value = heap_strdup(lbl->text);+ return expr_leaf(c);+ }+if (match(p, TOK_DOT)) {const cbm_token_t *prop = expect(p, TOK_IDENT);if (!prop) {@@ -2061,6 +2075,14 @@ static bool eval_comparison_op(const char *op, const char *actual, const char *e/* Evaluate a WHERE condition against a binding */static bool eval_condition(const cbm_condition_t *c, binding_t *b) {+ /* Label test: WHERE n:Label (#241) — compare the bound node's label+ * directly rather than a property value. */+ if (strcmp(c->op, "HAS_LABEL") == 0) {+ cbm_node_t *n = binding_get(b, c->variable);+ bool result = n && n->label && c->value && strcmp(n->label, c->value) == 0;+ return c->negated ? !result : result;+ }+const char *actual = resolve_condition_value(c, b);if (!actual) {return true;diff --git a/tests/test_cypher.c b/tests/test_cypher.cindex e800e65e8..f4dbd07e5 100644--- a/tests/test_cypher.c+++ b/tests/test_cypher.c@@ -770,6 +770,38 @@ TEST(cypher_exec_with_distinct_issue238) {PASS();}+/* issue #241: label tests in WHERE clauses (openCypher `WHERE n:Label`) —+ * previously a parse error. */+TEST(cypher_exec_where_label_test_issue241) {+ cbm_store_t *s = setup_cypher_store();++ /* f:Function is true for all 4 Function nodes. */+ cbm_cypher_result_t r = {0};+ int rc =+ cbm_cypher_execute(s, "MATCH (f:Function) WHERE f:Function RETURN f.name", "test", 0, &r);+ ASSERT_EQ(rc, 0);+ ASSERT_EQ(r.row_count, 4);+ cbm_cypher_result_free(&r);++ /* f:Class matches none of the functions. */+ cbm_cypher_result_t r2 = {0};+ rc = cbm_cypher_execute(s, "MATCH (f:Function) WHERE f:Class RETURN f.name", "test", 0, &r2);+ ASSERT_EQ(rc, 0);+ ASSERT_EQ(r2.row_count, 0);+ cbm_cypher_result_free(&r2);++ /* Negated label test: NOT f:Class is always true. */+ cbm_cypher_result_t r3 = {0};+ rc =+ cbm_cypher_execute(s, "MATCH (f:Function) WHERE NOT f:Class RETURN f.name", "test", 0, &r3);+ ASSERT_EQ(rc, 0);+ ASSERT_EQ(r3.row_count, 4);+ cbm_cypher_result_free(&r3);++ cbm_store_close(s);+ PASS();+}+/* --- Ported from cypher_test.go: TestExecuteInlinePropertyFilter --- */TEST(cypher_exec_inline_props) {cbm_store_t *s = setup_cypher_store();@@ -2242,6 +2274,7 @@ SUITE(cypher) {/* Go test ports */RUN_TEST(cypher_exec_distinct);RUN_TEST(cypher_exec_with_distinct_issue238);+ RUN_TEST(cypher_exec_where_label_test_issue241);RUN_TEST(cypher_exec_inline_props);RUN_TEST(cypher_parse_where_starts_with);RUN_TEST(cypher_parse_where_contains);