Skip to content

Fix source_file path lookup for explain and affected#1503

Closed
behavio1 wants to merge 1 commit into
Graphify-Labs:v8from
behavio1:codex/fix-source-file-path-lookup
Closed

Fix source_file path lookup for explain and affected#1503
behavio1 wants to merge 1 commit into
Graphify-Labs:v8from
behavio1:codex/fix-source-file-path-lookup

Conversation

@behavio1

Copy link
Copy Markdown
Contributor

Summary

This PR fixes full source_file path lookup for:

  • graphify explain "<source-file-path>"
  • graphify affected "<source-file-path>"

It also adds regression coverage for the case where a graph contains multiple
nodes from the same source file, such as a file-level node plus function nodes.

Root cause

Graphs can contain several nodes with the same source_file. For example, a
route file can have a file-level route.ts node and a GET() handler node from
the same path.

Before this change:

  • explain could miss full path queries because _find_node() tokenizes the
    query, while the trigram prefilter only indexed the raw source_file.
  • affected could fail to resolve a full path because exact source_file
    lookup returned multiple candidate nodes and no preferred seed.

What changed

  • Include tokenized source_file text in the serve.py trigram search index.
  • Let _find_node() match exact tokenized source_file paths.
  • Prefer the file-level node when a full source path matches multiple nodes from
    the same file.
  • Apply the same file-level preference in affected.resolve_seed().
  • Add regression tests for explain, affected, and _find_node().

Validation

uv run python -m py_compile graphify/serve.py graphify/affected.py
uv run ruff check graphify/serve.py graphify/affected.py tests/test_serve.py tests/test_affected_cli.py tests/test_explain_cli.py
uv run pytest tests/test_serve.py tests/test_affected_cli.py tests/test_explain_cli.py -q
env -u GEMINI_API_KEY -u GOOGLE_API_KEY -u GOOGLE_GENAI_API_KEY -u MOONSHOT_API_KEY -u ANTHROPIC_API_KEY -u OLLAMA_BASE_URL uv run pytest tests/ -q

Full test result with provider env vars unset:

2430 passed, 28 skipped

safishamsi pushed a commit that referenced this pull request Jun 27, 2026
…e nodes (#1503)

A path query like `explain "app/api/route.ts"` tokenized to terms that matched no
node, so explain/affected returned "No node matching". Source-file paths are now
part of the search index and matched exactly (serve._find_node gains a leading
source-exact tier; affected.resolve_seed gains a source-file match). When several
nodes share a source_file (e.g. a file-level node plus a function node), the lookup
prefers the file-level node — the L1 node whose label basename matches the queried
filename, falling back to the unique L1 or unique basename match, else None.

Ported from PR #1503 by @behavio1. Maintainer fixes on top: aligned trailing-
separator handling between resolve_seed and _find_node (affected previously
returned None for a trailing-slash path that explain resolved), corrected the
stale "three-tier" _find_node docstring, and added regression tests for the
trailing-slash parity and the ambiguous-no-file-node -> None case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@safishamsi

Copy link
Copy Markdown
Collaborator

Thanks @behavio1 — real bug, cleanly fixed, and the multi-node-per-source-file regression tests are exactly the right coverage. The file-node preference (L1 + basename match, with safe fallbacks) is sensible. Landed on v8 in 1b99496 with your authorship. Two small maintainer fixes on top: aligned trailing-separator handling between resolve_seed (affected) and _find_node (explain) — affected previously returned None for a trailing-slash path that explain resolved — and corrected the stale _find_node docstring; added regression tests for both. Verified end-to-end: path query resolves to the file node, label lookups unaffected, nonexistent path graceful, ambiguous no-L1 returns None. Closing as merged-by-port.

@safishamsi safishamsi closed this Jun 27, 2026
safishamsi added a commit that referenced this pull request Jun 28, 2026
Dates the 0.8.51 CHANGELOG and bumps the version. Highlights: Obsidian export no
longer overwrites user notes / .obsidian config in an existing vault (#1506);
cross-file node-ID cluster fixes — C# resolver (#1466), Go sourceless stubs
(#1500), import-stub disambiguation (#1462); Java enum/annotation type nodes
(#1512) + generic parents (#1510); explain/affected source-file path lookup
(#1503); claude-cli Windows GBK fix (#1505); macOS install docs (#1471) and the
global-add docs fix (#1489).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

3 participants