feat: unify structured error output

This commit is contained in:
jackwener
2026-03-10 21:18:38 +08:00
parent 9b7bdf3b06
commit 4c2c02efd5
3 changed files with 46 additions and 0 deletions

View File

@@ -55,6 +55,22 @@ def test_cli_commands_wrap_client_creation_errors(monkeypatch, args) -> None:
assert type(result.exception).__name__ == "SystemExit"
def test_cli_user_error_yaml(monkeypatch) -> None:
monkeypatch.setenv("OUTPUT", "auto")
monkeypatch.setattr(
"twitter_cli.cli._get_client",
lambda config=None: (_ for _ in ()).throw(RuntimeError("User not found")),
)
runner = CliRunner()
result = runner.invoke(cli, ["user", "alice", "--yaml"])
assert result.exit_code == 1
payload = yaml.safe_load(result.output)
assert payload["ok"] is False
assert payload["error"]["code"] == "api_error"
def test_cli_tweet_accepts_shared_url_with_query(monkeypatch) -> None:
class FakeClient:
def fetch_tweet_detail(self, tweet_id: str, max_count: int):