Skip to content

fix(flow): stable --key help so the CLI snapshot does not depend on HOME - #2572

Merged
abrichr merged 1 commit into
mainfrom
claude/fix-key-help-home
Nov 23, 2026
Merged

abrichr merged 1 commit into
mainfrom
claude/fix-key-help-home

Conversation

@abrichr

@abrichr abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member

Since #2561, openadapt-flow exceptions answer --key writes the expanded home directory into its help text each time the parser is built. packages/flow/tests/test_cli_surface.py formats the help first and only then replaces the home with <HOME>, so argparse wraps the line by the length of whatever HOME is set at that moment.

Several Flow tests point HOME at a long temporary directory (test_txplan, test_hooks_e2e, test_sealed_at_rest). So the snapshot passes or fails depending on test order and on the machine. On CI it fails (flow core unit, e.g. on #2540). Regenerating the snapshot can't fix this: it just records one machine's HOME.

Change

  • The --key help is now a fixed string, (default: ~/.openadapt/approver/desktop-approver.pem), the same way --key-dir shows ~/.openadapt/jit.
  • The default value itself is unchanged: it is still _key_default(), computed when the command runs, so fix(flow): compute exceptions --key default from Path.home() at use time #2561's fix stands.
  • packages/flow/tests/fixtures/cli_surface.json is regenerated (OPENADAPT_WRITE_CLI_SURFACE=1 pytest tests/test_cli_surface.py, Python 3.12). Only that help string changes.
  • New test, test_help_does_not_depend_on_home: it builds the parser under a long temporary HOME and asserts that every scrubbed help text and every argument is unchanged.

Checks

  • tests/test_cli_surface.py: 5 passed, run once during regeneration.
  • ruff check and ruff format --check pass on the changed files.
  • Machine load was very high, so I didn't run the new test against the pre-fix code.
  • No protected paths are touched.

Since #2561, `openadapt-flow exceptions answer --key` put the expanded home
directory into its help text each time the parser is built. The CLI
snapshot test formats help first and replaces the home with <HOME> after,
so argparse wrapped the line by the length of whatever HOME was current.
Flow tests that point HOME at a long temporary directory (txplan, hooks,
sealed-at-rest) made the snapshot pass or fail by test order on CI.

The help now says `~/.openadapt/approver/desktop-approver.pem`, like
`--key-dir` already does. The default itself is still computed when the
command runs (`_key_default()`), so #2561's behaviour is unchanged. The
snapshot is regenerated (only that help string changes), and a new test
builds the parser under a long HOME and asserts no scrubbed help or
argument changes.
@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude
Reviewed-Head: a735007

A fresh Claude reviewer looked at the diff and the test, not at the author's conclusions.

  • Diagnosis confirmed. The snapshot test wraps help text with argparse before it scrubs <HOME> (test_cli_surface.py:121). The old --key help put _key_default() into the text when the parser was built, so the line wrap depended on how long HOME was.
  • No other help text depends on the machine. No other flow help string embeds a path that varies by machine, and none uses %(default) or ArgumentDefaultsHelpFormatter.
  • Runtime unchanged. It is still load_encrypted_key(args.key or _key_default()) (cli.py:352).
  • Snapshot diff is minimal. Python 3.12 and 100 columns are unchanged. Only one help entry and one argument entry change, both for exceptions answer --key.
  • The new test catches the bug. With only the cli.py fix reverted, test_help_does_not_depend_on_home fails with "--help text depends on HOME for ['openadapt-flow exceptions answer']". With the fix in place it passes, under both the normal HOME and a 90-character HOME. State is restored through monkeypatch.
  • Lint. ruff check and ruff format --check pass.
  • Nits, not blocking. The help repeats _key_default()'s path as a literal string. The new test covers HOME changes only.

@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: a735007

Author declaration: Claude authored this PR. It touches no path in .github/agent-safety-manifest.json.

@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: a735007

Head confirmed open and unchanged versus this SHA. Three files: exceptions/cli.py, the cli_surface.json snapshot, and test_cli_surface.py. No types, package version bumps, or protected paths.

This is the right fix for the latent test_cli_surface failure that #2561 left on main and on #2540. --key help no longer embeds _key_default() (which expands Path.home()) at parser-build time, so argparse wrapping no longer depends on HOME. The help string is the same style as --key-dir (~/.openadapt/...). Runtime behaviour is unchanged: cmd_answer still does args.key or _key_default(), and _key_default() is still computed at use time.

The snapshot change is isolated to that one help string (including the expected wrap at desktop- now that the path is short and stable). test_help_does_not_depend_on_home builds the surface under a long HOME and requires scrubbed tree and help to match the usual HOME. That would fail if anyone put Path.home() back into help text.

I am approving at this head. I am not merging.

@abrichr
abrichr merged commit 8df7f2d into main Nov 23, 2026
55 checks passed
@abrichr
abrichr deleted the claude/fix-key-help-home branch November 23, 2026 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant