Skip to content

test(cli): add regression test for command/help sync, fix missing guardrails entry#863

Merged
muddlebee merged 2 commits intoTracer-Cloud:mainfrom
Davidson3556:test/cli-command-help-sync
Apr 28, 2026
Merged

test(cli): add regression test for command/help sync, fix missing guardrails entry#863
muddlebee merged 2 commits intoTracer-Cloud:mainfrom
Davidson3556:test/cli-command-help-sync

Conversation

@Davidson3556
Copy link
Copy Markdown
Contributor

Fixes #835

Describe the changes you have made in this PR -

Added tests/cli/test_command_help_sync.py — a regression test that compares the set of registered command names in _COMMANDS (app/cli/commands/__init__.py) against the set of keys in _HELP_COMMANDS (app/cli/layout.py). The test fails with a clear message naming the exact out-of-sync command if either list drifts from the other.

While writing the test, it immediately caught an existing drift: guardrails was registered in _COMMANDS but missing from _HELP_COMMANDS. This has been fixed in app/cli/layout.py.

Demo/Screenshot for feature changes and bug fixes -

Screenshot 2026-04-24 at 16 01 13

Code Understanding and AI Usage

Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?

  • No, I wrote all the code myself
  • Yes, I used AI assistance (continue below)

If you used AI assistance:

  • I have reviewed every single line of the AI-generated code
  • I can explain the purpose and logic of each function/component I added
  • I have tested edge cases and understand how the code handles them
  • I have modified the AI output to follow this project's coding standards and conventions

Explain your implementation approach:

The problem: _COMMANDS and _HELP_COMMANDS are two separate tuples that must stay in sync but have no enforced relationship — a developer can add a command to one and forget the other.

The fix is a set-comparison test. It extracts cmd.name from each click.Command in _COMMANDS (all commands use explicit name= in their decorator so .name is reliable), and the first element of each tuple in _HELP_COMMANDS. It then diffs the two sets and fails with a targeted message if anything is missing on either side. No formatting details are checked — only the names — so cosmetic changes to the help copy won't break it.

Alternative considered: checking the Click group's registered commands at runtime via cli.commands. Rejected because that requires booting the full CLI, while this test touches only the two data structures directly.


Checklist before requesting a review

  • I have added proper PR title and linked to the issue
  • I have performed a self-review of my code
  • I can explain the purpose of every function, class, and logic block I added
  • I understand why my changes work and have tested them thoroughly
  • I have considered potential edge cases and how my code handles them
  • If it is a core feature, I have added thorough tests
  • My code follows the project's style guidelines and conventions

Note: Please check Allow edits from maintainers if you would like us to assist in the PR.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 24, 2026

Greptile Summary

This PR adds a regression test (tests/cli/test_command_help_sync.py) that enforces bidirectional sync between _COMMANDS (the Click command registry) and _HELP_COMMANDS (the help-screen copy), and fixes the existing drift it immediately caught by adding the missing guardrails entry to _HELP_COMMANDS in app/cli/layout.py.

Confidence Score: 5/5

Safe to merge — changes are a one-line bug fix and a well-scoped regression test with no risk to existing behavior.

Only P2 findings remain (a minor defensive guard on cmd.name nullability). The fix is correct, the test logic is sound, and no production code paths are altered.

No files require special attention.

Important Files Changed

Filename Overview
app/cli/layout.py Added the missing guardrails entry to _HELP_COMMANDS — a one-line targeted fix that resolves the drift caught by the new regression test.
tests/cli/test_command_help_sync.py New regression test performing bidirectional set-diff between _COMMANDS and _HELP_COMMANDS; clean and self-contained, with one minor improvement possible around guarding None names.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[_COMMANDS\napp/cli/commands/__init__.py] -->|set of cmd.name| C{Set diff}
    B[_HELP_COMMANDS\napp/cli/layout.py] -->|set of name| C
    C -->|missing_from_help == ∅\nmissing_from_registry == ∅| D[✅ Test passes]
    C -->|any drift detected| E[❌ Assert fails\nnames the exact out-of-sync command]
Loading

Reviews (1): Last reviewed commit: "test(cli): add regression test for comma..." | Re-trigger Greptile

Comment thread tests/cli/test_command_help_sync.py
@Davidson3556
Copy link
Copy Markdown
Contributor Author

test_node_plan_actions_emits_retrieval_controls is failing because _InputStub is missing a model_copy attribute that node_plan_actions now expects — this is unrelated to my changes, which only touch tests/cli/test_command_help_sync.py and app/cli/layout.py. The failure reproduces on main independently of this PR.

@Davidson3556
Copy link
Copy Markdown
Contributor Author

Davidson3556 commented Apr 24, 2026

@rrajan94 @VaibhavUpreti kindly review

@Davidson3556
Copy link
Copy Markdown
Contributor Author

please kindly review @muddlebee

@muddlebee
Copy link
Copy Markdown
Collaborator

@Davidson3556 fix CI

@Davidson3556 Davidson3556 force-pushed the test/cli-command-help-sync branch from 3de1e10 to ebe51f2 Compare April 28, 2026 09:27
@Davidson3556
Copy link
Copy Markdown
Contributor Author

@muddlebee kindly review

@Davidson3556
Copy link
Copy Markdown
Contributor Author

@VaibhavUpreti @rrajan94 @muddlebee kindly review

Comment thread app/cli/layout.py
("remote", "Connect to remote agents and hosted service ops."),
("tests", "Browse and run inventoried tests from the terminal."),
("integrations", "Manage local integration credentials."),
("guardrails", "Manage sensitive information guardrail rules."),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for adding this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guardrails is already registered in _COMMANDS in app/cli/commands/init.py but was missing from _HELP_COMMANDS in app/cli/layout.py . this is exactly the drift the regression test was added to catch. The test itself surfaced this inconsistency, so fixing it is part of the acceptance criteria for this issue.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok if you say so @Davidson3556 ;)

@muddlebee muddlebee merged commit d75863e into Tracer-Cloud:main Apr 28, 2026
7 checks passed
@muddlebee
Copy link
Copy Markdown
Collaborator

nicely done @Davidson3556 🥳

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.

Add a regression test to keep CLI command registration in sync with help copy

2 participants