diff --git a/packages/flow/openadapt_flow/exceptions/cli.py b/packages/flow/openadapt_flow/exceptions/cli.py index 9da23797cb..544fe3eb38 100644 --- a/packages/flow/openadapt_flow/exceptions/cli.py +++ b/packages/flow/openadapt_flow/exceptions/cli.py @@ -131,8 +131,13 @@ def register(sub: argparse._SubParsersAction) -> None: metavar="CHOICE", choices=["continue", "skip", "decline", "done_by_person", "abort"], ) + # Fixed text, not the expanded home: help must not change with HOME (the + # CLI snapshot test and anyone diffing --help). The default itself is + # still computed when the command runs (_key_default()). a.add_argument( - "--key", help=f"the encrypted approver key (default: {_key_default()})" + "--key", + help="the encrypted approver key " + "(default: ~/.openadapt/approver/desktop-approver.pem)", ) a.add_argument("--json", action="store_true", help="print JSON") _roster(a) diff --git a/packages/flow/tests/fixtures/cli_surface.json b/packages/flow/tests/fixtures/cli_surface.json index b8683ed00f..0f24997a3d 100644 --- a/packages/flow/tests/fixtures/cli_surface.json +++ b/packages/flow/tests/fixtures/cli_surface.json @@ -61,7 +61,7 @@ "openadapt-flow emit-skill": "usage: openadapt-flow emit-skill [-h] --out OUT bundle\n\npositional arguments:\n bundle Workflow bundle directory\n\noptions:\n -h, --help show this help message and exit\n --out OUT Parent directory for the skill folder\n\nAlso available as: openadapt-flow workflow emit-skill\n", "openadapt-flow encrypt": "usage: openadapt-flow encrypt [-h] -o OUT source\n\npositional arguments:\n source Existing workflow bundle directory\n\noptions:\n -h, --help show this help message and exit\n -o OUT, --out OUT New destination directory (must not already exist)\n", "openadapt-flow exceptions": "usage: openadapt-flow exceptions [-h] {serve,watch,list,answer} ...\n\npositional arguments:\n {serve,watch,list,answer}\n serve Serve the raise_exception MCP tool over stdio\n watch Watch the agent's Chromium, raise cards without the agent, and block its\n saves while a card is open\n list Show cards waiting for a person\n answer Answer a card, signed with your approver key\n\noptions:\n -h, --help show this help message and exit\n\nAlso available as: openadapt-flow approve exceptions\n", - "openadapt-flow exceptions answer": "usage: openadapt-flow exceptions answer [-h] [--key KEY] [--json] [--key-dir KEY_DIR]\n [--approver-root APPROVER_ROOT] [--registry REGISTRY]\n CARD_ID CHOICE\n\npositional arguments:\n CARD_ID\n CHOICE\n\noptions:\n -h, --help show this help message and exit\n --key KEY the encrypted approver key (default:\n /.openadapt/approver/desktop-approver.pem)\n --json print JSON\n --key-dir KEY_DIR the approver roster's folder (default: ~/.openadapt/jit)\n --approver-root APPROVER_ROOT\n the roster's root public key (default: OPENADAPT_APPROVER_ROOT)\n --registry REGISTRY the exceptions folder (default: $OPENADAPT_HOME/exceptions)\n\nAlso available as: openadapt-flow approve exceptions answer\n", + "openadapt-flow exceptions answer": "usage: openadapt-flow exceptions answer [-h] [--key KEY] [--json] [--key-dir KEY_DIR]\n [--approver-root APPROVER_ROOT] [--registry REGISTRY]\n CARD_ID CHOICE\n\npositional arguments:\n CARD_ID\n CHOICE\n\noptions:\n -h, --help show this help message and exit\n --key KEY the encrypted approver key (default: ~/.openadapt/approver/desktop-\n approver.pem)\n --json print JSON\n --key-dir KEY_DIR the approver roster's folder (default: ~/.openadapt/jit)\n --approver-root APPROVER_ROOT\n the roster's root public key (default: OPENADAPT_APPROVER_ROOT)\n --registry REGISTRY the exceptions folder (default: $OPENADAPT_HOME/exceptions)\n\nAlso available as: openadapt-flow approve exceptions answer\n", "openadapt-flow exceptions list": "usage: openadapt-flow exceptions list [-h] [--run-ref RUN_REF] [--json] [--registry REGISTRY]\n\noptions:\n -h, --help show this help message and exit\n --run-ref RUN_REF only this run's cards\n --json print JSON\n --registry REGISTRY the exceptions folder (default: $OPENADAPT_HOME/exceptions)\n\nAlso available as: openadapt-flow approve exceptions list\n", "openadapt-flow exceptions serve": "usage: openadapt-flow exceptions serve [-h] [--run-ref RUN_REF] [--task-id TASK_ID]\n [--deadline-s DEADLINE_S] [--key-dir KEY_DIR]\n [--approver-root APPROVER_ROOT] [--registry REGISTRY]\n\noptions:\n -h, --help show this help message and exit\n --run-ref RUN_REF this run's folder name (default: a new one)\n --task-id TASK_ID the task the cards belong to\n --deadline-s DEADLINE_S\n how long a card waits for a person (default 900)\n --key-dir KEY_DIR the approver roster's folder (default: ~/.openadapt/jit)\n --approver-root APPROVER_ROOT\n the roster's root public key (default: OPENADAPT_APPROVER_ROOT)\n --registry REGISTRY the exceptions folder (default: $OPENADAPT_HOME/exceptions)\n\nAlso available as: openadapt-flow approve exceptions serve\n", "openadapt-flow exceptions watch": "usage: openadapt-flow exceptions watch [-h] --cdp CDP --config CONFIG [--page-url PAGE_URL]\n [--run-dir RUN_DIR] [--run-ref RUN_REF] [--task-id TASK_ID]\n [--deadline-s DEADLINE_S] [--stall-s STALL_S]\n [--poll-s POLL_S] [--max-s MAX_S] [--key-dir KEY_DIR]\n [--approver-root APPROVER_ROOT] [--registry REGISTRY]\n\noptions:\n -h, --help show this help message and exit\n --cdp CDP the agent's DevTools endpoint (start the watch after the guard has\n attached to it)\n --config CONFIG the guard's guard.yaml: the app's origin and its not_saves\n --page-url PAGE_URL watch the tab whose URL starts with this\n --run-dir RUN_DIR write exceptions_watch.jsonl here (the guard's --out)\n --run-ref RUN_REF this run's folder name in the registry (default: --run-dir's name, else a\n new one)\n --task-id TASK_ID the task the cards belong to\n --deadline-s DEADLINE_S\n default 900\n --stall-s STALL_S raise timeout_or_stall after this long with no request and no screen\n change (default: off)\n --poll-s POLL_S look every N seconds\n --max-s MAX_S stop after N seconds\n --key-dir KEY_DIR the approver roster's folder (default: ~/.openadapt/jit)\n --approver-root APPROVER_ROOT\n the roster's root public key (default: OPENADAPT_APPROVER_ROOT)\n --registry REGISTRY the exceptions folder (default: $OPENADAPT_HOME/exceptions)\n\nAlso available as: openadapt-flow approve exceptions watch\n", @@ -5885,7 +5885,7 @@ "choices": null, "default": null, "dest": "key", - "help": "the encrypted approver key (default: /.openadapt/approver/desktop-approver.pem)", + "help": "the encrypted approver key (default: ~/.openadapt/approver/desktop-approver.pem)", "metavar": null, "nargs": null, "options": [ diff --git a/packages/flow/tests/test_cli_surface.py b/packages/flow/tests/test_cli_surface.py index 2a8c76bb14..10c4c76c43 100644 --- a/packages/flow/tests/test_cli_surface.py +++ b/packages/flow/tests/test_cli_surface.py @@ -204,3 +204,22 @@ def test_walker_sees_nested_commands_and_aliases() -> None: assert deep["options"] == ["--n"] and deep["choices"] == ["1", "2"] assert deep["type"] == "int" assert tree["x"]["arguments"][-1]["default"] == 3 + + +def test_help_does_not_depend_on_home( + monkeypatch: pytest.MonkeyPatch, tmp_path: Path +) -> None: + """A long HOME (as other tests set) must not change any scrubbed help. + + Help that embeds the expanded home wraps by the home's length before the + scrub replaces it, so the snapshot would pass or fail by where it ran. + """ + usual = _current(monkeypatch) + long_home = tmp_path / ("h" * 80) / "home" + long_home.mkdir(parents=True) + monkeypatch.setenv("HOME", str(long_home)) + assert str(Path.home()) == str(long_home) + moved = _current(monkeypatch) + assert moved["tree"] == usual["tree"] + changed = [p for p in sorted(usual["help"]) if usual["help"][p] != moved["help"][p]] + assert changed == [], f"--help text depends on HOME for {changed}"