test_age_envelope.py
python
sha256:81ae324db5ad375fbfe4834c6fcb378312cafad3cc92dec5d3e5c427306621a2
fix: remove commit_exists filter from have anchors — server…
Sonnet 4.6
patch
20 days ago
| 1 | """Envelope tests for ``muse code age --json``.""" |
| 2 | from __future__ import annotations |
| 3 | import argparse |
| 4 | import json |
| 5 | import pytest |
| 6 | from tests.cli_test_helper import CliRunner, InvokeResult |
| 7 | |
| 8 | runner = CliRunner() |
| 9 | |
| 10 | def _age_json(*extra: str) -> InvokeResult: |
| 11 | return runner.invoke(None, ["code", "age", "--json", *extra]) |
| 12 | |
| 13 | class TestAgeEnvelope: |
| 14 | def test_has_muse_version(self) -> None: |
| 15 | r = _age_json() |
| 16 | assert r.exit_code == 0, r.output |
| 17 | assert "muse_version" in json.loads(r.output) |
| 18 | |
| 19 | def test_has_schema(self) -> None: |
| 20 | r = _age_json() |
| 21 | assert "schema" in json.loads(r.output) |
| 22 | |
| 23 | def test_has_timestamp(self) -> None: |
| 24 | r = _age_json() |
| 25 | assert "timestamp" in json.loads(r.output) |
| 26 | |
| 27 | def test_has_warnings(self) -> None: |
| 28 | r = _age_json() |
| 29 | assert "warnings" in json.loads(r.output) |
| 30 | |
| 31 | def test_no_schema_version(self) -> None: |
| 32 | r = _age_json() |
| 33 | assert "schema_version" not in json.loads(r.output) |
| 34 | |
| 35 | def test_j_alias_works(self) -> None: |
| 36 | r = runner.invoke(None, ["code", "age", "-j"]) |
| 37 | assert r.exit_code == 0 |
| 38 | d = json.loads(r.output) |
| 39 | assert "muse_version" in d |
| 40 | |
| 41 | |
| 42 | class TestRegisterFlags: |
| 43 | def _parse(self, *args: str) -> argparse.Namespace: |
| 44 | from muse.cli.commands.age import register |
| 45 | p = argparse.ArgumentParser() |
| 46 | sub = p.add_subparsers() |
| 47 | register(sub) |
| 48 | return p.parse_args(["age", *args]) |
| 49 | |
| 50 | def test_default_json_out_is_false(self) -> None: |
| 51 | ns = self._parse() |
| 52 | assert ns.json_out is False |
| 53 | |
| 54 | def test_json_flag_sets_json_out(self) -> None: |
| 55 | ns = self._parse("--json") |
| 56 | assert ns.json_out is True |
| 57 | |
| 58 | def test_j_shorthand_sets_json_out(self) -> None: |
| 59 | ns = self._parse("-j") |
| 60 | assert ns.json_out is True |
| 61 | |
| 62 | def test_top_default(self) -> None: |
| 63 | ns = self._parse() |
| 64 | assert ns.top == 20 |
| 65 | |
| 66 | def test_top_flag(self) -> None: |
| 67 | ns = self._parse("--top", "50") |
| 68 | assert ns.top == 50 |
| 69 | |
| 70 | def test_top_has_no_n_shorthand(self) -> None: |
| 71 | import sys |
| 72 | p = argparse.ArgumentParser() |
| 73 | sub = p.add_subparsers() |
| 74 | from muse.cli.commands.age import register |
| 75 | register(sub) |
| 76 | with pytest.raises(SystemExit): |
| 77 | p.parse_args(["age", "-n", "10"]) |
| 78 | |
| 79 | def test_sort_default(self) -> None: |
| 80 | ns = self._parse() |
| 81 | assert ns.sort == "rewrites" |
| 82 | |
| 83 | def test_sort_flag(self) -> None: |
| 84 | ns = self._parse("--sort", "calendar") |
| 85 | assert ns.sort == "calendar" |
| 86 | |
| 87 | def test_kind_filter_default(self) -> None: |
| 88 | ns = self._parse() |
| 89 | assert ns.kind_filter is None |
| 90 | |
| 91 | def test_kind_flag(self) -> None: |
| 92 | ns = self._parse("--kind", "function") |
| 93 | assert ns.kind_filter == "function" |
| 94 | |
| 95 | def test_file_filter_default(self) -> None: |
| 96 | ns = self._parse() |
| 97 | assert ns.file_filter is None |
| 98 | |
| 99 | def test_file_flag(self) -> None: |
| 100 | ns = self._parse("--file", "billing.py") |
| 101 | assert ns.file_filter == "billing.py" |
| 102 | |
| 103 | def test_file_has_no_f_shorthand(self) -> None: |
| 104 | p = argparse.ArgumentParser() |
| 105 | sub = p.add_subparsers() |
| 106 | from muse.cli.commands.age import register |
| 107 | register(sub) |
| 108 | with pytest.raises(SystemExit): |
| 109 | p.parse_args(["age", "-f", "billing.py"]) |
| 110 | |
| 111 | def test_since_default(self) -> None: |
| 112 | ns = self._parse() |
| 113 | assert ns.since is None |
| 114 | |
| 115 | def test_since_flag(self) -> None: |
| 116 | ns = self._parse("--since", "v1.0") |
| 117 | assert ns.since == "v1.0" |
| 118 | |
| 119 | def test_max_commits_default(self) -> None: |
| 120 | ns = self._parse() |
| 121 | assert ns.max_commits == 10_000 |
| 122 | |
| 123 | def test_explain_default(self) -> None: |
| 124 | ns = self._parse() |
| 125 | assert ns.explain is None |
File History
4 commits
sha256:81ae324db5ad375fbfe4834c6fcb378312cafad3cc92dec5d3e5c427306621a2
fix: remove commit_exists filter from have anchors — server…
Sonnet 4.6
patch
20 days ago
sha256:36c3cb3e76619d4c30a6d9bf81b5ec4ff148e30dcfed913e3114ca7b43b81c7e
fix: rename objects→blobs in push client and all stale test…
Sonnet 4.6
patch
22 days ago
sha256:c06a9b9b9fee26c68ea725b44d54b2c0a171301ce9de746d5b656617b4463a9a
fix: repair four test failures from post-migration audit
Sonnet 4.6
patch
28 days ago
sha256:1900655993c83c4107067375548a7be823e471d2515830842f1a12cba4bd3cdf
fix: unified object store migration — idempotent writes, JS…
Sonnet 4.6
minor
⚠
29 days ago