Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions code_review_graph/tools/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,27 @@ def get_docs_section(

search_roots: list[Path] = []

# Wheel install: docs are packaged inside code_review_graph/docs.
in_pkg_docs = (
Path(__file__).parent.parent
/ "docs"
/ "LLM-OPTIMIZED-REFERENCE.md"
)
if repo_root:
try:
search_roots.append(_validate_repo_root(Path(repo_root)))
except ValueError:
pass
else:
search_roots.append(find_project_root())
elif in_pkg_docs.exists():
in_pkg_root = in_pkg_docs.parent.parent
search_roots.append(in_pkg_root)

if not repo_root:
project_root = find_project_root()
if project_root not in search_roots:
search_roots.append(project_root)

# Fallback: package directory (for uvx/pip installs)
# Editable/source-tree fallback: docs live next to code_review_graph/.
pkg_docs = (
Path(__file__).parent.parent.parent
/ "docs"
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ dev = [
[tool.hatch.build.targets.wheel]
packages = ["code_review_graph"]

[tool.hatch.build.targets.wheel.force-include]
"docs/LLM-OPTIMIZED-REFERENCE.md" = "code_review_graph/docs/LLM-OPTIMIZED-REFERENCE.md"

[tool.hatch.build.targets.sdist]
include = [
"code_review_graph/",
Expand Down
32 changes: 32 additions & 0 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest

import code_review_graph.tools.docs as docs_module
from code_review_graph.graph import GraphStore, _sanitize_name, node_to_dict
from code_review_graph.parser import EdgeInfo, NodeInfo
from code_review_graph.tools import (
Expand Down Expand Up @@ -189,6 +190,37 @@ def test_real_section_lookup(self):
if result["status"] == "ok":
assert len(result["content"]) > 0

def test_source_tree_docs_lookup_from_outside_repo(self, tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
monkeypatch.delenv("CRG_REPO_ROOT", raising=False)

result = get_docs_section(section_name="usage")

assert result["status"] == "ok"
assert len(result["content"]) > 0

def test_packaged_docs_lookup_from_outside_repo(self, tmp_path, monkeypatch):
package_dir = tmp_path / "site-packages" / "code_review_graph"
tools_dir = package_dir / "tools"
docs_dir = package_dir / "docs"
tools_dir.mkdir(parents=True)
docs_dir.mkdir()
(docs_dir / "LLM-OPTIMIZED-REFERENCE.md").write_text(
'<section name="usage">packaged docs</section>\n',
encoding="utf-8",
)
work_dir = tmp_path / "elsewhere"
work_dir.mkdir()

monkeypatch.chdir(work_dir)
monkeypatch.delenv("CRG_REPO_ROOT", raising=False)
monkeypatch.setattr(docs_module, "__file__", str(tools_dir / "docs.py"))

result = docs_module.get_docs_section("usage")

assert result["status"] == "ok"
assert result["content"] == "packaged docs"


class TestFindLargeFunctions:
"""Tests for find_large_functions via direct store access."""
Expand Down