"""Envelope tests for clone 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 TestCloneEnvelope: def test_clone_already_exists_has_envelope(self) -> None: # Cloning into the current directory (which already has .muse/) triggers # the "already_exists" path immediately — no network call needed. r = runner.invoke(None, ["clone", "http://example.com/repo", ".", "--json"]) # exits with USER_ERROR but must emit a JSON envelope on the first line first_line = r.output.strip().splitlines()[0] d = json.loads(first_line) _check(d) assert d["status"] == "already_exists"