fix(explore): tests and examples the engine knows stay out of explore's answer

Merged
CO
4d ago
+176-34

What

codegraph_explore decides which files are low value (tests, plus icons and i18n) to drop them before the score floor, halve their rank, and break ties against them. db/queries.ts likewise keeps tests and generated files out of the dominant-file, top-route-file and routing-manifest candidates. Both kept a regex list of their own, written before the engine's isTestFile learned most of what it knows. They missed:

  • C++ foo_test.cc and FooTest.cpp;
  • Google's foo_unittest.cc (#2434);
  • LLVM's unittests/ trees (#2484);
  • testing/, e2e/, __mocks__/, Gradle foo-test/ modules and Kotlin jvmTest/ source sets;
  • the examples, samples, fixtures and benchmarks around a project.

On LLVM-style and Google-style C++ repos, a unit test that calls the code an agent asked about took a file slot in explore's answer.

Both now build on isTestFile, the same reading explore's gather already dampens scores by (×0.3 and a 15% node cap in the context builder). They keep their own extras:

  • explore keeps icons and i18n;
  • queries keeps generated files;
  • both keep the singular __test__/ folder the old lists matched and isTestFile doesn't.

The old lowercase suffix patterns go, along with their false positives: Latest.java, Contest.swift and contest.cs read as tests.

Follow-up from #2484's chip.

Validation: deterministic explore A/B (base main 1753472a vs this change)

  • Method: both builds ran codegraph_explore on the same indexes (the change is query-time only). Each repo got the README suite's flow question or an agent-style one, plus three symbol-bag queries.
  • Repos: django, excalidraw, okhttp, tokio, gin, alamofire; protobuf and glog (Google unittests); and llvm-project 50eb53f0's clang-tools-extra/clangd and lldb/{include,source,unittests,tools}.
  • "Named" counts query tokens with a production definition whose file rendered.
repoqueries changedtest / example files renderednamed
django, excalidraw, okhttp, gin, alamofire0 of 200 → 059/62 → 59/62
tokio1 of 41 → 0 (tokio-test/src/task.rs)9/12 → 9/12
protobuf3 of 44 → 014/14 → 14/14
glog3 of 43 → 0 (src/logging_unittest.cc)8/8 → 8/8
clangd3 of 42 → 011/11 → 11/11
lldb2 of 41 → 011/11 → 11/11
total12 of 4011 → 0112/118 → 112/118
  • Where the freed slots went. In protobuf, DescriptorPool BuildFile FindMessageTypeByName had rendered descriptor_unittest.cc, code_generator_unittest.cc and internal_feature_helper_test.cc. Those slots now go to the PHP, C# and Ruby DescriptorPool implementations. TextFormat Printer Print traded examples/ListPeople.java for Descriptors.java. clangd traded unittests/SymbolCollectorTests.cpp for index/Ref.h. Every other change only dropped a test file, or moved bytes between the same files.
  • No response tells the agent to use Read, in either build.
  • Budgets: the explore budgets are untouched.

Agent A/B not run. A nested claude -p on this machine fails with "OAuth session expired and could not be refreshed", the same blocker #2447 hit. Re-logging the CLI is the maintainer's call. The deterministic A/B above is the evidence for now; the change only removes files the gather already scores at 0.3× from the answer, and backfills from production files.

Tests

__tests__/explore-low-value-tests.test.ts (new):

  • explore answers Parser parseExpression parseStatement Lexer nextToken from src/parser.cc without rendering an LLVM-style unittests/Parse/ParserHarness.h, a parser_unittest.cc or a ParserTest.cpp;
  • getTopRouteFile() names the app's src/routes.js, not an e2e/mock-server.js with more routes.

Both fail on main: explore rendered unittests/Parse/ParserHarness.h, and the route file was e2e/mock-server.js. The 40 explore, context and route-related test files pass (475 tests).

Full suite on Windows: 6,663 passed. 6 failed in the parallel run (daemon-pid-reuse, git-index-currency, mcp-daemon), and all three files pass when rerun serially (35/35); the notes on this box list them as load-sensitive. The 404 skipped are the native-kernel suites, which skip because no kernel was built in this worktree; this change doesn't touch extraction.

🤖 Generated with Claude Code