Skip to content

fix(search): grep and callers get the test handling #37 gave ask (#425) - #862

Draft
hr1juldey wants to merge 1 commit into
trailhq:mainfrom
hr1juldey:fix/425-test-files-label
Draft

hr1juldey wants to merge 1 commit into
trailhq:mainfrom
hr1juldey:fix/425-test-files-label

Conversation

@hr1juldey

Copy link
Copy Markdown

Fixes #425.

What was missing

#37 landed test handling in ask (a rank penalty) and blast (separate testModules) — grep and callers got neither. Test hits came back unlabelled next to production code, and --in can narrow but cannot exclude, which does not help the colocated layout (service.ts + service.test.ts). In the reporter's production repro ~80% of one grep answer (~4,300 tokens) was test lines.

Fix

  • isTestPath moves to the search layer (src/search/grep.ts) with the pattern extracted to a named constant (TEST_PATH_RE) and the discriminating choices documented (why .test. needs the dots — testing.ts stays production). ask imports it from there and re-exports, so its behavior and public surface are unchanged; grep, callers and ask now share one predicate.
  • Label + order (the issue's second option): the grep formatter marks test-file groups [test] and lists them after production groups — a stable partition, so the in-degree ordering inside each half is untouched. callers labels a test-file edge calls ← service.test.ts (…) [test] and orders those after production callers.
  • The flag (the issue's first option): --no-tests on both commands drops test files entirely. Excluded files are not counted into grep's "searched N indexed files" — they were not searched.
  • Threaded through the workspace federation (federateGrep / federateCallers), so workspace grep/callers behave the same as single-repo ones.

JSON shapes are unchanged; the label and ordering live in the formatters, which the MCP tools (graft_find_all, graft_trace_calls) already share — they pick the behavior up for free.

Tests (RED→GREEN, adversarial)

  • grepGraph default keeps both files; includeTests: false leaves only production, and filesSearched drops by the excluded file (it was not searched);
  • the formatter labels the test group [test], does NOT label the production file (including the service.ts suffix-inside-service.test.ts trap), and lists the test group last even when it sorted first;
  • isTestPath covers the documented shapes (*.test.ts, *.spec.js, __tests__/, tests/, _test.go, conftest.py, test_*.py) and refuses lookalikes (testing.ts, contest.py, latest.ts);
  • hitLine labels a test-file edge, leaves production unlabelled, and leaves unresolved-import rows (no path to judge) unlabelled.
  • Full suite: fail-6 (the six pre-existing main failures), 4552 tests.

…sk (trailhq#425)

Test files came back from `grep` and `callers` unlabelled, next to
production code, with no way to leave them out — in the reporter's
production repro about 80% of a grep answer (~4,300 tokens) was test
lines. trailhq#37's detection existed (`isTestPath` in ask) but never reached
these two commands.

- isTestPath moves to the search layer (grep.ts) with the pattern as a
  named constant (TEST_PATH_RE), so grep, callers and ask share one
  predicate; ask re-exports it, behavior unchanged.
- grep/callers: test hits carry a [test] label and list after
  production ones (stable partition — in-degree/BFS order inside each
  half untouched).
- both commands gain --no-tests to drop test files entirely; excluded
  files are not counted into grep's "searched N indexed files" (they
  were not searched).
- Threaded through the workspace federation too, so a workspace grep or
  callers behaves the same as a single-repo one.

The JSON shapes are unchanged; the label and ordering are formatter
behavior, and the MCP tools render through the same formatters, so
graft_find_all picks the label up for free.
@github-actions

Copy link
Copy Markdown
Contributor

🌱 graft blast radius

4 areas changed → 7 areas can be affected. 15 dependent symbols, depth 2.
Tests: 2 areas updated their tests.
Tag: @anirudhkumar-nanonets — 8 of 11 areas · @shhdwi — 8 of 11 areas · Rushabh Nagda — First Run Setup

flowchart TB
  A0(("MCP Tool Invocation<br/>6 symbols"))
  A1(("Cloud Onboarding<br/>3 symbols"))
  A2(("Engine Initialization<br/>2 symbols"))
  A3(("Notes Query<br/>1 symbol"))
  A4(("First Run Setup<br/>1 symbol"))
  AX(("2 smaller areas<br/>2 symbols"))
  classDef reached fill:#D9EDF3,stroke:#3AA7C9,stroke-width:1.5px,color:#0E313C;
  class A0,A1,A2,A3,A4 reached;
  classDef tail fill:#EEF2F3,stroke:#9AA4A9,stroke-width:1px,color:#3A4247;
  class AX tail;
Loading
Can be affected Symbols Nearest hop Reached from
MCP Tool Invocation 6 src/mcp/tools.ts:L1-L352 tools.ts — imports, depth 1 Ask Query, Workspace Callers +1
Cloud Onboarding 3 src/cloud/lookup-activity.ts:L1-L60 lookup-activity.ts — imports, depth 1 Ask Query
Engine Initialization 2 src/engine.ts:L1-L194 engine.ts — imports, depth 1 Ask Query
Notes Query 1 src/notes/ask-notes.ts:L1-L25 ask-notes.ts — imports, depth 1 Ask Query
First Run Setup 1 src/init/first-minute.ts:L1-L646 first-minute.ts — imports, depth 2 Ask Query
Graph Root 1 src/graph/root.ts:L1-L98 root.ts — imports, depth 2 Ask Query
1 smaller area 1 Claude Sync Run see below
Who knows this code — 4 people across 11 areas
Area Who knows it
Ask Query · changed @anirudhkumar-nanonets — 17 commits, last 16d ago · @shhdwi — 18 commits, last 27d ago
Workspace Callers · changed @shhdwi — 13 commits, last 22d ago · @anirudhkumar-nanonets — 7 commits, last 3mo ago
Graph Search · changed @shhdwi — 5 commits, last 27d ago · @anirudhkumar-nanonets — 5 commits, last 29d ago
CLI Entry Point · changed @anirudhkumar-nanonets — 75 commits, last yesterday · @shhdwi — 51 commits, last 22d ago
MCP Tool Invocation · affected @shhdwi — 21 commits, last 22d ago · @anirudhkumar-nanonets — 14 commits, last 22d ago
Cloud Onboarding · affected @shhdwi — 22 commits, last 22d ago
Engine Initialization · affected @anirudhkumar-nanonets — 17 commits, last 1mo ago
Notes Query · affected @anirudhkumar-nanonets — 2 commits, last 10d ago
…3 further areas

Ownership is git history over each area's own files, weighted towards recent work (120-day half-life). Merge commits and bots are dropped, and you are dropped from your own PR. A name with no @ has no GitHub handle in its commit email — tag them by hand, or add a .mailmap entry. A suggestion from history, not a CODEOWNERS rule.

All 15 dependent symbols, grouped by area

MCP Tool Invocation — 6 symbols in 2 files

  • src/mcp/tools.ts:L1-L352 — tools.ts (imports, depth 1)
    6: import { join } from 'node:path';
  • src/mcp/tools.ts:L136-L151 — renderMatches (calls, depth 1)
    147: else for (const h of hits) lines.push(hitLine(direction, h, showDepth));
  • src/mcp/tools.ts:L157-L203 — callWorkspaceTool (calls, depth 1)
    175: const { text, found } = federateCallers(root, dirOverride, symbol, {
  • src/mcp/tools.ts:L265-L351 — callSingleTool (calls, depth 1)
    303: // file at depth>1 it walks the file node AND every symbol defined in
  • src/mcp/server.ts:L1-L257 — server.ts (imports, depth 2)
    5: import { createInterface } from 'node:readline';
  • src/mcp/tools.ts:L233-L262 — callTool (calls, depth 2)

Cloud Onboarding — 3 symbols in 3 files

  • src/cloud/lookup-activity.ts:L1-L60 — lookup-activity.ts (imports, depth 1)
    14: /** The file part of a hit's `file:Lx-Ly` pointer. */
  • src/cloud/onboarding.ts:L1-L735 — onboarding.ts (imports, depth 1)
    22: import { execFileSync } from "node:child_process";
  • src/cloud/pair.ts:L1-L368 — pair.ts (imports, depth 2)
    15: import { spawn } from "node:child_process";

Engine Initialization — 2 symbols in 2 files

  • src/engine.ts:L1-L194 — engine.ts (imports, depth 1)
    166: /** Per-node crux summarizer for the code graph's Tier-2 pass. */
  • src/index.ts:L1-L47 — index.ts (imports, depth 2)
    27: export type { ContextNode, NodeLink, SourceRef, Manifest } from "./context/node-file.js";

Notes Query — 1 symbol in 1 file

  • src/notes/ask-notes.ts:L1-L25 — ask-notes.ts (imports, depth 1)
    10: /** The file part of a hit's `file:Lx-Ly` pointer. */

First Run Setup — 1 symbol in 1 file

  • src/init/first-minute.ts:L1-L646 — first-minute.ts (imports, depth 2)
    35: import { readFileSync } from 'node:fs';

Graph Root — 1 symbol in 1 file

  • src/graph/root.ts:L1-L98 — root.ts (imports, depth 2)
    16: import { closeSync, existsSync, openSync, readSync, statSync } from "node:fs";

Claude Sync Run — 1 symbol in 1 file

  • src/claude/sync-run.ts:L1-L77 — sync-run.ts (imports, depth 2)
    1: import { execFileSync } from 'node:child_process';
Test signal per changed area — 2 ✓ · 2 –

Reached = a node under a test path has a resolved edge into the changed symbol. It undercounts anything called indirectly — through a CLI, a spawned process or a dynamic import — so read a low ratio as “look here”, never as a coverage gate.

  • – Ask Query — 12 test files reach it, none changed here
  • ✓ Workspace Callers — 3 of 7 reached · 1 test file changed here: test/traverse-test-label.test.ts
    • not reached: orderAndFilterTestHits, runCallersCommand, runWorkspaceGrep, runWorkspaceCallers
  • ✓ Graph Search — 3 of 5 reached · 2 test files changed here: test/search-grep.test.ts, test/traverse-test-label.test.ts
    • not reached: groupHeader, runGrepCommand
  • – CLI Entry Point — no function, method or class changed here
26 test suites also reference this code

27 symbols, kept out of the diagram and the table so they cannot crowd out the areas a reviewer has to look at.

  • test/ask-fusion.test.ts
  • test/ask-index.test.ts
  • test/ask.test.ts
  • test/claude-hooks.test.ts
  • test/context-only-dir.test.ts
  • test/engine-init-concurrency.test.ts
  • test/engine-synth-model.test.ts
  • test/generic-extract.test.ts
  • test/graph-extensions.test.ts
  • test/graph-follow-submodules.test.ts
  • test/graph-imported-call-mcp.test.ts
  • test/graph-load.test.ts
  • test/graph-posix-paths.test.ts
  • test/graph-refresh.test.ts
  • test/graph-seed.test.ts
  • test/graph-workspace-include-dir.test.ts
  • test/graphrank.test.ts
  • test/mcp-tools.test.ts
  • test/regression-single-repo.test.ts
  • test/savings-locale.test.ts
  • …6 more

graft blast · origin/main...HEAD · depth 2 · 9 changed files

Open the interactive graph → — click an area to see its dependent symbols at file:line.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

grep and callers have no test handling — #37 reached ask and blast only (5 of 8 grep hits in a small repro are test lines; ~80% of a real answer)

1 participant