Break the old god module into flat siblings for CLI parsing, run lifecycle, daemon state, shared processing helpers, benchmark tooling, and maintainer-only model sync so changes stop sharing one giant import graph. Keep aman as a thin shim over aman_cli, move sync-default-model behind the hidden aman-maint entrypoint plus Make wrappers, and update packaging metadata plus maintainer docs to reflect the new surface. Retarget the tests to the new seams with dedicated runtime, run, benchmark, maintainer, and entrypoint suites, and verify with python3 -m unittest discover -s tests -p "test_*.py", python3 -m py_compile src/*.py tests/*.py, PYTHONPATH=src python3 -m aman --help, PYTHONPATH=src python3 -m aman version, and PYTHONPATH=src python3 -m aman_maint --help.
148 lines
5.3 KiB
Python
148 lines
5.3 KiB
Python
import json
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
SRC = ROOT / "src"
|
|
if str(SRC) not in sys.path:
|
|
sys.path.insert(0, str(SRC))
|
|
|
|
import aman_maint
|
|
import aman_model_sync
|
|
|
|
|
|
class AmanMaintTests(unittest.TestCase):
|
|
def test_parse_args_sync_default_model_command(self):
|
|
args = aman_maint.parse_args(
|
|
[
|
|
"sync-default-model",
|
|
"--report",
|
|
"benchmarks/results/latest.json",
|
|
"--artifacts",
|
|
"benchmarks/model_artifacts.json",
|
|
"--constants",
|
|
"src/constants.py",
|
|
"--check",
|
|
]
|
|
)
|
|
|
|
self.assertEqual(args.command, "sync-default-model")
|
|
self.assertEqual(args.report, "benchmarks/results/latest.json")
|
|
self.assertEqual(args.artifacts, "benchmarks/model_artifacts.json")
|
|
self.assertEqual(args.constants, "src/constants.py")
|
|
self.assertTrue(args.check)
|
|
|
|
def test_main_dispatches_sync_default_model_command(self):
|
|
with patch("aman_model_sync.sync_default_model_command", return_value=7) as handler:
|
|
exit_code = aman_maint.main(["sync-default-model"])
|
|
|
|
self.assertEqual(exit_code, 7)
|
|
handler.assert_called_once()
|
|
|
|
def test_sync_default_model_command_updates_constants(self):
|
|
with tempfile.TemporaryDirectory() as td:
|
|
report_path = Path(td) / "latest.json"
|
|
artifacts_path = Path(td) / "artifacts.json"
|
|
constants_path = Path(td) / "constants.py"
|
|
report_path.write_text(
|
|
json.dumps({"winner_recommendation": {"name": "test-model"}}),
|
|
encoding="utf-8",
|
|
)
|
|
artifacts_path.write_text(
|
|
json.dumps(
|
|
{
|
|
"models": [
|
|
{
|
|
"name": "test-model",
|
|
"filename": "winner.gguf",
|
|
"url": "https://example.invalid/winner.gguf",
|
|
"sha256": "a" * 64,
|
|
}
|
|
]
|
|
}
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
constants_path.write_text(
|
|
(
|
|
'MODEL_NAME = "old.gguf"\n'
|
|
'MODEL_URL = "https://example.invalid/old.gguf"\n'
|
|
'MODEL_SHA256 = "' + ("b" * 64) + '"\n'
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
args = aman_maint.parse_args(
|
|
[
|
|
"sync-default-model",
|
|
"--report",
|
|
str(report_path),
|
|
"--artifacts",
|
|
str(artifacts_path),
|
|
"--constants",
|
|
str(constants_path),
|
|
]
|
|
)
|
|
exit_code = aman_model_sync.sync_default_model_command(args)
|
|
self.assertEqual(exit_code, 0)
|
|
updated = constants_path.read_text(encoding="utf-8")
|
|
self.assertIn('MODEL_NAME = "winner.gguf"', updated)
|
|
self.assertIn('MODEL_URL = "https://example.invalid/winner.gguf"', updated)
|
|
self.assertIn('MODEL_SHA256 = "' + ("a" * 64) + '"', updated)
|
|
|
|
def test_sync_default_model_command_check_mode_returns_2_on_drift(self):
|
|
with tempfile.TemporaryDirectory() as td:
|
|
report_path = Path(td) / "latest.json"
|
|
artifacts_path = Path(td) / "artifacts.json"
|
|
constants_path = Path(td) / "constants.py"
|
|
report_path.write_text(
|
|
json.dumps({"winner_recommendation": {"name": "test-model"}}),
|
|
encoding="utf-8",
|
|
)
|
|
artifacts_path.write_text(
|
|
json.dumps(
|
|
{
|
|
"models": [
|
|
{
|
|
"name": "test-model",
|
|
"filename": "winner.gguf",
|
|
"url": "https://example.invalid/winner.gguf",
|
|
"sha256": "a" * 64,
|
|
}
|
|
]
|
|
}
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
constants_path.write_text(
|
|
(
|
|
'MODEL_NAME = "old.gguf"\n'
|
|
'MODEL_URL = "https://example.invalid/old.gguf"\n'
|
|
'MODEL_SHA256 = "' + ("b" * 64) + '"\n'
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
args = aman_maint.parse_args(
|
|
[
|
|
"sync-default-model",
|
|
"--report",
|
|
str(report_path),
|
|
"--artifacts",
|
|
str(artifacts_path),
|
|
"--constants",
|
|
str(constants_path),
|
|
"--check",
|
|
]
|
|
)
|
|
exit_code = aman_model_sync.sync_default_model_command(args)
|
|
self.assertEqual(exit_code, 2)
|
|
updated = constants_path.read_text(encoding="utf-8")
|
|
self.assertIn('MODEL_NAME = "old.gguf"', updated)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|