-
Notifications
You must be signed in to change notification settings - Fork 97
fix(sec-core): complete skill-ledger status help #2707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jfeng18
wants to merge
1
commit into
main
Choose a base branch
from
fix/sec-core/ledger-help-statuses
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+72
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/agent-sec-core/tests/unit-test/skill_ledger/test_cli_help.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| """Help-text contract tests for the ``skill-ledger`` command group.""" | ||
|
|
||
| import json | ||
| import re | ||
| from pathlib import Path | ||
|
|
||
| from agent_sec_cli.security_middleware.backends.skill_ledger import ( | ||
| _VERDICT_SEVERITY, | ||
| ) | ||
| from agent_sec_cli.skill_ledger.cli import app | ||
| from typer.testing import CliRunner | ||
|
|
||
| # rich emits ANSI color codes when the environment forces color on (e.g. | ||
| # GITHUB_ACTIONS or FORCE_COLOR), so strip them before matching on layout. | ||
| _ANSI_ESCAPE_RE = re.compile(r"\x1b\[[0-9;]*m") | ||
|
|
||
|
|
||
| def _plain_lines(output: str) -> list[str]: | ||
| """Return help output as ANSI-free lines with indentation stripped.""" | ||
| return [_ANSI_ESCAPE_RE.sub("", line).strip() for line in output.splitlines()] | ||
|
|
||
|
|
||
| def _has_status_line(output: str, status: str) -> bool: | ||
| """True if any line starts with ``status`` followed by a word boundary. | ||
|
|
||
| Rich renders help differently per environment (ANSI codes, 2- vs | ||
| 3-space indent, width padding), so the match is layout-independent. | ||
| """ | ||
| return any(re.match(rf"^{status}\b", line) for line in _plain_lines(output)) | ||
|
|
||
|
|
||
| def test_app_help_lists_every_verdict_status() -> None: | ||
| result = CliRunner().invoke(app, ["--help"]) | ||
|
|
||
| assert result.exit_code == 0 | ||
| for status in _VERDICT_SEVERITY: | ||
| assert _has_status_line( | ||
| result.output, status | ||
| ), f"status {status!r} missing from skill-ledger --help" | ||
|
|
||
|
|
||
| def test_check_help_lists_error_status() -> None: | ||
| result = CliRunner().invoke(app, ["check", "--help"]) | ||
|
|
||
| assert result.exit_code == 0 | ||
| assert _has_status_line( | ||
| result.output, "error" | ||
| ), "check --help must document the error status" | ||
| # error is produced by both single-check failures and batch entries; | ||
| # the old "(--all path only)" qualifier was inaccurate. | ||
| assert "(--all path only)" not in result.output | ||
| # check never returns unmanaged (only show does, via manageability checks). | ||
| assert not _has_status_line(result.output, "unmanaged") | ||
|
|
||
|
|
||
| def test_check_missing_dir_prints_error_status_json(tmp_path: Path) -> None: | ||
|
jfeng18 marked this conversation as resolved.
|
||
| result = CliRunner().invoke(app, ["check", str(tmp_path / "missing")]) | ||
|
|
||
| assert result.exit_code == 1 | ||
| payload = json.loads(result.output) | ||
| # Assert only the error envelope contract; the message text is free to | ||
| # evolve as new failure types are added. | ||
| assert payload["status"] == "error" | ||
| assert payload["error"] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.