Turbocharge Claude Code, Cursor, Codex, Gemini & every coding agent: faster, cheaper, with contextual understanding specific to your codebase.
TypeScript ai-agentsanthropicclaude-codeclicode-graphcodexcontext-engineeringcursordeveloper-toolsgeminiknowledge-graphllmmcpmcp-serveropen-sourceopenaitree-sitter
fix(ask): de-rank pytest test_*.py + conftest.py in isTestPath
Shrish Dwivedi7a631352e446
diff --git a/src/ask/ask.ts b/src/ask/ask.tsindex fe41bd7d..17e1c650 100644--- a/src/ask/ask.ts+++ b/src/ask/ask.ts@@ -141,7 +141,7 @@ function loadCorpus(outDir: string): Corpus {* the results (they still matter for "where are the tests") but below the real* definition. Covers Go (`_test.go`), JS/TS (`.test.` / `.spec.`), and test dirs. */export function isTestPath(path: string): boolean {- return /(^|\/)(tests?|__tests__|spec)\/|(_test|\.test|\.spec)\.[a-z]+$/i.test(path || "");+ return /(^|\/)(tests?|__tests__|spec)\/|(_test|\.test|\.spec)\.[a-z]+$|(^|\/)(test_[^/]+|conftest)\.py$/i.test(path || "");}const TEST_RANK_PENALTY = 0.35;diff --git a/test/ask.test.ts b/test/ask.test.tsindex de43b353..3ae25db0 100644--- a/test/ask.test.ts+++ b/test/ask.test.ts@@ -21,6 +21,22 @@ test("isTestPath: de-ranks test files, not real source", () => {assert.ok(!isTestPath(p), `${p} should NOT be a test path`);});+test("isTestPath: recognizes pytest's test_*.py prefix and conftest, even outside a tests/ dir", () => {+ // pytest's dominant convention is the FILENAME prefix test_*.py — and repos put+ // these outside a tests/-named dir (kombu uses t/unit/). Missing these swamps+ // `ask` with test methods on well-tested Python repos.+ for (const p of [+ "t/unit/transport/test_qpid.py", // kombu layout+ "t/unit/test_messaging.py",+ "test_foo.py", // bare pytest file+ "src/pkg/test_utils.py", // pytest file beside source+ "conftest.py", "a/b/conftest.py", // pytest fixtures file+ ]) assert.ok(isTestPath(p), `${p} should be a test path`);+ // must NOT over-match ordinary source that merely contains "test"+ for (const p of ["src/contest.py", "src/latest_value.py", "pkg/attestation.py"])+ assert.ok(!isTestPath(p), `${p} should NOT be a test path`);+});+test("test files rank below the source they exercise for a non-test query, but not for a test-seeking one", async () => {const dir = mkdtempSync(join(tmpdir(), "graft-ask-testrank-"));try {