"""Envelope tests for coord sync command.""" 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 TestCoordSyncEnvelope: def test_coord_sync_push_has_envelope(self) -> None: # Push with no remote configured — will fail at hub resolution, # but the no-records path (empty local state) exits before that. r = runner.invoke(None, ["coord", "sync", "push", "--owner", "gabriel", "--slug", "muse", "--hub", "https://localhost:1337", "--json"]) # exit_code may be non-zero if hub is unreachable, but the JSON # must still carry the envelope when records were gathered first. # Use the simpler no-records path: if no coordination records exist # the command exits 0 with an envelope. # We accept either 0 (no records) or non-zero (hub error). output = r.output.strip() if output.startswith("{"): _check(json.loads(output))