`codegraph affected` kept six regexes of its own — `.test.`, `.spec.`, `/tests/`… — so a Go `foo_test.go`, a Python `test_foo.py` or a JVM `FooTest.kt` beside the changed file was never reported, and "no tests affected" read as "no coverage". Use isTestPath from search/query-utils, the same predicate search and the MCP tools already rank by. Cherry-picked from danusha2345's upstream PR #1688 (commit 995b6f1f262564cafa6eb0b026b84fa4122f2cb0). Preserve main's CLI imports and Unreleased entries, and credit the contributor in the changelog. The default affected depth remains 5. Fixes #1507. Supersedes #1688. Verified on Linux with Node 22.19.0: npm run build; the Go fixture changes from no affected tests to math_test.go; matching and nonmatching custom filters still override. Vitest: 3 files, 36 tests passed, including the upstream Go/Python/Kotlin suite and affected path/dependency coverage. Co-authored-by: danusha2345 <ewidusoc498@gmail.com>
This commit is contained in:
co-authored by
danusha2345
parent
9181dd1ef3
commit
64bd45cd2a
+7
-11
@@ -61,6 +61,7 @@ import { BROWSER_ENV, DEFAULT_UI_PORT } from '../ui-server/constants';
|
||||
import type { UiServerHandle } from '../ui-server';
|
||||
import { lookupSymbolNodes, describeSymbolNode, groupDefinitions } from '../graph/symbol-lookup';
|
||||
import type { Node, Edge } from '../types';
|
||||
import { isTestPath } from '../search/query-utils';
|
||||
|
||||
// Decided once, before `--color`/`--no-color` are stripped from argv below
|
||||
// (#1281). Piped/redirected stdout, NO_COLOR, or --no-color -> plain output.
|
||||
@@ -2452,16 +2453,6 @@ program
|
||||
const cg = await CodeGraph.open(projectPath);
|
||||
const maxDepth = parseInt(options.depth || '5', 10);
|
||||
|
||||
// Common test file patterns
|
||||
const defaultTestPatterns = [
|
||||
/\.spec\./,
|
||||
/\.test\./,
|
||||
/\/__tests__\//,
|
||||
/\/tests?\//,
|
||||
/\/e2e\//,
|
||||
/\/spec\//,
|
||||
];
|
||||
|
||||
// Custom filter pattern
|
||||
let customFilter: RegExp | null = null;
|
||||
if (options.filter) {
|
||||
@@ -2474,9 +2465,14 @@ program
|
||||
customFilter = new RegExp(regex);
|
||||
}
|
||||
|
||||
// One notion of "a test" for the whole tool (#1507): the CLI used to keep
|
||||
// its own six regexes here, which knew `.test.` and `/tests/` but not Go's
|
||||
// `_test.go`, Python's `test_x.py` or the JVM's `FooTest.kt` — so
|
||||
// `affected` reported "no tests" for whole ecosystems while `search` and
|
||||
// the MCP tools counted those very files as tests.
|
||||
function isTestFile(filePath: string): boolean {
|
||||
if (customFilter) return customFilter.test(filePath);
|
||||
return defaultTestPatterns.some(p => p.test(filePath));
|
||||
return isTestPath(filePath);
|
||||
}
|
||||
|
||||
// BFS to find all transitive dependents of changed files, filtered to test files
|
||||
|
||||
Reference in New Issue
Block a user