Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions crates/codegraph-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5831,17 +5831,13 @@ fn glob_match_bytes(pattern: &[u8], value: &[u8]) -> bool {
}
}

/// An explicit `--filter` glob fully REPLACES the heuristic — a user who names
/// their test files takes precedence over any pattern table.
fn is_test_file(file: &str, filter: Option<&str>) -> bool {
if let Some(filter) = filter {
return glob_matches(filter, file);
}
file.contains(".spec.")
|| file.contains(".test.")
|| file.contains("/__tests__/")
|| file.contains("/test/")
|| file.contains("/tests/")
|| file.contains("/e2e/")
|| file.contains("/spec/")
codegraph_core::file_class::is_test_file(file)
}

fn print_json(value: &serde_json::Value) -> Result<()> {
Expand Down Expand Up @@ -6495,6 +6491,15 @@ mod pure_helper_tests {
assert!(is_test_file("app/tests/mod.rs", None));
assert!(is_test_file("e2e/flow.spec.ts", None));
assert!(!is_test_file("src/main.rs", None));
// Go's test convention is a `_test.` stem, not a `.test.` one (#1507).
assert!(is_test_file("pkg/math_test.go", None));
assert!(is_test_file("math_test.go", None));
// Directory patterns are path-SEGMENT anchored, so a repo-root test
// directory (no leading slash) classifies like a nested one.
assert!(is_test_file("e2e/flow.go", None));
assert!(is_test_file("tests/mod.rs", None));
assert!(!is_test_file("internal/latest.go", None));
assert!(!is_test_file("src/route2e2e.ts", None));
}

#[test]
Expand Down
81 changes: 79 additions & 2 deletions crates/codegraph-cli/tests/affected.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ fn fixture() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/godot_audit")
}

fn go_fixture() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/go_test_convention")
}

fn copy_tree(src: &Path, dst: &Path) {
fs::create_dir_all(dst).unwrap();
for entry in fs::read_dir(src).unwrap() {
Expand Down Expand Up @@ -75,9 +79,13 @@ fn cli(args: &[&str]) -> (String, String, bool) {
}

fn indexed_project(label: &str) -> (TestDir, PathBuf) {
indexed_fixture(label, "godot_audit", &fixture())
}

fn indexed_fixture(label: &str, name: &str, src: &Path) -> (TestDir, PathBuf) {
let dir = TestDir::new(label);
let project = dir.path().join("godot_audit");
copy_tree(&fixture(), &project);
let project = dir.path().join(name);
copy_tree(src, &project);
let p = project.to_str().unwrap();
let (out, err, ok) = cli(&["init", p]);
assert!(ok, "init failed: stdout={out} stderr={err}");
Expand Down Expand Up @@ -211,3 +219,72 @@ fn affected_files_superset_of_tests() {
"affectedFiles must also list the non-test dependent main.tscn, got: {affected_files:?}"
);
}

/// Tier 1 item 1 (upstream #1507), end-to-end: Go names its tests `*_test.go`,
/// so a predicate keyed on `.test.` never classifies one. The dependent WAS
/// reachable — `affectedFiles` listed `math_test.go` — while `affectedTests`
/// came back `[]`, i.e. `affected` reported Go's entire test convention as "no
/// coverage". The same run also pins the repo-root `e2e/` directory, which the
/// original `contains("/e2e/")` shape missed for want of a leading slash.
#[test]
fn affected_classifies_go_test_convention_and_root_e2e_dir() {
// Given an indexed Go module where math_test.go calls Add/Double from
// math.go, and a repo-root e2e/flow.go calls Double as well.
let (_dir, project) = indexed_fixture("go-test-conv", "go_test_convention", &go_fixture());
let p = project.to_str().unwrap();

// When affected runs on the implementation file,
let value = affected_json(p, "math.go", &["--depth", "5"]);

// Then both dependents are reachable (this held before the fix too — the
// defect was classification, not traversal),
let affected_files = string_array(&value, "affectedFiles");
for expected in ["math_test.go", "e2e/flow.go"] {
assert!(
affected_files.contains(&expected.to_string()),
"affectedFiles must list {expected}, got: {affected_files:?}"
);
}

// and both are reported as TESTS rather than as production dependents.
let affected_tests = string_array(&value, "affectedTests");
assert!(
affected_tests.contains(&"math_test.go".to_string()),
"Go's `_test.go` convention must count as test coverage, got: {affected_tests:?}"
);
assert!(
affected_tests.contains(&"e2e/flow.go".to_string()),
"a repo-root e2e/ directory must count as test coverage, got: {affected_tests:?}"
);

// and affectedFiles stays a superset of affectedTests.
for test_file in &affected_tests {
assert!(
affected_files.contains(test_file),
"affectedFiles must be a superset of affectedTests; missing {test_file:?} in {affected_files:?}"
);
}
}

/// The explicit `--filter` glob keeps overriding the heuristic: under a filter
/// that matches nothing in the project, `math_test.go` must NOT be classified
/// as a test even though the widened heuristic would now claim it.
#[test]
fn affected_filter_glob_still_overrides_the_heuristic() {
let (_dir, project) = indexed_fixture("go-filter", "go_test_convention", &go_fixture());
let p = project.to_str().unwrap();

let value = affected_json(p, "math.go", &["--depth", "5", "--filter", "*_never.go"]);

let affected_tests = string_array(&value, "affectedTests");
assert!(
affected_tests.is_empty(),
"an explicit --filter that matches nothing must suppress the heuristic, got: {affected_tests:?}"
);
// Traversal is unaffected: the dependents are still listed.
let affected_files = string_array(&value, "affectedFiles");
assert!(
affected_files.contains(&"math_test.go".to_string()),
"a filtered-out test file must remain reachable, got: {affected_files:?}"
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package e2e

import "example.com/mathutil"

func RunCheckoutFlow() int {
return mathutil.Double(21)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module example.com/mathutil

go 1.22
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package mathutil

func Add(a int, b int) int {
return a + b
}

func Double(n int) int {
return Add(n, n)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package mathutil

import "testing"

func TestAdd(t *testing.T) {
if Add(1, 2) != 3 {
t.Fatal("Add is wrong")
}
}

func TestDouble(t *testing.T) {
if Double(2) != 4 {
t.Fatal("Double is wrong")
}
}
Loading
Loading