Skip to content

Commit cdeaff1

Browse files
authored
Merge pull request #470 from escoffier-labs/fix/issue-442-deliberation-probe-flags
fix(deliberation): stop passing --markdown/--limit to graph probe commands
2 parents 0941c3e + 286fea1 commit cdeaff1

2 files changed

Lines changed: 64 additions & 4 deletions

File tree

src/brigade/deliberation.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,15 @@ def _truncate_scope_text(text: str, limit: int = 3500) -> str:
147147
return clipped.rstrip() + note
148148

149149

150-
def _graphtrail_markdown(cwd: Path, db_path: Path, args: list[str]) -> str:
150+
def _graphtrail_scope_text(cwd: Path, db_path: Path, args: list[str], *, markdown: bool = False) -> str:
151151
binary = _graphtrail_bin()
152152
if binary is None:
153153
return ""
154+
# Only `context` accepts --markdown/--limit; callers, callees, and impact
155+
# reject them and would exit non-zero, leaving the planner one scope short.
156+
extra = ["--markdown", "--limit", "8"] if markdown else []
154157
result = proc.run(
155-
[binary, "--db", str(db_path), *args, "--markdown", "--limit", "8"],
158+
[binary, "--db", str(db_path), *args, *extra],
156159
timeout=10.0,
157160
cwd=cwd,
158161
)
@@ -208,7 +211,7 @@ def _candidate_graphtrail_scopes(cwd: Path, task: str) -> list[EvidenceScope]:
208211
if not db_path.is_file():
209212
return []
210213
candidates: list[EvidenceScope] = []
211-
context_text = _graphtrail_markdown(cwd, db_path, ["context", task])
214+
context_text = _graphtrail_scope_text(cwd, db_path, ["context", task], markdown=True)
212215
if context_text:
213216
candidates.append(
214217
EvidenceScope(
@@ -228,7 +231,7 @@ def _candidate_graphtrail_scopes(cwd: Path, task: str) -> list[EvidenceScope]:
228231
("graphtrail-callees", ["callees", symbol]),
229232
("graphtrail-impact", ["impact", symbol]),
230233
):
231-
text = _graphtrail_markdown(cwd, db_path, command)
234+
text = _graphtrail_scope_text(cwd, db_path, command)
232235
if not text:
233236
continue
234237
candidates.append(

tests/test_deliberation.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,3 +631,60 @@ def test_runs_show_and_watch_surface_deliberation(tmp_path, capsys):
631631
out = capsys.readouterr().out
632632
assert "deliberation:" in out
633633
assert meta is not None
634+
635+
636+
_FAKE_GRAPHTRAIL = """\
637+
#!/bin/sh
638+
# Mimics the installed graphtrail CLI's flag surface: `context` accepts
639+
# --markdown/--limit/--json, while callers/callees/impact reject them.
640+
shift 2
641+
cmd="$1"
642+
shift
643+
case "$cmd" in
644+
context)
645+
shift
646+
for arg in "$@"; do
647+
if [ "$arg" = "--json" ]; then
648+
echo '{"entry_points":[{"qualified_name":"module.fn"}]}'
649+
exit 0
650+
fi
651+
done
652+
echo "# context pack"
653+
exit 0
654+
;;
655+
callers|callees|impact)
656+
shift
657+
for arg in "$@"; do
658+
case "$arg" in
659+
--markdown|--limit)
660+
echo "error: unexpected argument '$arg' found" >&2
661+
exit 2
662+
;;
663+
esac
664+
done
665+
echo "$cmd edge list"
666+
exit 0
667+
;;
668+
esac
669+
exit 2
670+
"""
671+
672+
673+
def test_candidate_scopes_survive_probe_flag_rejection(monkeypatch, tmp_path):
674+
"""Issue #442 experiment route C: callers/callees/impact reject --markdown
675+
and --limit, so passing them left the planner with a single scope and every
676+
deliberation plan was rejected before dispatch."""
677+
fake = tmp_path / "fake-graphtrail"
678+
fake.write_text(_FAKE_GRAPHTRAIL)
679+
fake.chmod(0o755)
680+
monkeypatch.setenv("GRAPHTRAIL_BIN", str(fake))
681+
graph_dir = tmp_path / ".graphtrail"
682+
graph_dir.mkdir()
683+
(graph_dir / "graphtrail.db").write_text("")
684+
685+
scopes = deliberation._candidate_graphtrail_scopes(tmp_path, "migrate the queue")
686+
687+
kinds = {scope.kind for scope in scopes}
688+
assert "graphtrail-context" in kinds
689+
assert {"graphtrail-callers", "graphtrail-callees", "graphtrail-impact"} <= kinds
690+
assert all(scope.grounded for scope in scopes)

0 commit comments

Comments
 (0)