From 806a942eb17e5cbf21d8b5159ea1ef94537e9e68 Mon Sep 17 00:00:00 2001 From: Chandra Irugalbandara Date: Tue, 10 Nov 2026 19:09:30 +0530 Subject: [PATCH 1/2] salli-server runs with Typer 0.29: Typer builds the --json flag from a declaration with_json_option called TyperOption(...) directly, and Typer 0.29 made type_descriptor a required argument of it, so every command failed with a TypeError wherever 0.29 was installed (a pip install of the wheel today; salli-hosted's test job). The lock's 0.26.7 hid it. _json_flag now declares the option with typer.Option on a throwaway command and takes the option Typer builds, so it depends on no constructor's arguments: still eager, not exposed, the same help text and _enable_json itself as its callback. Every help page is byte-identical to main's under 0.26.7, and the CLI tests pass with Typer 0.26.7, 0.26.8, 0.27.0, 0.27.3, 0.28.0 and 0.29.0. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 +++ src/salli/interfaces/cli/support.py | 39 +++++++++++++++++++++-------- tests/unit/cli/test_server_cli.py | 14 +++++++++++ 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 754527a8..33839532 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Fixed + +- **`salli-server` runs with Typer 0.29.** Where Typer 0.29 was installed, as a pip install of the package gets it, every command failed with a `TypeError`: the `--json` flag was built by calling Typer's option class, whose arguments 0.29 changed. Typer now builds the flag from a declaration, as it builds every other option; tested with Typer 0.26.7 to 0.29.0. + ## 0.6.2 — 2026-11-10 The console's Cash flow by month draws the twelve months Home averages over, and the console is leaner on a phone. diff --git a/src/salli/interfaces/cli/support.py b/src/salli/interfaces/cli/support.py index 00eb11c3..d66e4ad6 100644 --- a/src/salli/interfaces/cli/support.py +++ b/src/salli/interfaces/cli/support.py @@ -23,7 +23,6 @@ import typer from rich.console import Console -from typer.core import TyperOption console = Console() @@ -103,21 +102,39 @@ def leaf_commands(group: Any, path: tuple[str, ...] = ()) -> Iterator[tuple[tupl yield path, group +def _json_flag() -> Any: + """A new --json option for one command. Typer builds it from a declaration, + as it builds every other option, so nothing here depends on the arguments + of Typer's option class (0.29 added a required one to TyperOption).""" + + def declare( + json: bool | None = typer.Option( + None, + "--json", + is_eager=True, + expose_value=False, + # typer.Option shows both by default; --json shows neither. + show_default=False, + show_envvar=False, + help="Print the result as JSON on stdout (messages go to stderr).", + ), + ) -> None: + """Never run: only its option is used.""" + + probe = typer.Typer(add_completion=False) + probe.command()(declare) + [flag] = typer.main.get_command(probe).params + # Set here rather than passed to typer.Option, which would wrap it. + flag.callback = _enable_json + return flag + + def with_json_option(root: Any) -> Any: """Give every non-interactive command a --json flag.""" for path, command in leaf_commands(root): if path in INTERACTIVE_COMMANDS or any(p.name == "json" for p in command.params): continue - command.params.append( - TyperOption( - param_decls=["--json"], - is_flag=True, - expose_value=False, - is_eager=True, - callback=_enable_json, - help="Print the result as JSON on stdout (messages go to stderr).", - ) - ) + command.params.append(_json_flag()) return root diff --git a/tests/unit/cli/test_server_cli.py b/tests/unit/cli/test_server_cli.py index 8d47849c..8cb72384 100644 --- a/tests/unit/cli/test_server_cli.py +++ b/tests/unit/cli/test_server_cli.py @@ -93,6 +93,20 @@ def test_every_command_takes_json(): ), path +def test_the_json_flag_is_eager_unexposed_and_in_the_help(monkeypatch, capsys): + # Typer builds it from a declaration (support._json_flag): constructing + # TyperOption directly broke with typer 0.29, which added an argument. + for path, command in leaf_commands(main.cli()): + [flag] = [p for p in command.params if p.name == "json"] + assert (flag.opts, flag.secondary_opts) == (["--json"], []), path + assert flag.is_flag and flag.is_eager and not flag.expose_value, path + assert flag.callback is support._enable_json, path + assert flag.help == "Print the result as JSON on stdout (messages go to stderr).", path + helped = _run(monkeypatch, capsys, "db", "current", "--help") + assert helped.exit_code == 0, helped.output + assert "--json" in helped.output and "Print the result as JSON" in helped.output + + def test_the_names_extensions_import_stay_put(): # A deployment's own commands and tests import these; renaming one breaks it. for name in ("console", "emit", "json_mode", "require_user", "services", "leaf_commands"): From 166580501aa940f444b19d3535fc8718bfbbe576 Mon Sep 17 00:00:00 2001 From: Chandra Irugalbandara Date: Tue, 10 Nov 2026 19:28:30 +0530 Subject: [PATCH 2/2] The --json help test reads the help without the colours Typer forces in CI Typer forces a terminal where GITHUB_ACTIONS (or FORCE_COLOR) is set, and the highlighter splits "--json" with escape codes, so the assertion failed in CI and passed locally. Strip the SGR codes before looking for it. Co-Authored-By: Claude Opus 5.5 --- tests/unit/cli/test_server_cli.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/unit/cli/test_server_cli.py b/tests/unit/cli/test_server_cli.py index 8cb72384..9ce2fbaa 100644 --- a/tests/unit/cli/test_server_cli.py +++ b/tests/unit/cli/test_server_cli.py @@ -3,6 +3,7 @@ from __future__ import annotations import json +import re import sys import tomllib from pathlib import Path @@ -104,7 +105,9 @@ def test_the_json_flag_is_eager_unexposed_and_in_the_help(monkeypatch, capsys): assert flag.help == "Print the result as JSON on stdout (messages go to stderr).", path helped = _run(monkeypatch, capsys, "db", "current", "--help") assert helped.exit_code == 0, helped.output - assert "--json" in helped.output and "Print the result as JSON" in helped.output + # Typer colours the help where GITHUB_ACTIONS or FORCE_COLOR is set. + shown = re.sub(r"\x1b\[[0-9;]*m", "", helped.output) + assert "--json" in shown and "Print the result as JSON" in shown def test_the_names_extensions_import_stay_put():