fix(invariant): use json format in persistence helper list calls

The helper used the CLI default Rich table renderer and substring-checked
for the invariant text in the captured output. With CliRunner's narrow
default console width the Rich table soft-wraps "Must validate inputs"
across two visual rows, so the substring check always failed even though
the invariant was correctly persisted and retrieved from the database.

Pass --format json on the list invocations: the JSON serialiser emits the
text verbatim so the substring assertion now reflects persistence rather
than column-width formatting. Verified locally by running all three
helper subcommands against a fresh SQLite DB — all three now print their
ok markers.

ISSUES CLOSED: #8573
This commit is contained in:
2026-06-13 20:53:47 -04:00
committed by Forgejo
parent 13e23a6a8a
commit c1dca18654
+9 -3
View File
@@ -52,11 +52,15 @@ def add_then_list_project() -> None:
print(f"FAIL-ADD: exit={add_result.exit_code} out={add_result.output}")
sys.exit(1)
# Invocation 2: list (fresh service — simulates new process)
# Invocation 2: list (fresh service — simulates new process).
# Use --format json so the invariant text is emitted verbatim instead of
# being soft-wrapped by the default Rich table renderer (which breaks
# substring matching when the text spans multiple visual rows).
svc2 = InvariantService()
with patch("cleveragents.cli.commands.invariant._get_service", return_value=svc2):
list_result = runner.invoke(
invariant_app, ["list", "--project", "local/test-proj"]
invariant_app,
["list", "--project", "local/test-proj", "--format", "json"],
)
# The list output should contain the invariant — if it doesn't, bug exists
@@ -84,7 +88,9 @@ def add_then_list_global() -> None:
svc2 = InvariantService()
with patch("cleveragents.cli.commands.invariant._get_service", return_value=svc2):
list_result = runner.invoke(invariant_app, ["list", "--global"])
list_result = runner.invoke(
invariant_app, ["list", "--global", "--format", "json"]
)
if "Never expose credentials" in list_result.output:
print("invariant-persist-global-ok")