@@ -1869,6 +1869,35 @@ static const char **extract_decorators(CBMArena *a, TSNode node, const char *sou
18691869 * first and one branch is lost (#495). Fold the cfg predicate into the QN so
18701870 * each cfg-gated twin gets a DISTINCT, predicate-encoding QN. Returns the
18711871 * (possibly suffixed) QN; the original QN when no cfg attribute is present. */
1872+ /* Rust: mark a function as a test when it carries a test attribute (#855).
1873+ * cbm's test detection is otherwise file-path-based (cbm_is_test_file:
1874+ * *_test.rs / test_*), so inline #[test]/#[tokio::test] functions inside a
1875+ * regular .rs file are indexed as ordinary Functions (is_test=false) and leak
1876+ * past the store.c `is_test != 1` filter into graph/agent context. The
1877+ * attribute_item text extract_decorators stores is the bracketed form
1878+ * ("#[test]", "#[tokio::test]", "#[tokio::test(...)]", ...). */
1879+ static bool rust_def_is_test (const char * const * decorators ) {
1880+ if (!decorators ) {
1881+ return false;
1882+ }
1883+ for (int i = 0 ; decorators [i ]; i ++ ) {
1884+ const char * d = decorators [i ];
1885+ /* Path-qualified async/param test macros (substring match, robust to the
1886+ * optional argument list and the surrounding #[ ]). */
1887+ if (strstr (d , "tokio::test" ) || strstr (d , "async_std::test" ) ||
1888+ strstr (d , "actix_rt::test" ) || strstr (d , "test_case::case" )) {
1889+ return true;
1890+ }
1891+ /* Bare #[test] / #[test(...)]: match the bracketed path exactly so we do
1892+ * NOT match the unrelated #[test_case::case] (handled above) or a
1893+ * hypothetical #[test_crate]. */
1894+ if (strstr (d , "#[test]" ) || strstr (d , "#[test(" )) {
1895+ return true;
1896+ }
1897+ }
1898+ return false;
1899+ }
1900+
18721901static const char * rust_cfg_qualified_name (CBMArena * a , const char * base_qn ,
18731902 const char * const * decorators ) {
18741903 if (!decorators ) {
@@ -3192,6 +3221,7 @@ static void extract_func_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec
31923221 // predicate into the QN so both branches survive the graph upsert (#495).
31933222 if (ctx -> language == CBM_LANG_RUST ) {
31943223 def .qualified_name = rust_cfg_qualified_name (a , def .qualified_name , def .decorators );
3224+ def .is_test = rust_def_is_test (def .decorators );
31953225 }
31963226
31973227 // Docstring
0 commit comments