Skip to content

Commit 6e707f1

Browse files
anvansterclaude
andcommitted
fix(parser): persist is_test on Rust function nodes (partial)
ir_to_graph wrote is_async/is_static/is_abstract but not is_test, so the graph never carried the marker the visitor already computes. Add it, plus a regression test that a #[test] fn with a descriptive name inside `#[cfg(test)] mod tests` sets is_test. NOTE: insufficient on its own — end-to-end pr_context still misreports coverage; is_test is not reaching the queried nodes in the real indexing pipeline (cause not yet isolated; not a cache artifact). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent ba5942f commit 6e707f1

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

crates/codegraph-rust/src/mapper.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ pub fn ir_to_graph(
7171
.with("line_end", func.line_end as i64)
7272
.with("is_async", func.is_async)
7373
.with("is_static", func.is_static)
74-
.with("is_abstract", func.is_abstract);
74+
.with("is_abstract", func.is_abstract)
75+
.with("is_test", func.is_test);
7576

7677
// Add complexity metrics if available
7778
if let Some(ref complexity) = func.complexity {

crates/codegraph-rust/src/visitor.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,33 @@ fn test_something() {}
13201320
assert!(visitor.functions[0].is_test);
13211321
}
13221322

1323+
#[test]
1324+
fn test_visitor_test_fn_inside_cfg_test_mod() {
1325+
// The idiomatic Rust unit-test shape: a #[test] fn with a descriptive
1326+
// (non-`test_`) name inside `#[cfg(test)] mod tests`. This is what the
1327+
// PR-review coverage analysis was missing.
1328+
let source = r#"
1329+
fn weighted_mean_l2() {}
1330+
1331+
#[cfg(test)]
1332+
mod tests {
1333+
use super::*;
1334+
1335+
#[test]
1336+
fn weighted_mean_l2_math() {
1337+
weighted_mean_l2();
1338+
}
1339+
}
1340+
"#;
1341+
let visitor = parse_and_visit(source);
1342+
let t = visitor
1343+
.functions
1344+
.iter()
1345+
.find(|f| f.name == "weighted_mean_l2_math")
1346+
.expect("nested test fn should be visited");
1347+
assert!(t.is_test, "#[test] fn inside `mod tests` must set is_test");
1348+
}
1349+
13231350
#[test]
13241351
fn test_visitor_visibility_modifiers() {
13251352
let source = r#"

0 commit comments

Comments
 (0)