fix(query): narrow marker fallback and complete help

Refs #1654

AI-Assistance: OpenAI Codex
(cherry picked from commit 52404fc1a1)
This commit is contained in:
Alex Tumanov authored and safishamsi committed 2026-11-03 22:25:19 +00:00
1 parent 19eacc74a1
commit 5b8415f368
4 files changed
+42 -10

No files matched your search

+4 -2
View File
@@ -933,8 +933,10 @@ def _run_cli() -> None:
print(" --context C explicit edge-context filter (repeatable)")
print(" --seed X start at node X (id, label or file path; repeatable)")
print(" instead of the question's keyword matches")
print(" --budget N token budget (project .graphifyrc, otherwise 2000)")
print(" --depth N, --depth=N traversal depth 1-6 (project .graphifyrc, otherwise 2)")
print(" --budget N, --budget=N cap output at N tokens (default 2000)")
print(" --depth N, --depth=N traversal depth 1-6 (default 2)")
print(" absent options use the selected graph project's .graphifyrc")
print(" query_budget / query_depth. Explicit options override project values.")
print(" --graph <path> path to graph.json (default graphify-out/graph.json)")
print(" query, path and explain exit 0 with an answer, 3 when a name is ambiguous")
print(" (the candidates are listed), 4 when no node matches")
+8 -4
View File
@@ -168,10 +168,14 @@ def _graph_root_for(gp: Path) -> Path:
if text:
root = Path(text)
if root.is_absolute():
root = root.resolve()
if root.is_dir():
return root
except (OSError, UnicodeError, ValueError, RuntimeError):
try:
resolved = root.resolve()
except RuntimeError:
pass # Path resolution can report a symlink loop this way.
else:
if resolved.is_dir():
return resolved
except (OSError, UnicodeError, ValueError):
pass
# CLI-written absolute markers cover shared output. Otherwise strip only
+7 -3
View File
@@ -69,6 +69,10 @@ def test_help_lists_every_install_platform():
def test_help_lists_project_query_defaults_and_depth_range():
result = subprocess.run([PYTHON, "-m", "graphify", "--help"], capture_output=True, text=True)
assert result.returncode == 0
assert "--depth N" in result.stdout
assert "1-6" in result.stdout
assert ".graphifyrc" in result.stdout
assert "--budget N, --budget=N" in result.stdout
assert "--depth N, --depth=N" in result.stdout
assert "1-6 (default 2)" in result.stdout
assert "tokens (default 2000)" in result.stdout
assert "query_budget" in result.stdout and "query_depth" in result.stdout
assert "selected graph project's .graphifyrc" in result.stdout
assert "Explicit options override project values" in result.stdout
+23 -1
View File
@@ -358,7 +358,7 @@ def test_query_root_marker_is_absolute_directory_or_falls_back(monkeypatch, tmp_
assert _graph_root_for(gp) == expected
@pytest.mark.parametrize("failure", [OSError("unreadable"), UnicodeError("bad encoding"), ValueError("invalid path"), RuntimeError("resolve loop")])
@pytest.mark.parametrize("failure", [OSError("unreadable"), UnicodeError("bad encoding"), ValueError("invalid path")])
def test_query_root_expected_marker_failures_fall_back(monkeypatch, tmp_path, failure):
from graphify.cli import _graph_root_for
@@ -450,3 +450,25 @@ def test_query_reads_custom_output_selected_project_settings(monkeypatch, tmp_pa
for consumer in ["execution", "log"]:
assert (captured[consumer]["token_budget"], captured[consumer]["depth"]) == (4000, 4)
assert captured["execution"]["seed_root"] == project
@pytest.mark.parametrize("operation", ["read_text", "is_dir"])
def test_query_root_unexpected_runtime_error_propagates(monkeypatch, tmp_path, operation):
from graphify.cli import _graph_root_for
directory = tmp_path / "graphify-out"
directory.mkdir()
target = tmp_path / "project"
target.mkdir()
marker = directory / ".graphify_root"
marker.write_text(str(target), encoding="utf-8")
original = getattr(Path, operation)
def unexpected(path, *args, **kwargs):
if path == (marker if operation == "read_text" else target):
raise RuntimeError("unexpected marker operation")
return original(path, *args, **kwargs)
monkeypatch.setattr(Path, operation, unexpected)
with pytest.raises(RuntimeError, match="unexpected marker operation"):
_graph_root_for(directory / "graph.json")