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
16 changes: 14 additions & 2 deletions src/cfg/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,21 @@ def main(argv: list[str] | None = None) -> int:
from cfg import update

if args.snooze is not None:
_emit(update.snooze(args.snooze), json_mode=args.json)
result = update.snooze(args.snooze)
if args.json:
_emit(result, json_mode=True)
else:
print(f"Update reminders snoozed for {result['days']} days.")
return EXIT_OK
_emit(update.check(force=True).to_json(), json_mode=args.json)
status = update.check(force=True)
if args.json:
_emit(status.to_json(), json_mode=True)
elif status.disabled:
print(f"Update check is disabled (CFGIT_NO_UPDATE_CHECK is set). Installed: {status.installed}.")
elif status.message:
print(status.message)
else:
print(f"cfgit {status.installed} is up to date.")
return EXIT_OK
try:
project = load_config(args.config_file)
Expand Down
43 changes: 43 additions & 0 deletions tests/test_update_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,46 @@ def test_cli_nudge_gating(monkeypatch, capsys, cmd, json_mode, isatty, expect_nu
captured = capsys.readouterr()
assert ("available" in captured.err) is expect_nudge
assert captured.out == "" # the nudge must NEVER touch stdout, in any case


# --- `cfg check-update` renders human prose, not a JSON dump (regression) --------------------


def test_check_update_human_prints_sentence_not_json(monkeypatch, capsys):
"""Up-to-date `cfg check-update` must print a readable line in human mode, not raw JSON."""
import types

monkeypatch.setattr(
update, "check",
lambda *a, **k: types.SimpleNamespace(
installed="0.4.0", disabled=False, message=None, to_json=lambda: {}
),
)
from cfg.cli.main import main

rc = main(["check-update"]) # no --json; capsys is not a TTY → auto picks JSON... so force human
_ = capsys.readouterr()
# explicit human mode via env is the real contract:
monkeypatch.setenv("CFG_OUTPUT", "human")
main(["check-update"])
out = capsys.readouterr().out
assert rc == 0
assert "up to date" in out
assert not out.strip().startswith("{") # never a JSON dump


def test_check_update_json_is_structured(monkeypatch, capsys):
import types

monkeypatch.setattr(
update, "check",
lambda *a, **k: types.SimpleNamespace(
installed="0.4.0", disabled=False, message=None,
to_json=lambda: {"installed": "0.4.0", "update_available": False},
),
)
from cfg.cli.main import main

main(["--json", "check-update"])
out = capsys.readouterr().out
assert '"installed"' in out and out.strip().startswith("{")
Loading