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
5 changes: 3 additions & 2 deletions src/loopzero/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ def cmd_check(args: argparse.Namespace) -> int:
raise config_mod.ConfigError("checks.commands must list at least one command to run checks")
try:
report = sandbox.run_checks(config, wt, progress=lambda command: print(
f"running: {command}", flush=True),
f"running: {github.redact_credentials(command)}", flush=True),
status=lambda message: print(message, flush=True),
checkpoint=lambda partial: _save_report(wt, partial),
workflow=args.config or f"origin/{config.base_branch}:workflow.toml")
Expand All @@ -659,7 +659,8 @@ def cmd_check(args: argparse.Namespace) -> int:
shortened = False
for result in report.results:
if result.exit_code != 0:
print(f"--- {result.command} (exit {result.exit_code}) ---", file=sys.stderr)
heading = github.redact_credentials(result.command)
print(f"--- {heading} (exit {result.exit_code}) ---", file=sys.stderr)
tail = _proc.tail(result.tail)
preview = _check_failure_preview(tail)
shortened |= preview != tail
Expand Down
8 changes: 4 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,18 +688,18 @@ def run_checks(cfg, path, *, progress, status, checkpoint, workflow):


@pytest.mark.parametrize("command,exit_code,tail", [
("echo no; exit 3", 3, "no\n"),
("echo no; exit 3 # https://fake-heading-secret@example.invalid", 3, "no\n"),
("seq 1 50; exit 1", 1, "".join(f"{i}\n" for i in range(11, 51)))])
def test_check_failure_reports_verdict_and_capped_tail(wt, capsys, command, exit_code, tail):
(wt / "workflow.toml").write_text(WORKFLOW.replace(
'["echo ok", "test -f README.md"]', json.dumps([command, "test -f README.md"])))
code, out, err = run(capsys, "--config", str(wt / "workflow.toml"), "check")
assert code == 1 and out.endswith("FAIL\n")
assert out.startswith("checks are unpinned because --config was provided\n")
assert sum(line.startswith(("stage 1/2: exit ", "exit "))
for line in out.splitlines()) == 1
heading = command.replace("fake-heading-secret", "[REDACTED]")
assert out.count(f"running: {heading}\n") == out.count("stage 1/2: exit ") == 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: The updated test no longer catches a stray bare exit N line

The old assertion counted output lines starting with either stage 1/2: exit or exit and required exactly one. The new one uses out.count("stage 1/2: exit "), so an extra bare exit N line on stdout would now go unnoticed. This is minor. To keep that coverage without adding lines, chain the old line-prefix count into the same equality.

assert f"stage 1/2: exit {exit_code} (" in out and "README.md" not in out
assert err == f"--- {command} (exit {exit_code}) ---\n{tail}"
assert err == f"--- {heading} (exit {exit_code}) ---\n{tail}"
report = json.loads((wt / ".loopzero/checks.json").read_text())
assert [result["command"] for result in report["results"]] == [command]

Expand Down
Loading