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
2 changes: 2 additions & 0 deletions app/cli/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
("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."),
("health", "Check integration and agent setup status."),
("doctor", "Run a full environment diagnostic."),
("update", "Check for a newer version and update if one is available."),
Expand All @@ -36,6 +37,7 @@
("opensre remote ops status", "Inspect hosted service status (Railway)"),
("opensre tests", "Browse and run inventoried tests"),
("opensre integrations list", "Show configured integrations"),
("opensre guardrails rules", "List configured 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.

why new layouts are added?

("opensre health", "Check integration and agent setup status"),
("opensre doctor", "Run a full environment diagnostic"),
("opensre update", "Update to the latest version"),
Expand Down
73 changes: 73 additions & 0 deletions tests/cli/test_layout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from __future__ import annotations

import click

from app.cli.__main__ import cli
from app.cli.layout import (
_HELP_COMMANDS,
_LANDING_COMMANDS,
_SHORT_OPTIONS,
RichGroup,
render_help,
render_landing,
)


def _normalized_output(output: str) -> str:
return " ".join(output.split())


def test_render_help_shows_root_commands(capsys) -> None:
render_help()
output = _normalized_output(capsys.readouterr().out)

assert "Usage: opensre [OPTIONS] COMMAND [ARGS]..." in output
assert "Commands:" in output
assert "Options:" in output

for label, description in _HELP_COMMANDS:
assert label in output
assert description in output

Comment on lines +28 to +31
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

output is not normalized here, so Rich line-wrapping can split long descriptions (e.g., the update help text) across newlines, making assert description in output fail depending on console width. Consider normalizing whitespace (like _normalized_output) before asserting, or otherwise making the assertions robust to wrapped output.

Copilot uses AI. Check for mistakes.
for label, description in _SHORT_OPTIONS:
assert label in output
assert description in output
Comment on lines +20 to +34
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Inconsistent output normalization across render tests

test_render_landing_shows_root_commands_and_header passes the captured output through _normalized_output() (collapsing all whitespace) before asserting, but test_render_help_shows_root_commands checks the raw output directly. With Rich's default 80-column non-TTY width, the help output currently fits without wrapping — but any future widening of labels or descriptions could silently break only this test while the landing test stays green. Consider applying _normalized_output consistently to both, or adding a comment noting why the raw form is safe here.

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.

@7vignesh is this solved?



def test_render_landing_shows_root_commands_and_header(capsys) -> None:
render_landing()
output = _normalized_output(capsys.readouterr().out)

assert (
"open-source SRE agent for automated incident investigation and root cause analysis"
in output
)
assert "Usage: opensre [OPTIONS] COMMAND [ARGS]..." in output
assert "Quick start:" in output
assert "Options:" in output

for label, description in _LANDING_COMMANDS:
assert label in output
assert description in output

for label, description in _SHORT_OPTIONS:
assert label in output
assert description in output


def test_help_command_names_match_layout_metadata() -> None:
assert tuple(cli.commands.keys()) == tuple(label for label, _description in _HELP_COMMANDS)


def test_rich_group_format_help_delegates_to_render_help(monkeypatch) -> None:
called = []

def fake_render_help() -> None:
called.append(True)

monkeypatch.setattr("app.cli.layout.render_help", fake_render_help)

group = RichGroup(name="opensre")
group.format_help(click.Context(group), click.HelpFormatter())

assert called == [True]
Loading