Skip to content
Merged
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
10 changes: 8 additions & 2 deletions agentdescent/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6913,8 +6913,14 @@ def _register_commands(mount: "_CommandMount", *, with_lab: bool) -> None:
if with_lab:
lab = sub.add_parser("lab", help="every other verb, grouped; "
"`lab <verb>` runs it unchanged")
_register_commands(_CommandMount(lab.add_subparsers(dest="lab_cmd", required=True),
listed=True), with_lab=False)
lab_sub = lab.add_subparsers(dest="lab_cmd", required=True)
_register_commands(_CommandMount(lab_sub, listed=True), with_lab=False)
# Same #420 contract as the top-level usage line: `run` is the
# detached worker, not a user verb, so it must not appear in the
# `{...}` metavar. Help already omits its line; choose-from already
# strips it via _visible_choices. The verb still parses (#1171).
lab_sub.metavar = "{" + ",".join(
n for n in lab_sub.choices if n not in _INTERNAL_COMMANDS) + "}"

s = sub.add_parser("mcp", help="serve the tools over MCP (stdio by default; needs agentdescent[mcp])")
s.add_argument("--transport", choices=("stdio", "streamable-http"), default="stdio",
Expand Down
4 changes: 4 additions & 0 deletions changelog.d/1171-lab-hides-internal-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fixed
`agentdescent lab --help` and the usage line on a `lab` argparse error no
longer list the internal `run` worker in the `{...}` metavar; the verb stays
reachable as `lab run` (#1171).
46 changes: 46 additions & 0 deletions tests/test_cli_help_hides_internal_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,49 @@ def test_nonsense_verb_has_no_guess_and_hides_run(capsys):
assert "invalid choice: 'no-such-verb'" in err
assert "did you mean" not in err
assert "'run'" not in err


def _lab_parser():
return _subparsers_action().choices["lab"]


def test_lab_help_and_usage_do_not_list_run():
"""The lab mount must honour the same #420 contract as the top level (#1171)."""
lab = _lab_parser()
for text in (lab.format_help(), lab.format_usage()):
verbs = _verbs_in_braces(text)
assert "run" not in verbs
assert "evolve" in verbs
assert "algorithms" in verbs


def test_lab_every_listed_verb_has_a_help_line():
text = _lab_parser().format_help()
for verb in _verbs_in_braces(text):
assert re.search(rf"^ {re.escape(verb)}\s+\S", text, re.M), verb


def test_lab_unknown_verb_error_does_not_list_run(capsys):
out, err = _unknown_verb(capsys, ["lab", "xyz"])
assert out == ""
assert "run" not in _verbs_in_braces(err)
assert "'run'" not in err


def test_lab_unknown_verb_json_hides_run(capsys):
import json

out, err = _unknown_verb(capsys, ["--json", "lab", "xyz"])
assert err == ""
payload = json.loads(out)
assert payload["ok"] is False
assert "'run'" not in payload["error"]
assert "'run'" not in payload["usage"]
assert "run" not in _verbs_in_braces(payload["usage"])


def test_lab_run_still_parses():
a = cli.build_parser().parse_args(
["lab", "run", "--run-dir", "/tmp/x", "--budget", "1.5"])
assert a.fn is cli.cmd_run
assert a.run_dir == "/tmp/x" and a.budget == 1.5
Loading