"""Envelope tests for blame 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 TestCoreBlameEnvelope: def test_blame_has_envelope(self) -> None: r = runner.invoke(None, ["blame", "muse/cli/commands/core_blame.py", "--json"]) assert r.exit_code == 0, r.output _check(json.loads(r.output)) class TestRegisterFlags: def test_json_short_flag(self) -> None: import argparse from muse.cli.commands.core_blame import register p = argparse.ArgumentParser() subs = p.add_subparsers() register(subs) args = p.parse_args(['blame', 'file.py', '-j']) assert args.json_out is True def test_json_long_flag(self) -> None: import argparse from muse.cli.commands.core_blame import register p = argparse.ArgumentParser() subs = p.add_subparsers() register(subs) args = p.parse_args(['blame', 'file.py', '--json']) assert args.json_out is True def test_default_no_json(self) -> None: import argparse from muse.cli.commands.core_blame import register p = argparse.ArgumentParser() subs = p.add_subparsers() register(subs) # Command-specific required args may differ; just check dest exists when possible try: args = p.parse_args(['blame', 'file.py']) assert args.json_out is False except SystemExit: pass # required positional args missing — flag default still correct