Echo the saved model, skip the ask when both overrides are set, and say when no catalog is cached
This commit is contained in:
+15
-1
@@ -148,6 +148,8 @@ class WorkerArgs(unittest.TestCase):
|
||||
class ProjectModel(unittest.TestCase):
|
||||
def test_asks_once_per_project_from_the_newest_catalog_and_saves_the_answer(self):
|
||||
with tempfile.TemporaryDirectory() as home, unittest.mock.patch.dict(os.environ, {"HOME": home}), unittest.mock.patch.object(sys, "stderr", io.StringIO()):
|
||||
for variable in ("LOOP_CLAUDE_JUDGE_MODEL", "LOOP_CLAUDE_WORKER_MODEL"):
|
||||
os.environ.pop(variable, None)
|
||||
saved = pathlib.Path(home, ".claude", "loop-claude-models.json")
|
||||
catalog = pathlib.Path(home, ".claude", "cache", "model-catalog")
|
||||
catalog.mkdir(parents=True)
|
||||
@@ -156,7 +158,10 @@ class ProjectModel(unittest.TestCase):
|
||||
with unittest.mock.patch("sys.stdin.isatty", return_value=False), self.assertRaises(SystemExit) as stopped:
|
||||
loop.project_model("/srv/a")
|
||||
self.assertEqual(stopped.exception.code, 2)
|
||||
self.assertIn(f'add "srv/a": "<model>" to {saved}', sys.stderr.getvalue())
|
||||
self.assertFalse(saved.exists())
|
||||
with unittest.mock.patch.dict(os.environ, {"LOOP_CLAUDE_JUDGE_MODEL": "j", "LOOP_CLAUDE_WORKER_MODEL": "w"}), unittest.mock.patch("sys.stdin.isatty", return_value=False):
|
||||
self.assertEqual(loop.project_model("/srv/a"), "")
|
||||
with (
|
||||
unittest.mock.patch("sys.stdin.isatty", return_value=True),
|
||||
unittest.mock.patch("sys.stdout.isatty", return_value=True),
|
||||
@@ -166,6 +171,7 @@ class ProjectModel(unittest.TestCase):
|
||||
self.assertEqual(typed.call_count, 3)
|
||||
self.assertIn("2. CLAUDE-SONNET-5 (claude-sonnet-5)", sys.stderr.getvalue())
|
||||
self.assertIn("pick 1 to 2", sys.stderr.getvalue())
|
||||
self.assertIn("srv/a runs on claude-sonnet-5", sys.stderr.getvalue())
|
||||
self.assertNotIn("claude-opus-5)", sys.stderr.getvalue())
|
||||
def saved_elsewhere_while_asking(prompt):
|
||||
saved.write_text(json.dumps({**json.loads(saved.read_text()), "srv/d": "haiku"}))
|
||||
@@ -184,10 +190,18 @@ class ProjectModel(unittest.TestCase):
|
||||
self.assertEqual(stopped.exception.code, f"could not save the model in {saved}: Permission denied")
|
||||
self.assertEqual(json.loads(saved.read_text()), {"srv/a": "claude-sonnet-5", "srv/b": "opus[1m]", "srv/d": "haiku"})
|
||||
self.assertEqual(sorted(os.listdir(saved.parent)), ["cache", "loop-claude-models.json"])
|
||||
for shape in ({"fetchedAt": 3, "catalog": None}, {"fetchedAt": 3, "catalog": {"config": []}}, {"fetchedAt": 3, "catalog": {"config": {"models": "x"}}}):
|
||||
for shape in ({"fetchedAt": 3, "catalog": {"config": {"models": []}}}, {"fetchedAt": 3, "catalog": None}, {"fetchedAt": 3, "catalog": {"config": []}}, {"fetchedAt": 3, "catalog": {"config": {"models": "x"}}}):
|
||||
catalog.joinpath("new.json").write_text(json.dumps(shape))
|
||||
with self.subTest(shape=shape):
|
||||
self.assertEqual(loop.catalog(), [])
|
||||
with (
|
||||
unittest.mock.patch("sys.stdin.isatty", return_value=True),
|
||||
unittest.mock.patch("sys.stdout.isatty", return_value=True),
|
||||
unittest.mock.patch("builtins.input", side_effect=["1"]) as typed,
|
||||
):
|
||||
self.assertEqual(loop.project_model("/srv/e"), "1")
|
||||
self.assertEqual(typed.call_args.args[0], "A name claude --model takes: ")
|
||||
self.assertIn("no model catalog cached", sys.stderr.getvalue())
|
||||
for broken in ("{", "[]", '{"srv/a": 1}'):
|
||||
saved.write_text(broken)
|
||||
with self.subTest(broken=broken), self.assertRaises(SystemExit) as stopped:
|
||||
|
||||
Reference in New Issue
Block a user