gabriel / muse public

test_fetch_envelope.py file-level

at sha256:8 · View file ↗ · Intel ↗

History
1 files
1 commits
0 hotspots
0 🧊 dead
0 💥 blast risk
sha256:4 Merge branch 'dev' into main · gabriel · Jun 17, 2026
1 """Envelope tests for fetch command."""
2 from __future__ import annotations
3 from collections.abc import Mapping
4 import argparse
5 import json
6 import pytest
7 from tests.cli_test_helper import CliRunner
8
9 runner = CliRunner()
10
11 _FIELDS = ("muse_version", "schema", "timestamp", "warnings")
12
13
14 def _check(d: Mapping[str, object]) -> None:
15 for f in _FIELDS:
16 assert f in d, f"missing {f}"
17 assert "schema_version" not in d
18
19
20 class TestFetchEnvelope:
21 def test_fetch_no_remote_has_envelope(self) -> None:
22 # fetch with an unconfigured remote exits non-zero but still emits JSON envelope
23 r = runner.invoke(None, ["fetch", "nonexistent_remote_xyz", "--json"])
24 assert r.exit_code != 0
25 # runner captures stdout + stderr; first line is the JSON envelope
26 _check(json.loads(r.output.splitlines()[0]))
27
28
29 # ---------------------------------------------------------------------------
30 # TestRegisterFlags — argparse-level verification
31 # ---------------------------------------------------------------------------
32
33
34 class TestRegisterFlags:
35 """Verify that register() wires --json / -j correctly."""
36
37 def _make_parser(self) -> "argparse.ArgumentParser":
38 import argparse
39 from muse.cli.commands.fetch import register
40 ap = argparse.ArgumentParser()
41 subs = ap.add_subparsers()
42 register(subs)
43 return ap
44
45 def test_json_flag_long(self) -> None:
46 ns = self._make_parser().parse_args(["fetch", "--json"])
47 assert ns.json_out is True
48
49 def test_j_alias(self) -> None:
50 ns = self._make_parser().parse_args(["fetch", "-j"])
51 assert ns.json_out is True
52
53 def test_default_is_text(self) -> None:
54 ns = self._make_parser().parse_args(["fetch"])
55 assert ns.json_out is False
56
57 def test_dest_is_json_out(self) -> None:
58 ns = self._make_parser().parse_args(["fetch", "-j"])
59 assert hasattr(ns, "json_out")
60 assert not hasattr(ns, "fmt")