gabriel / muse public
test_path_annotate.py python
102 lines 3.8 KB
Raw
sha256:9a3bb190de5a18742792038aa709072a582ada8b223d5dfa4f72c70831ec3ba3 docs: revert migrate hub-scoping/domain-integers rows from … Sonnet 5 15 hours ago
1 """Tests for ``muse path annotate`` — six-level and hub-scoped seven-level paths.
2
3 Hub scoping (musehub#221) inserted a ``hub'`` segment between ``role'`` and
4 ``index'``; this command must decode both shapes.
5 """
6
7 from __future__ import annotations
8
9 import json
10
11 import pytest
12
13 from muse.cli.commands.path_cmd import _annotate
14 from muse.core.hdkeys import DOMAIN_IDENTITY, hub_index, muse_path
15 from tests.cli_test_helper import CliRunner
16
17 runner = CliRunner()
18
19
20 class TestAnnotateSixLevel:
21 def test_decodes_pre_hub_scoping_path(self) -> None:
22 result = _annotate(muse_path(DOMAIN_IDENTITY))
23 assert result["purpose"] == "muse"
24 assert result["domain"] == "muse/identity"
25 assert result["entity_type"] == "human"
26 assert result["role"] == "sign"
27 assert result["hub_idx"] is None
28 assert result["hub_scoped"] is False
29 assert result["index"] == 0
30
31
32 class TestAnnotateSevenLevel:
33 def test_decodes_hub_scoped_path(self) -> None:
34 hub = hub_index("musehub.ai")
35 result = _annotate(muse_path(DOMAIN_IDENTITY, hub=hub))
36 assert result["hub_idx"] == hub
37 assert result["hub_scoped"] is True
38 assert result["index"] == 0
39
40 def test_preserves_other_fields_when_hub_scoped(self) -> None:
41 from muse.core.hdkeys import ENTITY_AGENT, ROLE_ATTEST
42 hub = hub_index("staging.musehub.ai")
43 result = _annotate(muse_path(DOMAIN_IDENTITY, ENTITY_AGENT, 3, ROLE_ATTEST, 2, hub=hub))
44 assert result["entity_type"] == "agent"
45 assert result["entity_id"] == 3
46 assert result["role"] == "attest"
47 assert result["hub_idx"] == hub
48 assert result["index"] == 2
49
50
51 class TestAnnotateMalformed:
52 def test_five_segments_raises(self) -> None:
53 with pytest.raises(ValueError, match="Cannot parse path"):
54 _annotate("m/1075233755'/0'/0'/0'/0'")
55
56 def test_eight_segments_raises(self) -> None:
57 with pytest.raises(ValueError, match="Cannot parse path"):
58 _annotate("m/1075233755'/0'/0'/0'/0'/0'/0'/0'")
59
60 def test_garbage_raises(self) -> None:
61 with pytest.raises(ValueError, match="Cannot parse path"):
62 _annotate("not-a-path")
63
64 def test_empty_raises(self) -> None:
65 with pytest.raises(ValueError, match="Cannot parse path"):
66 _annotate("")
67
68
69 class TestAnnotateCli:
70 def test_cli_json_six_level(self) -> None:
71 result = runner.invoke(
72 None, ["path", "annotate", muse_path(DOMAIN_IDENTITY), "--json"]
73 )
74 assert result.exit_code == 0, result.output
75 data = json.loads(result.output)
76 assert data["hub_scoped"] is False
77 assert data["hub_idx"] is None
78
79 def test_cli_json_seven_level(self) -> None:
80 hub = hub_index("musehub.ai")
81 path = muse_path(DOMAIN_IDENTITY, hub=hub)
82 result = runner.invoke(None, ["path", "annotate", path, "--json"])
83 assert result.exit_code == 0, result.output
84 data = json.loads(result.output)
85 assert data["hub_scoped"] is True
86 assert data["hub_idx"] == hub
87
88 def test_cli_text_output_includes_hub_line_when_scoped(self) -> None:
89 hub = hub_index("musehub.ai")
90 path = muse_path(DOMAIN_IDENTITY, hub=hub)
91 result = runner.invoke(None, ["path", "annotate", path])
92 assert result.exit_code == 0, result.output
93 assert f"hub: {hub}" in result.output
94
95 def test_cli_text_output_omits_hub_line_when_not_scoped(self) -> None:
96 result = runner.invoke(None, ["path", "annotate", muse_path(DOMAIN_IDENTITY)])
97 assert result.exit_code == 0, result.output
98 assert "hub:" not in result.output
99
100 def test_cli_malformed_path_exits_nonzero(self) -> None:
101 result = runner.invoke(None, ["path", "annotate", "garbage"])
102 assert result.exit_code != 0
File History 1 commit
sha256:9a3bb190de5a18742792038aa709072a582ada8b223d5dfa4f72c70831ec3ba3 docs: revert migrate hub-scoping/domain-integers rows from … Sonnet 5 15 hours ago