Skip to content

Commit 358d062

Browse files
committed
Add Local Model Door CLI tests
1 parent 5658e23 commit 358d062

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

tests/test_local_model_cli.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
"""Unit tests for sourceosctl Local Model Door commands."""
2+
3+
import json
4+
import os
5+
import pathlib
6+
import sys
7+
import tempfile
8+
import unittest
9+
from unittest import mock
10+
11+
_REPO_ROOT = pathlib.Path(__file__).parent.parent
12+
sys.path.insert(0, str(_REPO_ROOT))
13+
14+
from sourceosctl.cli import main
15+
from sourceosctl.commands import local_model
16+
17+
18+
class TestLocalModelCommands(unittest.TestCase):
19+
def test_profiles_direct(self):
20+
self.assertEqual(local_model.profiles(mock.Mock()), 0)
21+
22+
@mock.patch("sourceosctl.commands.local_model.shutil.which", return_value=None)
23+
def test_doctor_without_ollama(self, _which):
24+
self.assertEqual(main(["local-model", "doctor"]), 0)
25+
26+
@mock.patch("sourceosctl.commands.local_model.shutil.which", return_value="/usr/bin/ollama")
27+
@mock.patch("sourceosctl.commands.local_model.subprocess.run")
28+
def test_doctor_with_ollama_models(self, run, _which):
29+
run.return_value = mock.Mock(
30+
returncode=0,
31+
stdout="NAME ID SIZE MODIFIED\nllama3.2:1b abc 1.3 GB now\n",
32+
stderr="",
33+
)
34+
self.assertEqual(main(["local-model", "doctor"]), 0)
35+
run.assert_called_once()
36+
self.assertEqual(run.call_args.args[0], ["/usr/bin/ollama", "list"])
37+
38+
@mock.patch("sourceosctl.commands.local_model.shutil.which", return_value=None)
39+
def test_plan_does_not_pull_model(self, _which):
40+
self.assertEqual(main(["local-model", "plan", "--profile", "local-llama32-1b"]), 0)
41+
42+
@mock.patch("sourceosctl.commands.local_model.shutil.which", return_value=None)
43+
def test_route_hash_only_with_prompt(self, _which):
44+
self.assertEqual(
45+
main([
46+
"local-model",
47+
"route",
48+
"--task-class",
49+
"office-assist",
50+
"--prompt",
51+
"sensitive prompt body should not be emitted",
52+
"--personalization-ref",
53+
"urn:socioprophet:personal-tuning-contract:demo-user-local-llama32",
54+
]),
55+
0,
56+
)
57+
58+
def test_evidence_inspect_valid(self):
59+
payload = {
60+
"type": "LocalModelRouteDecision",
61+
"taskClass": "office-assist",
62+
"target": "personal-local-policy-checked",
63+
"promptStored": False,
64+
"promptHash": "sha256:example",
65+
"routerBindingRef": "urn:socioprophet:model-router-binding:demo-user-local-llama32",
66+
}
67+
with tempfile.NamedTemporaryFile(suffix=".json", mode="w", delete=False) as handle:
68+
json.dump(payload, handle)
69+
tmp_path = handle.name
70+
try:
71+
self.assertEqual(main(["local-model", "evidence", "inspect", tmp_path]), 0)
72+
finally:
73+
os.unlink(tmp_path)
74+
75+
def test_evidence_inspect_missing(self):
76+
self.assertEqual(main(["local-model", "evidence", "inspect", "/nonexistent/local-model.json"]), 1)
77+
78+
79+
if __name__ == "__main__":
80+
unittest.main()

0 commit comments

Comments
 (0)