"""Envelope tests for attributes and auth commands.""" from __future__ import annotations from collections.abc import Mapping import json import pytest from tests.cli_test_helper import CliRunner runner = CliRunner() _FIELDS = ("muse_version", "schema", "timestamp", "warnings") def _check(d: "Mapping[str, object]") -> None: for f in _FIELDS: assert f in d, f"missing {f}" assert "schema_version" not in d class TestAttributesEnvelope: def test_list_has_envelope(self) -> None: r = runner.invoke(None, ["attributes", "list", "--json"]) assert r.exit_code == 0, r.output _check(json.loads(r.output)) def test_check_has_envelope(self) -> None: r = runner.invoke(None, ["attributes", "check", "README.md", "--json"]) assert r.exit_code == 0, r.output _check(json.loads(r.output)) def test_validate_has_envelope(self) -> None: r = runner.invoke(None, ["attributes", "validate", "--json"]) assert r.exit_code == 0, r.output _check(json.loads(r.output)) class TestAuthEnvelope: def test_whoami_has_envelope(self) -> None: r = runner.invoke(None, ["auth", "whoami", "--json"]) # May be logged in or not; either way JSON with envelope if r.exit_code == 0: _check(json.loads(r.output)) else: pytest.skip("no identity configured")