From 594b1770abd37428ca5c6352b47206a04d01c89f Mon Sep 17 00:00:00 2001 From: Danyang Chen Date: Fri, 20 Nov 2026 06:26:40 +0800 Subject: [PATCH] fix(cli): hide the internal run worker from lab usage Closes #1171 The lab subparsers left argparse's default metavar, so `lab --help` and lab argparse errors listed `run` in the braces after #1169. Set the metavar from the public choices, the same #420 contract as the top-level usage line. `lab run` still parses. --- agentdescent/cli.py | 10 ++++- changelog.d/1171-lab-hides-internal-run.md | 4 ++ tests/test_cli_help_hides_internal_run.py | 46 ++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 changelog.d/1171-lab-hides-internal-run.md diff --git a/agentdescent/cli.py b/agentdescent/cli.py index fb31fa64..45367bc6 100644 --- a/agentdescent/cli.py +++ b/agentdescent/cli.py @@ -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 ` 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", diff --git a/changelog.d/1171-lab-hides-internal-run.md b/changelog.d/1171-lab-hides-internal-run.md new file mode 100644 index 00000000..eb6f0c91 --- /dev/null +++ b/changelog.d/1171-lab-hides-internal-run.md @@ -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). diff --git a/tests/test_cli_help_hides_internal_run.py b/tests/test_cli_help_hides_internal_run.py index b59d356c..676bb384 100644 --- a/tests/test_cli_help_hides_internal_run.py +++ b/tests/test_cli_help_hides_internal_run.py @@ -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