Classification by recorded facts only: no name parser or tier words, no guessed classes; sisi workers classify prints the question for a cheap worker and --record validates and stores its answer; identity (maker, class) and release date drive supersession, inheritance, tie-break; route and session start ask only when it matters. done / next: proof on a copy, repeat runs, report
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d6bdb799c5
commit
d36550d00f
15 files changed
+619
-677
No files matched your search
@@ -4,7 +4,7 @@ Requirement ids: R-7.2-1, R-7.2-2, R-7.2-3."""
|
||||
import json, os, random, unittest
|
||||
from support import *
|
||||
from sisi import routing
|
||||
from test_model_supersession import cand, attempts, pick, NOW
|
||||
from test_model_supersession import cand, attempts, pick, NOW, R1, R2
|
||||
from test_worker_models import ModelCase
|
||||
|
||||
ORDER = {"abc": ["fable", "opus", "sonnet", "haiku"]}
|
||||
@@ -12,7 +12,7 @@ COST = {"fable": 9.0, "opus": 6.0, "sonnet": 3.0, "haiku": 1.0}
|
||||
|
||||
|
||||
def fleet(**extra):
|
||||
return [cand("prov/abc-%s-5" % c, **dict({"cost": COST[c]}, **extra.get(c, {}))) for c in ("fable", "opus", "sonnet", "haiku")]
|
||||
return [cand("prov/abc-%s-5" % c, **dict({"cost": COST[c], "cls": c}, **extra.get(c, {}))) for c in ("fable", "opus", "sonnet", "haiku")]
|
||||
|
||||
|
||||
def best(cands, difficulty, records=(), **kw):
|
||||
@@ -62,13 +62,13 @@ class ClassOrderTests(unittest.TestCase):
|
||||
self.assertEqual((who, r["basis"]), ("prov/abc-sonnet-5", "strongest"))
|
||||
|
||||
def test_another_makers_models_are_not_placed_by_this_order(self):
|
||||
other = cand("prov/xyz-opus-5", cost=0.1, maker="xyz")
|
||||
other = cand("prov/xyz-opus-5", cls="opus", cost=0.1, maker="xyz")
|
||||
who, r = best(fleet() + [other], 3)
|
||||
self.assertEqual(who, "prov/abc-opus-5")
|
||||
self.assertNotEqual(r["assessments"]["prov/xyz-opus-5"]["tier"], "class")
|
||||
|
||||
def test_a_class_missing_from_the_order_is_not_placed(self):
|
||||
extra = cand("prov/abc-ember-1", cost=0.1)
|
||||
extra = cand("prov/abc-ember-1", cls="ember", cost=0.1)
|
||||
who, r = best(fleet() + [extra], 3)
|
||||
self.assertNotEqual(r["assessments"]["prov/abc-ember-1"]["tier"], "class")
|
||||
|
||||
@@ -77,13 +77,13 @@ class ClassOrderTests(unittest.TestCase):
|
||||
self.assertEqual(r["class_ask"]["order"], [("abc", ["fable", "haiku", "opus", "sonnet"])])
|
||||
r = best(fleet(), 3)[1]
|
||||
self.assertEqual(r["class_ask"]["order"], [])
|
||||
one = pick([cand("prov/abc-opus-5"), cand("prov/abc-opus-6")], (), 3)[1]
|
||||
one = pick([cand("prov/abc-opus-5", cls="opus", rel=R1), cand("prov/abc-opus-6", cls="opus", rel=R2)], (), 3)[1]
|
||||
self.assertEqual(one["class_ask"]["order"], []) # one class only: nothing to order
|
||||
|
||||
def test_property_the_order_never_outranks_a_record_or_a_standing(self):
|
||||
rng = random.Random(9)
|
||||
for _ in range(300 * ITERS):
|
||||
cands = [cand("prov/abc-%s-5" % c, cost=rng.choice([1.0, 2.0, 5.0]),
|
||||
cands = [cand("prov/abc-%s-5" % c, cls=c, cost=rng.choice([1.0, 2.0, 5.0]),
|
||||
standing=rng.choice([None, None, 40.0, 90.0])) for c in rng.sample(list(COST), rng.randint(2, 4))]
|
||||
records = []
|
||||
for c in cands:
|
||||
@@ -123,6 +123,7 @@ class ClassesCommandTests(ModelCase):
|
||||
models = ("abc-fable-5", "abc-opus-5", "abc-sonnet-5", "abc-haiku-5")
|
||||
for m in models:
|
||||
self.sisi("workers", "fact", "muse/" + m, "--price", str(COST[m.split("-")[1]]), "--source", "fixture", env=self.env(models))
|
||||
self.record("muse/" + m, m.split("-")[1], models=models)
|
||||
first = self.route(3, models=models)
|
||||
self.assertIn("record the order", first.stdout)
|
||||
self.assertLessEqual(len(first.stdout.splitlines()), 7, first.stdout)
|
||||
|
||||
@@ -4,7 +4,7 @@ predecessor's bad record does not block it. Invented ids. Requirement ids: R-7.2
|
||||
import random, unittest
|
||||
from support import *
|
||||
from sisi import routing
|
||||
from test_model_supersession import cand, attempts, pick, NOW
|
||||
from test_model_supersession import cand, attempts, pick, NOW, R1, R2, R3, R4
|
||||
|
||||
|
||||
def assessed(cands, records, worker, difficulty=2, kind="impl", **kw):
|
||||
@@ -12,9 +12,12 @@ def assessed(cands, records, worker, difficulty=2, kind="impl", **kw):
|
||||
return r["assessments"].get(worker), r
|
||||
|
||||
|
||||
m_ = {'5.1': '2026-01-01', '5.2': '2026-03-01', '5.3': '2026-06-01', '5.4': '2026-09-01', '5.10': '2026-10-01'}
|
||||
|
||||
|
||||
class InheritanceTests(unittest.TestCase):
|
||||
def test_a_new_version_inherits_the_record_of_its_predecessor_and_says_so(self):
|
||||
old, new = cand("prov/abc-5.3", cost=1.0), cand("prov/abc-5.4", cost=2.0)
|
||||
old, new = cand("prov/abc-5.3", rel="2026-06-01", cost=1.0), cand("prov/abc-5.4", rel="2026-09-01", cost=2.0)
|
||||
records = attempts("prov/abc-5.3", 12, 11, difficulty=2)
|
||||
a, r = assessed([old, new], records, "prov/abc-5.4")
|
||||
self.assertEqual((a["tier"], a["capable"], a["inherited_from"]), ("a", True, "prov/abc-5.3"))
|
||||
@@ -24,7 +27,7 @@ class InheritanceTests(unittest.TestCase):
|
||||
self.assertIn("11 of 12", line)
|
||||
|
||||
def test_it_walks_back_one_predecessor_at_a_time(self):
|
||||
cands = [cand("prov/abc-5.2", cost=1.0), cand("prov/abc-5.3", cost=1.0), cand("prov/abc-5.4", cost=1.0)]
|
||||
cands = [cand("prov/abc-5.2", rel="2026-03-01", cost=1.0), cand("prov/abc-5.3", rel="2026-06-01", cost=1.0), cand("prov/abc-5.4", rel="2026-09-01", cost=1.0)]
|
||||
records = attempts("prov/abc-5.2", 12, 12, difficulty=2) + attempts("prov/abc-5.3", 3, 3, difficulty=2)
|
||||
a, _ = assessed(cands, records, "prov/abc-5.4")
|
||||
self.assertEqual(a["inherited_from"], "prov/abc-5.2") # 5.3 has only a thin record
|
||||
@@ -33,17 +36,17 @@ class InheritanceTests(unittest.TestCase):
|
||||
self.assertEqual(a["inherited_from"], "prov/abc-5.3") # now the closest thick one
|
||||
|
||||
def test_a_predecessors_bad_record_does_not_block_the_newer_model(self):
|
||||
cands = [cand("prov/abc-5.3", cost=1.0), cand("prov/abc-5.4", cost=1.0, standing=70.0)]
|
||||
cands = [cand("prov/abc-5.3", rel="2026-06-01", cost=1.0), cand("prov/abc-5.4", rel="2026-09-01", cost=1.0, standing=70.0)]
|
||||
records = attempts("prov/abc-5.3", 12, 2, difficulty=2)
|
||||
a, _ = assessed(cands, records, "prov/abc-5.4")
|
||||
self.assertFalse(a["bad"])
|
||||
self.assertEqual(a["tier"], "standing") # it starts from its benchmark, not from the old verdict
|
||||
bare = assessed([cands[0], cand("prov/abc-5.4", cost=1.0)], records, "prov/abc-5.4")[0]
|
||||
bare = assessed([cands[0], cand("prov/abc-5.4", rel="2026-09-01", cost=1.0)], records, "prov/abc-5.4")[0]
|
||||
self.assertFalse(bare["bad"])
|
||||
self.assertFalse(bare["capable"])
|
||||
|
||||
def test_the_models_own_thick_record_replaces_the_inherited_one(self):
|
||||
cands = [cand("prov/abc-5.3", cost=1.0), cand("prov/abc-5.4", cost=1.0)]
|
||||
cands = [cand("prov/abc-5.3", rel="2026-06-01", cost=1.0), cand("prov/abc-5.4", rel="2026-09-01", cost=1.0)]
|
||||
records = attempts("prov/abc-5.3", 12, 12, difficulty=2) + attempts("prov/abc-5.4", 9, 1, difficulty=2)
|
||||
a, _ = assessed(cands, records, "prov/abc-5.4")
|
||||
self.assertTrue(a["bad"])
|
||||
@@ -53,30 +56,30 @@ class InheritanceTests(unittest.TestCase):
|
||||
self.assertEqual((a["tier"], a.get("inherited_from")), ("a", None))
|
||||
|
||||
def test_a_thin_record_that_already_contradicts_is_not_papered_over(self):
|
||||
cands = [cand("prov/abc-5.3", cost=1.0), cand("prov/abc-5.4", cost=1.0)]
|
||||
cands = [cand("prov/abc-5.3", rel="2026-06-01", cost=1.0), cand("prov/abc-5.4", rel="2026-09-01", cost=1.0)]
|
||||
records = attempts("prov/abc-5.3", 12, 12, difficulty=2) + attempts("prov/abc-5.4", 3, 0, difficulty=2)
|
||||
a, _ = assessed(cands, records, "prov/abc-5.4")
|
||||
self.assertIsNone(a.get("inherited_from"))
|
||||
self.assertFalse(a["capable"])
|
||||
|
||||
def test_nothing_is_inherited_across_classes_or_makers(self):
|
||||
flash, new = cand("prov/abc-5.3-flash", cost=1.0), cand("prov/abc-5.4", cost=1.0)
|
||||
flash, new = cand("prov/abc-5.3-flash", cls="flash", rel="2026-06-01", cost=1.0), cand("prov/abc-5.4", rel="2026-09-01", cost=1.0)
|
||||
records = attempts("prov/abc-5.3-flash", 12, 12, difficulty=2)
|
||||
self.assertFalse(assessed([flash, new], records, "prov/abc-5.4")[0]["capable"])
|
||||
other = cand("prov/xyz-5.4", cost=1.0, maker="xyz")
|
||||
self.assertFalse(assessed([cand("prov/abc-5.3"), other], attempts("prov/abc-5.3", 12, 12, difficulty=2), "prov/xyz-5.4")[0]["capable"])
|
||||
other = cand("prov/xyz-5.4", rel="2026-09-01", cost=1.0, maker="xyz")
|
||||
self.assertFalse(assessed([cand("prov/abc-5.3", rel="2026-06-01"), other], attempts("prov/abc-5.3", 12, 12, difficulty=2), "prov/xyz-5.4")[0]["capable"])
|
||||
|
||||
def test_nothing_is_inherited_by_an_unreadable_class(self):
|
||||
cands = [cand("prov/abc-6.2-sol"), cand("prov/abc-6.3-sol")]
|
||||
cands = [cand("prov/abc-6.2-sol", known=False), cand("prov/abc-6.3-sol", known=False)]
|
||||
records = attempts("prov/abc-6.2-sol", 12, 12, difficulty=2)
|
||||
self.assertFalse(assessed(cands, records, "prov/abc-6.3-sol")[0]["capable"])
|
||||
|
||||
def test_inherited_evidence_counts_as_a_judged_record_before_a_benchmark(self):
|
||||
"""Difficulty 2 and 3: proof comes before benchmark, and an inherited record is proof."""
|
||||
new = cand("prov/abc-5.4", cost=5.0)
|
||||
new = cand("prov/abc-5.4", rel="2026-09-01", cost=5.0)
|
||||
rival = cand("prov/xyz-2.0", cost=0.1, maker="xyz", standing=90.0)
|
||||
records = attempts("prov/abc-5.3", 12, 12, difficulty=3)
|
||||
who, r = pick([cand("prov/abc-5.3", cost=5.0), new, rival], records, 3)
|
||||
who, r = pick([cand("prov/abc-5.3", rel="2026-06-01", cost=5.0), new, rival], records, 3)
|
||||
self.assertEqual(who, "prov/abc-5.4")
|
||||
self.assertTrue(r["judged_first"])
|
||||
|
||||
@@ -90,7 +93,7 @@ class InheritanceTests(unittest.TestCase):
|
||||
|
||||
def test_a_model_with_no_data_of_its_own_is_routable_through_its_predecessor(self):
|
||||
from sisi import workers
|
||||
old, new, lone = cand("prov/abc-5.3"), cand("prov/abc-5.4"), cand("prov/xyz-9.9", maker="xyz")
|
||||
old, new, lone = cand("prov/abc-5.3", rel="2026-06-01"), cand("prov/abc-5.4", rel="2026-09-01"), cand("prov/xyz-9.9", rel="2026-09-01", maker="xyz")
|
||||
for c in (old, new, lone):
|
||||
c["price_source"] = None
|
||||
old["price_source"] = "fixture"
|
||||
@@ -103,7 +106,7 @@ class InheritanceTests(unittest.TestCase):
|
||||
seen = 0
|
||||
for _ in range(300 * ITERS):
|
||||
versions = rng.sample(["5.1", "5.2", "5.3", "5.4", "5.10"], rng.randint(2, 4))
|
||||
cands = [cand("prov/abc-%s" % v, cost=rng.choice([None, 1.0, 2.0])) for v in versions]
|
||||
cands = [cand("prov/abc-%s" % v, rel=m_[v], cost=rng.choice([None, 1.0, 2.0])) for v in versions]
|
||||
records = []
|
||||
for c in cands:
|
||||
for d in (1, 2, 3):
|
||||
|
||||
+16
-16
@@ -1,5 +1,5 @@
|
||||
"""Recency breaks ties: where the arithmetic falls back to a stable order, the more recently released model wins
|
||||
first (a recorded release date, else the version within one line, else the old tie-break by worker id), and the
|
||||
first (its recorded release date, else the old tie-break by worker id), and the
|
||||
rule is in the text agents and people read. Requirement ids: R-7.2-1, R-7.2-2."""
|
||||
import os, unittest
|
||||
from support import *
|
||||
@@ -9,27 +9,25 @@ from test_model_supersession import cand, pick
|
||||
|
||||
class RecencyTieBreakTests(unittest.TestCase):
|
||||
def test_a_recorded_release_date_decides_a_tie_between_unrelated_models(self):
|
||||
a = cand("prov/aaa-1.0", cost=1.0, fact={"released": "2026-01-10"}, maker="aaa")
|
||||
b = cand("prov/bbb-2.0", cost=1.0, fact={"released": "2026-08-01"}, maker="bbb")
|
||||
a = cand("prov/aaa-1.0", cost=1.0, rel="2026-01-10", maker="aaa")
|
||||
b = cand("prov/bbb-2.0", cost=1.0, rel="2026-08-01", maker="bbb")
|
||||
who, r = pick([a, b])
|
||||
self.assertEqual(who, "prov/bbb-2.0")
|
||||
self.assertIn(("prov/aaa-1.0", "equal on price and load; the choice is the more recently released"), r["passed_over"])
|
||||
|
||||
def test_the_version_inside_one_line_decides_when_nothing_supersedes(self):
|
||||
old, new = cand("prov/abc-5.9", cost=1.0), cand("prov/abc-5.10", cost=1.0)
|
||||
who, r = pick([old, new], opts={"supersede_guessed": False})
|
||||
self.assertEqual(who, "prov/abc-5.10")
|
||||
self.assertEqual(pick([new, old], opts={"supersede_guessed": False})[0], "prov/abc-5.10")
|
||||
self.assertEqual(pick([b, a])[0], "prov/bbb-2.0")
|
||||
|
||||
def test_unknown_recency_keeps_the_old_tie_break(self):
|
||||
a, b = cand("prov/aaa-1.0", cost=1.0, maker="aaa"), cand("prov/bbb-9.0", cost=1.0, maker="bbb")
|
||||
a, b = cand("prov/aaa-1.0", cost=1.0, maker="aaa"), cand("prov/bbb-9.0", cost=1.0, maker="bbb", rel="2026-08-01")
|
||||
who, r = pick([a, b])
|
||||
self.assertEqual(who, "prov/bbb-9.0") # a recorded date beats none
|
||||
a2, b2 = cand("prov/aaa-1.0", cost=1.0, maker="aaa", known=False), cand("prov/bbb-9.0", cost=1.0, maker="bbb", known=False)
|
||||
who, r = pick([a2, b2])
|
||||
self.assertEqual(who, "prov/aaa-1.0")
|
||||
self.assertIn(("prov/bbb-9.0", "equal on price and load; the choice came first in worker-id order"), r["passed_over"])
|
||||
|
||||
def test_price_and_load_still_come_before_recency(self):
|
||||
cheap_old = cand("prov/aaa-1.0", cost=0.5, fact={"released": "2026-01-10"}, maker="aaa")
|
||||
dear_new = cand("prov/bbb-2.0", cost=1.0, fact={"released": "2026-08-01"}, maker="bbb")
|
||||
cheap_old = cand("prov/aaa-1.0", cost=0.5, rel="2026-01-10", maker="aaa")
|
||||
dear_new = cand("prov/bbb-2.0", cost=1.0, rel="2026-08-01", maker="bbb")
|
||||
self.assertEqual(pick([cheap_old, dear_new])[0], "prov/aaa-1.0")
|
||||
|
||||
|
||||
@@ -58,11 +56,13 @@ class TextTests(unittest.TestCase):
|
||||
|
||||
|
||||
class SessionLineTests(SisiCase):
|
||||
def test_session_start_asks_for_the_release_date_of_each_worker_that_lacks_one(self):
|
||||
def test_session_start_names_unclassified_workers_in_the_one_facts_line(self):
|
||||
from sisi import workers
|
||||
line = workers.facts_line()
|
||||
self.assertIn("release date", line)
|
||||
self.assertIn("--released", line)
|
||||
line = workers.facts_line(unclassified=2)
|
||||
self.assertEqual(len(line.splitlines()), 1)
|
||||
self.assertIn("2 routable workers have no recorded maker, class and release date", line)
|
||||
self.assertIn("sisi workers classify", line)
|
||||
self.assertNotIn("classify", workers.facts_line(unclassified=0))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
+128
-117
@@ -1,19 +1,22 @@
|
||||
"""The newest usable version of a maker's class always wins over its older versions (hard rule), however good the
|
||||
older record or cheap its plan. Pure routing tests over invented ids shaped like real ones.
|
||||
older record or cheap its plan. Identity and recency come from recorded facts. Pure routing tests over invented ids.
|
||||
Requirement ids: R-7.2-1, R-7.2-2, R-7.2-3."""
|
||||
import json, os, random, unittest
|
||||
import random, unittest
|
||||
from support import *
|
||||
from sisi import modelid, routing
|
||||
from sisi import routing
|
||||
|
||||
WORDS = json.load(open(os.path.join(REPO, "canon", "model-words.json")))
|
||||
NOW = 1000000.0
|
||||
R1, R2, R3, R4 = "2026-03-01", "2026-06-01", "2026-09-01", "2026-11-01"
|
||||
|
||||
|
||||
def cand(worker, plan="per-use", cost=1.0, fact=None, host_native=False, standing=None, **kw):
|
||||
def cand(worker, cls="standard", rel=None, maker="abc", plan="per-use", cost=1.0, host_native=False, standing=None,
|
||||
known=True, **kw):
|
||||
"""A candidate whose maker, class and release date were recorded (known=False: nothing recorded)."""
|
||||
model = worker.rsplit("/", 1)[-1]
|
||||
c = {"worker": worker, "tool": worker.split("/")[0] if "/" in worker else None, "model": model, "maker": "abc",
|
||||
fact = {"class": cls, "maker": maker, "released": rel} if known else {}
|
||||
c = {"worker": worker, "tool": worker.split("/")[0] if "/" in worker else None, "model": model, "maker": maker,
|
||||
"plan": plan, "cost": cost, "allowance_pct_left": None, "usable": True, "standing": standing,
|
||||
"aliases": [worker, model], "lineage": modelid.resolve(worker, WORDS, fact=fact, host_native=host_native)}
|
||||
"aliases": [worker, model], "lineage": routing.lineage_from_fact(fact, host_native=host_native)}
|
||||
c.update(kw)
|
||||
return c
|
||||
|
||||
@@ -29,121 +32,145 @@ def pick(cands, records=(), difficulty=1, availability=None, **kw):
|
||||
return (r["choice"] or {}).get("worker"), r
|
||||
|
||||
|
||||
class IdentityTests(unittest.TestCase):
|
||||
def test_no_recorded_class_and_maker_means_no_identity(self):
|
||||
for fact in (None, {}, {"class": "flash"}, {"maker": "abc"}, {"released": "2026-01-01"}):
|
||||
got = routing.lineage_from_fact(fact)
|
||||
self.assertIsNone(got["key"], fact)
|
||||
self.assertEqual(got["source"], "unknown")
|
||||
|
||||
def test_a_recorded_maker_and_class_are_the_identity_whatever_the_name(self):
|
||||
a = routing.lineage_from_fact({"class": "Flash", "maker": "ABC", "released": "2026-03-01"})
|
||||
self.assertEqual((a["key"], a["source"], a["released"]), (("abc", "flash"), "fact", "2026-03-01"))
|
||||
self.assertNotEqual(routing.lineage_from_fact({"class": "standard", "maker": "abc"})["key"], a["key"])
|
||||
|
||||
def test_the_more_recent_release_date_is_newer_and_dates_compare_as_dates(self):
|
||||
old = routing.lineage_from_fact({"class": "x", "maker": "m", "released": "2026-09-30"})
|
||||
new = routing.lineage_from_fact({"class": "x", "maker": "m", "released": "2026-10-02"})
|
||||
self.assertGreater(routing.compare_release(new, old), 0)
|
||||
self.assertLess(routing.compare_release(old, new), 0)
|
||||
self.assertEqual(routing.compare_release(old, old), 0)
|
||||
self.assertEqual(routing.compare_release(old, routing.lineage_from_fact({"class": "x", "maker": "m"})), 0) # unknowable
|
||||
self.assertGreater(routing.days("2026-10-02"), routing.days("2026-09-30"))
|
||||
self.assertEqual(routing.days("soon"), 0)
|
||||
|
||||
def test_a_bare_host_alias_without_a_release_date_is_the_newest_of_its_class(self):
|
||||
alias = routing.lineage_from_fact({"class": "x", "maker": "m"}, host_native=True)
|
||||
dated = routing.lineage_from_fact({"class": "x", "maker": "m", "released": "2030-01-01"})
|
||||
self.assertTrue(alias["alias"])
|
||||
self.assertGreater(routing.compare_release(alias, dated), 0)
|
||||
self.assertFalse(routing.lineage_from_fact({"class": "x", "maker": "m"})["alias"])
|
||||
self.assertFalse(routing.lineage_from_fact({}, host_native=True)["alias"]) # no class recorded: no comparison
|
||||
self.assertFalse(routing.lineage_from_fact({"class": "x", "maker": "m", "released": "2026-01-01"}, host_native=True)["alias"])
|
||||
|
||||
def test_unknown_answers_and_partial_dates(self):
|
||||
self.assertIsNone(routing.lineage_from_fact({"class": "unknown", "maker": "abc"})["key"])
|
||||
self.assertIsNone(routing.lineage_from_fact({"class": "x", "maker": "unknown"})["key"])
|
||||
self.assertIsNone(routing.lineage_from_fact({"class": "x", "maker": "abc", "released": "unknown"})["released"])
|
||||
a = routing.lineage_from_fact({"class": "x", "maker": "m", "released": "2026-09"})
|
||||
b = routing.lineage_from_fact({"class": "x", "maker": "m", "released": "2026-10-15"})
|
||||
self.assertGreater(routing.compare_release(b, a), 0)
|
||||
self.assertGreater(routing.days("2026-10"), routing.days("2026-09-30"))
|
||||
|
||||
def test_no_code_reads_a_model_name(self):
|
||||
import os, re as _re
|
||||
self.assertFalse(os.path.exists(os.path.join(REPO, "sisi", "modelid.py")))
|
||||
self.assertFalse(os.path.exists(os.path.join(REPO, "canon", "model-words.json")))
|
||||
text = open(os.path.join(REPO, "sisi", "routing.py")).read()
|
||||
self.assertEqual(_re.findall(r"modelid|tier word|parse_model", text), [])
|
||||
|
||||
|
||||
class SupersessionTests(unittest.TestCase):
|
||||
def test_the_newer_version_wins_over_an_older_one_with_a_better_record_and_a_cheaper_plan(self):
|
||||
"""The owner's rule: no evidence exception, no price exception."""
|
||||
old = cand("prov/abc-5.3", plan="flat", cost=0.0)
|
||||
new = cand("prov/abc-5.4", plan="per-use", cost=9.0)
|
||||
records = attempts("prov/abc-5.3", 30, 30, difficulty=1)
|
||||
old = cand("prov/abc-old", rel=R1, plan="flat", cost=0.0)
|
||||
new = cand("prov/abc-new", rel=R2, plan="per-use", cost=9.0)
|
||||
records = attempts("prov/abc-old", 30, 30, difficulty=1)
|
||||
who, r = pick([old, new], records)
|
||||
self.assertEqual(who, "prov/abc-5.4")
|
||||
self.assertIn(("prov/abc-5.3", "superseded by prov/abc-5.4 (a newer version of the same class)"), r["passed_over"])
|
||||
self.assertEqual(who, "prov/abc-new")
|
||||
self.assertIn(("prov/abc-old", "superseded by prov/abc-new (a newer version of the same class)"), r["passed_over"])
|
||||
|
||||
def test_numeric_version_order(self):
|
||||
self.assertEqual(pick([cand("prov/abc-5.9"), cand("prov/abc-5.10")])[0], "prov/abc-5.10")
|
||||
self.assertEqual(pick([cand("prov/abc-5.3"), cand("prov/abc-5-4-20261101")])[0], "prov/abc-5-4-20261101")
|
||||
|
||||
def test_the_tier_word_before_or_after_the_version_is_one_class(self):
|
||||
self.assertEqual(pick([cand("prov/abc-5.3-flash"), cand("prov/abc-flash-5.4")])[0], "prov/abc-flash-5.4")
|
||||
def test_the_release_date_decides_not_the_name(self):
|
||||
"""A name that looks newer but was released earlier is the older model."""
|
||||
a = cand("prov/abc-9.9", rel=R1)
|
||||
b = cand("prov/abc-1.0", rel=R3)
|
||||
self.assertEqual(pick([a, b])[0], "prov/abc-1.0")
|
||||
|
||||
def test_different_classes_never_supersede_each_other(self):
|
||||
flash, std = cand("prov/abc-5.3-flash", cost=0.1), cand("prov/abc-5.4", cost=5.0)
|
||||
flash, std = cand("prov/abc-a", cls="flash", rel=R1, cost=0.1), cand("prov/abc-b", rel=R2, cost=5.0)
|
||||
who, r = pick([flash, std])
|
||||
self.assertEqual(who, "prov/abc-5.3-flash") # the cheaper class still competes
|
||||
self.assertEqual(who, "prov/abc-a") # the cheaper class still competes
|
||||
self.assertFalse([w for w, why in r["passed_over"] if why.startswith("superseded")])
|
||||
|
||||
def test_two_named_lines_of_one_maker_are_different_classes(self):
|
||||
a, b = cand("prov/abc-wonder-1.0", cost=1.0), cand("prov/abc-ember-1.3", cost=2.0)
|
||||
a, b = cand("prov/abc-w", cls="wonder", rel=R1, cost=1.0), cand("prov/abc-e", cls="ember", rel=R2, cost=2.0)
|
||||
who, r = pick([a, b])
|
||||
self.assertEqual(who, "prov/abc-wonder-1.0")
|
||||
self.assertEqual(who, "prov/abc-w")
|
||||
self.assertFalse([w for w, why in r["passed_over"] if why.startswith("superseded")])
|
||||
|
||||
def test_unknown_class_never_supersedes_or_is_superseded(self):
|
||||
a, b = cand("prov/abc-6.2-sol", cost=1.0), cand("prov/abc-6.3-sol", cost=2.0)
|
||||
self.assertIsNone(a["lineage"]["key"])
|
||||
who, r = pick([a, b])
|
||||
self.assertEqual(who, "prov/abc-6.2-sol")
|
||||
self.assertFalse([w for w, why in r["passed_over"] if why.startswith("superseded")])
|
||||
def test_different_makers_never_supersede_each_other(self):
|
||||
a, b = cand("prov/abc-a", rel=R1, cost=1.0), cand("prov/xyz-b", rel=R3, cost=2.0, maker="xyz")
|
||||
self.assertEqual(pick([a, b])[0], "prov/abc-a")
|
||||
|
||||
def test_a_recorded_class_makes_an_unknown_one_comparable(self):
|
||||
fact = {"class": "sol", "maker": "abc"}
|
||||
a, b = cand("prov/abc-6.2-sol", fact=fact, cost=1.0), cand("prov/abc-6.3-sol", fact=fact, cost=2.0)
|
||||
self.assertEqual(pick([a, b])[0], "prov/abc-6.3-sol")
|
||||
def test_a_model_with_nothing_recorded_is_never_compared(self):
|
||||
a, b = cand("prov/abc-a", known=False, cost=1.0), cand("prov/abc-b", rel=R3, cost=2.0)
|
||||
who, r = pick([a, b])
|
||||
self.assertEqual(who, "prov/abc-a")
|
||||
self.assertFalse([w for w, why in r["passed_over"] if why.startswith("superseded")])
|
||||
no_date = cand("prov/abc-c", cost=1.0) # class recorded, no date: not comparable with a dated one
|
||||
self.assertFalse([w for w, why in pick([no_date, cand("prov/abc-d", rel=R3)])[1]["passed_over"] if why.startswith("superseded")])
|
||||
|
||||
def test_the_newer_one_unusable_lets_the_older_compete_again(self):
|
||||
old, new = cand("prov/abc-5.3", cost=1.0), cand("prov/abc-5.4", cost=2.0)
|
||||
self.assertEqual(pick([old, new], availability={"prov/abc-5.4": {"reason": "limit", "retry_at": NOW + 99}})[0], "prov/abc-5.3")
|
||||
new2 = dict(new, usable=False, reason="not logged in")
|
||||
self.assertEqual(pick([old, new2])[0], "prov/abc-5.3")
|
||||
self.assertEqual(pick([old, new], avoid=[{"pattern": "5.4"}])[0], "prov/abc-5.3")
|
||||
spent = dict(new, plan="flat", allowance_pct_left=0)
|
||||
self.assertEqual(pick([old, spent])[0], "prov/abc-5.3")
|
||||
old, new = cand("prov/abc-old", rel=R1, cost=1.0), cand("prov/abc-new", rel=R2, cost=2.0)
|
||||
self.assertEqual(pick([old, new], availability={"prov/abc-new": {"reason": "limit", "retry_at": NOW + 99}})[0], "prov/abc-old")
|
||||
self.assertEqual(pick([old, dict(new, usable=False, reason="not logged in")])[0], "prov/abc-old")
|
||||
self.assertEqual(pick([old, new], avoid=[{"pattern": "abc-new"}])[0], "prov/abc-old")
|
||||
self.assertEqual(pick([old, dict(new, plan="flat", allowance_pct_left=0)])[0], "prov/abc-old")
|
||||
|
||||
def test_a_tried_newer_version_does_not_send_a_retry_back_to_the_older(self):
|
||||
old, new = cand("prov/abc-5.3", cost=1.0), cand("prov/abc-5.4", cost=2.0)
|
||||
who, r = pick([old, new], exclude=["prov/abc-5.4"])
|
||||
self.assertIsNone(who)
|
||||
old, new = cand("prov/abc-old", rel=R1, cost=1.0), cand("prov/abc-new", rel=R2, cost=2.0)
|
||||
self.assertIsNone(pick([old, new], exclude=["prov/abc-new"])[0])
|
||||
|
||||
def test_a_newer_version_with_a_thick_bad_record_never_sends_work_back_to_the_older(self):
|
||||
old, new, other = cand("prov/abc-5.3", cost=1.0), cand("prov/abc-5.4", cost=2.0), cand("prov/xyz-2.0", cost=3.0, maker="xyz")
|
||||
records = attempts("prov/abc-5.4", 10, 1, difficulty=1) + attempts("prov/xyz-2.0", 10, 10, difficulty=1)
|
||||
who, r = pick([old, new, other], records)
|
||||
self.assertEqual(who, "prov/xyz-2.0")
|
||||
who, r = pick([old, new], records)
|
||||
self.assertEqual(who, "prov/abc-5.4") # nobody else: the bad newer model is still not replaced by the older
|
||||
old, new = cand("prov/abc-old", rel=R1, cost=1.0), cand("prov/abc-new", rel=R2, cost=2.0)
|
||||
other = cand("prov/xyz-2", cost=3.0, maker="xyz")
|
||||
records = attempts("prov/abc-new", 10, 1, difficulty=1) + attempts("prov/xyz-2", 10, 10, difficulty=1)
|
||||
self.assertEqual(pick([old, new, other], records)[0], "prov/xyz-2")
|
||||
self.assertEqual(pick([old, new], records)[0], "prov/abc-new") # nobody else: still not the older version
|
||||
|
||||
def test_the_same_model_through_two_providers_is_one_model(self):
|
||||
old_a = cand("prova/abc-5.3", plan="flat", cost=0.0)
|
||||
new_a, new_b = cand("prova/abc-5.4", cost=5.0), cand("provb/abc-5.4", cost=2.0)
|
||||
old_a = cand("prova/abc-old", rel=R1, plan="flat", cost=0.0)
|
||||
new_a, new_b = cand("prova/abc-new", rel=R2, cost=5.0), cand("provb/abc-new", rel=R2, cost=2.0)
|
||||
who, r = pick([old_a, new_a, new_b])
|
||||
self.assertEqual(who, "provb/abc-5.4") # the existing cost comparison picks the provider
|
||||
self.assertEqual(sorted(w for w, why in r["passed_over"] if why.startswith("superseded")), ["prova/abc-5.3"])
|
||||
who, _ = pick([old_a, new_a, new_b], availability={"provb": {"reason": "limit", "retry_at": NOW + 9}})
|
||||
self.assertEqual(who, "prova/abc-5.4")
|
||||
self.assertEqual(who, "provb/abc-new") # the existing cost comparison picks the provider
|
||||
self.assertEqual(sorted(w for w, why in r["passed_over"] if why.startswith("superseded")), ["prova/abc-old"])
|
||||
self.assertEqual(pick([old_a, new_a, new_b], availability={"provb": {"reason": "limit", "retry_at": NOW + 9}})[0], "prova/abc-new")
|
||||
|
||||
def test_a_bare_host_alias_with_a_recorded_class_is_the_newest(self):
|
||||
alias = cand("abc", fact={"class": "standard", "maker": "abc"}, host_native=True, cost=9.0)
|
||||
versioned = cand("prov/abc-9.9", cost=0.1)
|
||||
def test_a_bare_host_alias_is_the_newest_of_its_class(self):
|
||||
alias = cand("abc", host_native=True, cost=9.0)
|
||||
versioned = cand("prov/abc-9", rel=R4, cost=0.1)
|
||||
self.assertEqual(pick([alias, versioned])[0], "abc")
|
||||
bare = cand("abc", host_native=True, cost=9.0) # class not recorded: no comparison
|
||||
self.assertEqual(pick([bare, versioned])[0], "prov/abc-9.9")
|
||||
self.assertEqual(pick([cand("abc", host_native=True, known=False, cost=9.0), versioned])[0], "prov/abc-9")
|
||||
|
||||
def test_guessed_classes_take_part_unless_the_config_says_only_recorded_ones(self):
|
||||
old, new = cand("prov/abc-5.3", cost=1.0), cand("prov/abc-5.4", cost=2.0)
|
||||
self.assertEqual(pick([old, new])[0], "prov/abc-5.4")
|
||||
self.assertEqual(pick([old, new], opts={"supersede_guessed": False})[0], "prov/abc-5.3")
|
||||
fact = {"class": "standard"}
|
||||
old_r, new_r = cand("prov/abc-5.3", fact=fact, cost=1.0), cand("prov/abc-5.4", fact=fact, cost=2.0)
|
||||
self.assertEqual(pick([old_r, new_r], opts={"supersede_guessed": False})[0], "prov/abc-5.4")
|
||||
|
||||
def test_the_asking_line_is_only_for_a_class_that_could_not_be_read(self):
|
||||
a, b = cand("prov/abc-6.2-sol", cost=1.0), cand("prov/abc-6.3-luna", cost=2.0)
|
||||
r = pick([a, b])[1]
|
||||
self.assertEqual(sorted(r["class_ask"]["classify"]), ["prov/abc-6.2-sol", "prov/abc-6.3-luna"])
|
||||
lone = pick([cand("prov/abc-6.2-sol"), cand("prov/xyz-1.0", maker="xyz")])[1]
|
||||
self.assertEqual(lone["class_ask"]["classify"], []) # no sibling of the same maker: it cannot matter
|
||||
guessed = pick([cand("prov/abc-5.3"), cand("prov/abc-5.4")])[1]
|
||||
self.assertEqual(guessed["class_ask"]["classify"], []) # read with confidence: no question
|
||||
fact = {"class": "sol", "maker": "abc"}
|
||||
settled = pick([cand("prov/abc-6.2-sol", fact=fact), cand("prov/abc-6.3-luna", fact=fact)])[1]
|
||||
self.assertEqual(settled["class_ask"]["classify"], [])
|
||||
def test_the_asking_line_names_workers_with_nothing_recorded_when_a_choice_is_made_among_several(self):
|
||||
a, b = cand("prov/abc-a", known=False), cand("prov/abc-b", rel=R2)
|
||||
self.assertEqual(pick([a, b])[1]["class_ask"]["classify"], ["prov/abc-a"])
|
||||
self.assertEqual(pick([a])[1]["class_ask"]["classify"], [])
|
||||
self.assertEqual(pick([cand("prov/abc-a", rel=R1), cand("prov/abc-b", rel=R2)])[1]["class_ask"]["classify"], [])
|
||||
|
||||
|
||||
class SupersessionPropertyTests(unittest.TestCase):
|
||||
def fleet(self, rng):
|
||||
cands, records, down = [], [], {}
|
||||
for maker in rng.sample(["abc", "xyz", "qrs"], rng.randint(1, 3)):
|
||||
for cls in rng.sample(["", "-flash", "-mini", "-wonder", "-pro"], rng.randint(1, 3)):
|
||||
for ver in rng.sample(["5.3", "5.4", "5.9", "5.10", "6", "5-4-20261101", "5.4-20250101"], rng.randint(1, 4)):
|
||||
for cls in rng.sample(["standard", "flash", "mini", "wonder"], rng.randint(1, 3)):
|
||||
for rel in rng.sample(["2026-01-05", "2026-03-01", "2026-06-01", "2026-09-30", "2026-10-02", None], rng.randint(1, 4)):
|
||||
for prov in rng.sample(["pa", "pb"], rng.randint(1, 2)):
|
||||
w = "%s/%s%s-%s" % (prov, maker, cls, ver)
|
||||
if cls == "-wonder":
|
||||
w = "%s/%s-wonder-%s" % (prov, maker, ver)
|
||||
if any(c["worker"] == w for c in cands):
|
||||
continue
|
||||
cands.append(cand(w, plan=rng.choice(["flat", "per-use", None]),
|
||||
cost=rng.choice([None, 0.1, 1.0, 5.0]), maker=maker,
|
||||
allowance_pct_left=rng.choice([None, 0, 50])))
|
||||
w = "%s/%s-%s-%s" % (prov, maker, cls, rel)
|
||||
c = cand(w, cls=cls, rel=rel, maker=maker, plan=rng.choice(["flat", "per-use", None]),
|
||||
cost=rng.choice([None, 0.1, 1.0, 5.0]), allowance_pct_left=rng.choice([None, 0, 50]),
|
||||
known=rng.random() < 0.9)
|
||||
cands.append(c)
|
||||
if rng.random() < 0.15:
|
||||
down[w] = {"reason": "limit", "retry_at": NOW + 99}
|
||||
for d in (1, 2, 3):
|
||||
@@ -161,20 +188,16 @@ class SupersessionPropertyTests(unittest.TestCase):
|
||||
checked = 0
|
||||
for _ in range(300 * ITERS):
|
||||
cands, records, down = self.fleet(rng)
|
||||
if not cands:
|
||||
continue
|
||||
d = rng.choice([1, 2, 3])
|
||||
who, r = pick(cands, records, d, availability=down)
|
||||
who, r = pick(cands, records, rng.choice([1, 2, 3]), availability=down)
|
||||
if who is None:
|
||||
continue
|
||||
chosen = next(c for c in cands if c["worker"] == who)
|
||||
lc = chosen["lineage"]
|
||||
for c in cands:
|
||||
if c is chosen or not self.usable(c, down):
|
||||
if c is chosen or not self.usable(c, down) or not lc["key"]:
|
||||
continue
|
||||
lo = c["lineage"]
|
||||
if lo["key"] == lc["key"]:
|
||||
self.assertLessEqual(modelid.compare(lo, lc), 0, (who, c["worker"]))
|
||||
if c["lineage"]["key"] == lc["key"]:
|
||||
self.assertLessEqual(routing.compare_release(c["lineage"], lc), 0, (who, c["worker"]))
|
||||
checked += 1
|
||||
for w, why in r["passed_over"]:
|
||||
if why.startswith("superseded by "):
|
||||
@@ -182,7 +205,8 @@ class SupersessionPropertyTests(unittest.TestCase):
|
||||
a = next(c for c in cands if c["worker"] == w)["lineage"]
|
||||
b = next(c for c in cands if c["worker"] == newer)["lineage"]
|
||||
self.assertEqual(a["key"], b["key"], "a model never supersedes one of another maker or class")
|
||||
self.assertGreater(modelid.compare(b, a), 0)
|
||||
self.assertIsNotNone(a["key"])
|
||||
self.assertGreater(routing.compare_release(b, a), 0)
|
||||
self.assertGreater(checked, 100)
|
||||
|
||||
def test_adding_a_newer_version_of_the_chosen_model_never_makes_the_choice_an_older_model_of_that_class(self):
|
||||
@@ -190,40 +214,27 @@ class SupersessionPropertyTests(unittest.TestCase):
|
||||
done = 0
|
||||
for _ in range(200 * ITERS):
|
||||
cands, records, down = self.fleet(rng)
|
||||
if not cands:
|
||||
continue
|
||||
d = rng.choice([1, 2, 3])
|
||||
who, _r = pick(cands, records, d, availability=down)
|
||||
if who is None:
|
||||
continue
|
||||
chosen = next(c for c in cands if c["worker"] == who)
|
||||
lc = chosen["lineage"]
|
||||
if not lc["version"] or lc["date"]:
|
||||
continue
|
||||
ver = ".".join(str(x) for x in lc["version"][:1] + (lc["version"][1] + 1 if len(lc["version"]) > 1 else 1,))
|
||||
prov = who.split("/")[0]
|
||||
maker = lc["maker"]
|
||||
tail = "" if lc["class"] == "standard" else "-" + lc["class"]
|
||||
new_w = "pc/%s%s-%s" % (maker, tail, ver) if lc["line"] == "" else None
|
||||
if new_w is None or any(c["worker"] == new_w for c in cands):
|
||||
continue
|
||||
new = cand(new_w, maker=chosen["maker"], cost=rng.choice([None, 0.1, 5.0]))
|
||||
if new["lineage"]["key"] != lc["key"] or modelid.compare(new["lineage"], lc) <= 0:
|
||||
lc = next(c for c in cands if c["worker"] == who)["lineage"]
|
||||
if not lc["key"] or not lc["released"]:
|
||||
continue
|
||||
new = cand("pc/newest", cls=lc["class"], maker=lc["maker"], rel="2027-01-01", cost=rng.choice([None, 0.1, 5.0]))
|
||||
after, _ = pick(cands + [new], records, d, availability=down)
|
||||
if after is None:
|
||||
continue
|
||||
got = next(c for c in cands + [new] if c["worker"] == after)["lineage"]
|
||||
if got["key"] == lc["key"]:
|
||||
self.assertGreaterEqual(modelid.compare(got, lc), 0, (who, after))
|
||||
self.assertGreaterEqual(routing.compare_release(got, lc), 0, (who, after))
|
||||
done += 1
|
||||
self.assertGreater(done, 30)
|
||||
|
||||
def test_a_result_read_as_unknown_never_triggers_supersession(self):
|
||||
def test_a_model_with_nothing_recorded_never_triggers_supersession(self):
|
||||
rng = random.Random(5)
|
||||
for _ in range(200 * ITERS):
|
||||
ids = ["prov/abc-%d.%d-%s" % (rng.randint(1, 9), rng.randint(0, 9), rng.choice(["sol", "luna", "astra"])) for _ in range(rng.randint(2, 5))]
|
||||
cands = [cand(w, cost=rng.choice([None, 1.0, 2.0])) for w in dict.fromkeys(ids)]
|
||||
for _ in range(100 * ITERS):
|
||||
cands = [cand("prov/m-%d" % i, known=False, cost=rng.choice([None, 1.0, 2.0])) for i in range(rng.randint(2, 5))]
|
||||
who, r = pick(cands)
|
||||
self.assertFalse([w for w, why in r["passed_over"] if why.startswith("superseded")])
|
||||
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
"""Reading a model id: maker, line, class, version, and which of two is the more recently released.
|
||||
Fixtures are invented ids shaped like real ones. Requirement ids: R-7.2-1, R-7.2-2, R-7.2-3."""
|
||||
import json, os, random, unittest
|
||||
from support import *
|
||||
from sisi import modelid
|
||||
|
||||
WORDS = json.load(open(os.path.join(REPO, "canon", "model-words.json")))
|
||||
|
||||
|
||||
def p(worker, **kw):
|
||||
return modelid.parse(worker, WORDS, **kw)
|
||||
|
||||
|
||||
def r(worker, **kw):
|
||||
return modelid.resolve(worker, WORDS, **kw)
|
||||
|
||||
|
||||
class ParseTests(unittest.TestCase):
|
||||
def test_version_line_and_class_from_the_name(self):
|
||||
"""R-7.2-1: the class is read from the id; no tier word means the line's standard model."""
|
||||
a = p("prov/abc-5.3")
|
||||
self.assertEqual((a["maker"], a["class"], a["version"], a["confident"]), ("abc", "standard", (5, 3), True))
|
||||
self.assertEqual(p("prov/abc-5.3-flash")["class"], "flash")
|
||||
|
||||
def test_a_tier_word_before_or_after_the_version_parses_the_same(self):
|
||||
after, before = p("prov/abc-5.4-flash"), p("prov/abc-flash-5.4")
|
||||
for k in ("maker", "line", "class", "label", "version", "confident"):
|
||||
self.assertEqual(after[k], before[k], k)
|
||||
|
||||
def test_versions_compare_numerically(self):
|
||||
"""5.10 is newer than 5.9, not older (the string order would say so)."""
|
||||
self.assertGreater(modelid.compare(r("prov/abc-5.10"), r("prov/abc-5.9")), 0)
|
||||
self.assertLess(modelid.compare(r("prov/abc-5.9"), r("prov/abc-5.10")), 0)
|
||||
self.assertEqual(modelid.compare(r("prov/abc-5"), r("prov/abc-5.0")), 0)
|
||||
|
||||
def test_a_dated_suffix_compares_as_a_date_and_does_not_disturb_the_version(self):
|
||||
dated = p("prov/abc-5-4-20261101")
|
||||
self.assertEqual((dated["version"], dated["date"], dated["class"]), ((5, 4), "2026-11-01", "standard"))
|
||||
self.assertEqual(p("prov/abc-5.4-2026-11-01")["date"], "2026-11-01")
|
||||
self.assertGreater(modelid.compare(r("prov/abc-5-4-20261101"), r("prov/abc-5.3")), 0)
|
||||
self.assertEqual(modelid.compare(r("prov/abc-5-4-20261101"), r("prov/abc-5.4")), 0)
|
||||
self.assertGreater(modelid.compare(r("prov/abc-5.4-20261101"), r("prov/abc-5.4-20260901")), 0)
|
||||
self.assertGreater(modelid.compare(r("prov/abc-20261101"), r("prov/abc-20250301")), 0)
|
||||
self.assertEqual(modelid.compare(r("prov/abc-20261101"), r("prov/abc-5.3")), 0) # not comparable
|
||||
self.assertIsNone(p("prov/abc-5.4-20261345")["date"]) # not a date
|
||||
|
||||
def test_two_tier_words_make_one_class_and_letter_prefixed_versions_read(self):
|
||||
self.assertEqual(p("prov/abc-flash-lite-5.4")["class"], "flash-lite")
|
||||
self.assertEqual(p("prov/xyz-v4.1-pro")["version"], (4, 1))
|
||||
self.assertEqual(p("prov/xyz-k2.7-code")["class"], "code")
|
||||
self.assertEqual(p("prov/xyz3.8-flash")["version"], (3, 8))
|
||||
|
||||
def test_ignored_words_are_neither_line_nor_class(self):
|
||||
self.assertEqual(p("prov/abc-5.4-preview-free")["class"], "standard")
|
||||
self.assertEqual(p("prov/abc-5.4-flash-latest")["class"], "flash")
|
||||
|
||||
def test_a_named_line_is_the_class_label(self):
|
||||
"""Item 7: for a maker whose lines are the classes the line name is the class label."""
|
||||
a, b = p("prov/abc-wonder-1.0"), p("prov/abc-wonder-full-1.0")
|
||||
self.assertEqual((a["line"], a["label"]), ("wonder", "wonder"))
|
||||
self.assertEqual((b["line"], b["class"], b["label"]), ("wonder", "full", "wonder-full"))
|
||||
self.assertEqual(p("prov/abc-ember-1.0")["label"], "ember")
|
||||
|
||||
def test_what_cannot_be_read_with_confidence_says_unknown(self):
|
||||
"""R-7.2-3: no version, or a word after the version that the data does not know: class unknown."""
|
||||
for ident in ("prov/xyz-mini", "prov/abc", "prov/abc-6.2-sol", "prov/abc-3-5-sonnet", "prov/5.4"):
|
||||
got = p(ident)
|
||||
self.assertFalse(got["confident"], ident)
|
||||
self.assertEqual(got["class"], "unknown", ident)
|
||||
self.assertIsNone(r(ident)["key"], ident)
|
||||
self.assertEqual(r(ident)["source"], "unknown", ident)
|
||||
|
||||
def test_tier_words_are_data_not_code(self):
|
||||
"""Adding a tier word to the data changes the reading; the code names none."""
|
||||
self.assertFalse(p("prov/abc-5.4-sol")["confident"])
|
||||
got = modelid.parse("prov/abc-5.4-sol", {"tiers": ["sol"], "ignore": []})
|
||||
self.assertEqual((got["class"], got["confident"]), ("sol", True))
|
||||
text = open(os.path.join(REPO, "sisi", "modelid.py")).read()
|
||||
for word in WORDS["tiers"] + WORDS["ignore"]:
|
||||
self.assertNotRegex(text.replace("standard", ""), r'"%s"' % word)
|
||||
|
||||
def test_a_recorded_fact_beats_the_reading(self):
|
||||
got = r("prov/abc-6.2-sol", fact={"class": "sol", "maker": "abc"})
|
||||
self.assertEqual((got["source"], got["class"], got["key"]), ("fact", "sol", ("abc", "", "sol")))
|
||||
flipped = r("prov/abc-5.3-flash", fact={"class": "standard"})
|
||||
self.assertEqual(flipped["class"], "standard")
|
||||
self.assertEqual(r("prov/abc-5.4", fact={"family": "wonder", "class": "full"})["label"], "wonder-full")
|
||||
self.assertEqual(r("prov/abc-5.4", fact={"family": "wonder", "class": "wonder-full"})["label"], "wonder-full")
|
||||
self.assertEqual(r("prov/abc-5.4")["source"], "guess")
|
||||
|
||||
def test_a_recorded_release_date_beats_version_numbers(self):
|
||||
old_but_later = r("prov/abc-5.3", fact={"released": "2026-09-01"})
|
||||
new_but_earlier = r("prov/abc-5.4", fact={"released": "2026-03-01"})
|
||||
self.assertGreater(modelid.compare(old_but_later, new_but_earlier), 0)
|
||||
self.assertGreater(modelid.compare(r("prov/abc-5.4"), r("prov/abc-5.3")), 0)
|
||||
|
||||
def test_a_bare_host_alias_is_the_newest_of_its_class_once_the_class_is_recorded(self):
|
||||
alias = r("abc", host_native=True, fact={"class": "standard", "maker": "abc"})
|
||||
self.assertTrue(alias["alias"])
|
||||
self.assertGreater(modelid.compare(alias, r("prov/abc-9.9")), 0)
|
||||
self.assertEqual(alias["key"], r("prov/abc-5.3")["key"])
|
||||
unrecorded = r("abc", host_native=True)
|
||||
self.assertFalse(unrecorded["alias"])
|
||||
self.assertIsNone(unrecorded["key"])
|
||||
|
||||
def test_the_parser_never_raises_and_compare_is_antisymmetric(self):
|
||||
rng = random.Random(7)
|
||||
pool = ["abc", "xyz", "5", "4", "10", "3.2", "flash", "mini", "pro", "preview", "20261101", "v2", "k3", "x", "", "-", "70b", "sol", "4o", "2026", "11", "01"]
|
||||
for _ in range(500 * ITERS):
|
||||
ident = "prov/" + "-".join(rng.choice(pool) for _ in range(rng.randint(0, 6)))
|
||||
a, b = r(ident), r("prov/" + "-".join(rng.choice(pool) for _ in range(rng.randint(0, 6))))
|
||||
self.assertEqual(modelid.compare(a, b), -modelid.compare(b, a), ident)
|
||||
if a["source"] == "unknown":
|
||||
self.assertIsNone(a["key"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,128 @@
|
||||
"""`sisi workers classify`: the question for a cheap, fast worker and the validated recording of its answer.
|
||||
Invented ids. Requirement ids: R-7.2-1, R-7.2-3."""
|
||||
import json, os, unittest
|
||||
from support import *
|
||||
from test_worker_models import ModelCase
|
||||
|
||||
MODELS = ("abc-old", "abc-new", "xyz-one")
|
||||
ANSWER = {"workers": {"muse/abc-old": {"maker": "abc", "class": "standard", "released": "2026-03"},
|
||||
"muse/abc-new": {"maker": "abc", "class": "standard", "released": "2026-09-01"},
|
||||
"muse/xyz-one": {"maker": "xyz", "class": "unknown", "released": "unknown"}},
|
||||
"classes": {"abc": ["standard", "flash"]}}
|
||||
|
||||
|
||||
class ClassifyCase(ModelCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.seed([("muse/abc-old", 12, 12), ("muse/abc-new", 3, 3), ("muse/xyz-one", 12, 12)], difficulty=2)
|
||||
self.file = os.path.join(self.tmp, "answer.json")
|
||||
|
||||
def classify(self, *args):
|
||||
return self.sisi("workers", "classify", *args, env=self.env(MODELS))
|
||||
|
||||
def answer(self, obj, wrap=lambda t: t):
|
||||
open(self.file, "w").write(wrap(obj if isinstance(obj, str) else json.dumps(obj)))
|
||||
return self.classify("--record", self.file, "--by", "cheap-worker-x")
|
||||
|
||||
def stored(self):
|
||||
p = os.path.join(self.data, "worker-models.json")
|
||||
return json.load(open(p)) if os.path.exists(p) else {}
|
||||
|
||||
|
||||
class QuestionTests(ClassifyCase):
|
||||
def test_it_prints_a_short_instruction_and_the_ids_that_have_no_classification(self):
|
||||
out = self.classify().stdout.splitlines()
|
||||
ids = [l for l in out if l.startswith("muse/")]
|
||||
self.assertEqual(sorted(ids), ["muse/abc-new", "muse/abc-old", "muse/xyz-one"])
|
||||
self.assertLessEqual(len(out) - len(ids), 15, out)
|
||||
text = "\n".join(out)
|
||||
for must in ("maker", "class", "release date", "unknown", "JSON"):
|
||||
self.assertIn(must, text)
|
||||
|
||||
def test_classified_workers_are_not_asked_again_and_nothing_is_left_to_ask_at_the_end(self):
|
||||
self.record("muse/abc-old", "standard", "2026-03-01", models=MODELS)
|
||||
ids = [l for l in self.classify().stdout.splitlines() if l.startswith("muse/")]
|
||||
self.assertEqual(sorted(ids), ["muse/abc-new", "muse/xyz-one"])
|
||||
self.assertEqual(self.answer({"workers": {w: ANSWER["workers"][w] for w in ids}}).returncode, 0)
|
||||
self.assertIn("every routable worker is classified", self.classify().stdout)
|
||||
|
||||
|
||||
class RecordTests(ClassifyCase):
|
||||
def test_a_valid_answer_is_stored_with_the_classifying_worker_as_the_source(self):
|
||||
r = self.answer(ANSWER)
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
self.assertIn("3 classification(s) (1 unknown) and 1 class order(s)", r.stdout)
|
||||
data = self.stored()
|
||||
self.assertEqual(data["models"]["muse/abc-new"]["source"], "classified by cheap-worker-x")
|
||||
self.assertEqual((data["models"]["muse/abc-old"]["class"], data["models"]["muse/abc-old"]["released"]), ("standard", "2026-03"))
|
||||
self.assertEqual(data["classes"]["abc"]["order"], ["standard", "flash"])
|
||||
self.assertEqual(data["models"]["muse/xyz-one"]["class"], "unknown")
|
||||
self.assertNotIn("released", data["models"]["muse/xyz-one"])
|
||||
|
||||
def test_an_answer_wrapped_in_prose_or_a_code_fence_is_read(self):
|
||||
r = self.answer(ANSWER, wrap=lambda t: "Here you go:\n```json\n%s\n```\nDone." % t)
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
|
||||
def test_an_id_that_was_not_asked_about_is_refused_and_nothing_is_recorded(self):
|
||||
bad = json.loads(json.dumps(ANSWER))
|
||||
bad["workers"]["muse/never-heard-of-it"] = {"maker": "abc", "class": "standard", "released": "2026-01"}
|
||||
r = self.answer(bad)
|
||||
self.assertEqual(r.returncode, 1)
|
||||
self.assertIn("muse/never-heard-of-it", r.stderr)
|
||||
self.assertEqual(self.stored(), {})
|
||||
self.record("muse/abc-old", "standard", models=MODELS) # an id that is already classified is not asked about either
|
||||
r = self.answer({"workers": {"muse/abc-old": ANSWER["workers"]["muse/abc-old"]}})
|
||||
self.assertEqual(r.returncode, 1)
|
||||
|
||||
def test_malformed_answers_are_refused_and_nothing_is_recorded(self):
|
||||
for bad in ("not json at all", "[1, 2]", json.dumps({"workers": []}),
|
||||
json.dumps({"workers": {"muse/abc-old": {"maker": "abc", "class": "so l", "released": "2026-01"}}}),
|
||||
json.dumps({"workers": {"muse/abc-old": {"maker": "abc", "class": "x", "released": "last year"}}}),
|
||||
json.dumps({"workers": {"muse/abc-old": "standard"}})):
|
||||
self.assertEqual(self.answer(bad).returncode, 1, bad)
|
||||
self.assertEqual(self.stored(), {})
|
||||
self.assertEqual(self.classify("--record", os.path.join(self.tmp, "missing.json")).returncode, 1)
|
||||
|
||||
def test_a_recorded_class_order_is_never_overwritten_by_an_answer(self):
|
||||
self.sisi("workers", "classes", "abc", "flash", "standard", "--source", "owner", env=self.env(MODELS))
|
||||
self.answer(ANSWER)
|
||||
self.assertEqual(self.stored()["classes"]["abc"]["order"], ["flash", "standard"])
|
||||
|
||||
def test_an_unknown_answer_changes_nothing_in_routing_and_is_not_asked_again(self):
|
||||
def route():
|
||||
return self.sisi("route", "--kind", "impl", "--difficulty", "2", "--explain", env=self.env(MODELS)).stdout
|
||||
before = route()
|
||||
self.answer({"workers": {w: {"maker": "unknown", "class": "unknown", "released": "unknown"} for w in ANSWER["workers"]}})
|
||||
after = route()
|
||||
strip = lambda t: [l for l in t.splitlines() if not l.startswith("sisi:")]
|
||||
self.assertEqual(strip(before), strip(after))
|
||||
self.assertIn("every routable worker is classified", self.classify().stdout)
|
||||
self.assertNotIn("sisi: no maker", after)
|
||||
|
||||
def test_after_recording_the_newest_version_wins(self):
|
||||
self.answer(ANSWER)
|
||||
r = self.sisi("route", "--kind", "impl", "--difficulty", "2", "--explain", env=self.env(MODELS))
|
||||
self.assertEqual(r.stdout.splitlines()[0], "muse/abc-new", r.stdout)
|
||||
self.assertIn("superseded by muse/abc-new", r.stdout)
|
||||
self.assertIn("the record of its predecessor muse/abc-old", r.stdout)
|
||||
|
||||
|
||||
class AskingLineTests(ClassifyCase):
|
||||
def test_route_asks_only_when_an_unclassified_worker_is_in_the_running(self):
|
||||
r = self.sisi("route", "--kind", "impl", "--difficulty", "2", env=self.env(MODELS))
|
||||
self.assertEqual(len([l for l in r.stdout.splitlines() if "sisi workers classify" in l]), 1, r.stdout)
|
||||
self.assertLessEqual(len(r.stdout.splitlines()), 7)
|
||||
self.answer(ANSWER)
|
||||
r = self.sisi("route", "--kind", "impl", "--difficulty", "2", env=self.env(MODELS))
|
||||
self.assertNotIn("sisi workers classify", r.stdout)
|
||||
|
||||
def test_session_start_names_the_unclassified_workers_in_its_one_facts_line(self):
|
||||
from sisi import workers
|
||||
r = self.sisi("tick", stdin=json.dumps({"session_id": "s-cls", "cwd": self.proj, "source": "startup", "model": "mystery-9"}),
|
||||
env=self.env(MODELS))
|
||||
lines = [l for l in r.stdout.splitlines() if "worker facts" in l or "sisi workers classify" in l]
|
||||
self.assertEqual(len(lines), 1, r.stdout)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
+70
-73
@@ -1,7 +1,7 @@
|
||||
"""Model lines in the worker commands: the class a lead agent records beats the parser, and `sisi workers`
|
||||
shows maker, class and recency for each routable worker. Fixtures are invented ids shaped like real ones.
|
||||
Requirement ids: R-7.2-1, R-7.2-3."""
|
||||
import json, os, stat, unittest
|
||||
"""The worker commands and the model facts: the maker, class and release date a cheap worker researched are
|
||||
recorded with `sisi workers fact`, shown by `sisi workers`, and drive `sisi route`. sisi reads nothing from a name.
|
||||
Invented ids. Requirement ids: R-7.2-1, R-7.2-3."""
|
||||
import json, os, stat, subprocess, unittest
|
||||
from support import *
|
||||
|
||||
FAKE_MUSE = """#!/bin/sh
|
||||
@@ -44,9 +44,15 @@ class ModelCase(SisiCase):
|
||||
os.chmod(path, os.stat(path).st_mode | stat.S_IXUSR)
|
||||
return dict(PATH=bindir, MUSE_MODELS=" ".join(models))
|
||||
|
||||
def route(self, difficulty=1, *extra, models=("abc-5.3", "abc-5.4")):
|
||||
r = self.sisi("route", "--kind", "impl", "--difficulty", str(difficulty), *extra, env=self.env(models))
|
||||
return r
|
||||
def record(self, worker, cls, released=None, maker="abc", models=None):
|
||||
args = ["workers", "fact", worker, "--maker", maker, "--class", cls, "--source", "fixture research"]
|
||||
if released:
|
||||
args += ["--released", released]
|
||||
r = self.sisi(*args, env=self.env(models))
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
|
||||
def route(self, difficulty=1, *extra, models=("abc-old", "abc-new")):
|
||||
return self.sisi("route", "--kind", "impl", "--difficulty", str(difficulty), *extra, env=self.env(models))
|
||||
|
||||
def listing(self):
|
||||
r = self.sisi("workers", env=self.env())
|
||||
@@ -55,39 +61,26 @@ class ModelCase(SisiCase):
|
||||
|
||||
|
||||
class FactTests(ModelCase):
|
||||
def test_a_class_fact_is_recorded_with_its_source_and_shown(self):
|
||||
"""R-7.2-3: the lead agent's decision about a model is stored, with its source, and shown."""
|
||||
self.seed([("prov/abc-6.2-sol", 9, 9), ("prov/abc-5.3", 9, 9)])
|
||||
before = self.listing()
|
||||
self.assertIn("prov/abc-6.2-sol: class unknown", before)
|
||||
self.assertIn("prov/abc-5.3: maker abc, class standard (a guess read from the id)", before)
|
||||
r = self.sisi("workers", "fact", "prov/abc-6.2-sol", "--class", "sol", "--released", "2026-11-01",
|
||||
"--source", "lead agent, read the maker's page", env=self.env())
|
||||
self.assertEqual(r.returncode, 0, r.stderr)
|
||||
stored = json.load(open(os.path.join(self.data, "worker-models.json")))["models"]["prov/abc-6.2-sol"]
|
||||
self.assertEqual((stored["class"], stored["released"], stored["source"]),
|
||||
("sol", "2026-11-01", "lead agent, read the maker's page"))
|
||||
after = self.listing()
|
||||
self.assertIn("prov/abc-6.2-sol: maker abc, class sol (recorded); released 2026-11-01 (recorded), version 6.2", after)
|
||||
|
||||
def test_a_recorded_class_beats_the_parser(self):
|
||||
self.seed([("prov/abc-5.3-flash", 9, 9)])
|
||||
self.assertIn("class flash (a guess", self.listing())
|
||||
self.sisi("workers", "fact", "prov/abc-5.3-flash", "--class", "standard", "--source", "lead", env=self.env())
|
||||
self.assertIn("class standard (recorded)", self.listing())
|
||||
def test_a_maker_class_and_release_date_are_recorded_with_their_source_and_shown(self):
|
||||
"""R-7.2-3: what a cheap worker researched about a model is stored, with its source, and shown."""
|
||||
self.seed([("prov/abc-x", 9, 9)])
|
||||
self.assertIn("prov/abc-x: no maker and class recorded", self.listing())
|
||||
self.record("prov/abc-x", "flash", "2026-11-01")
|
||||
stored = json.load(open(os.path.join(self.data, "worker-models.json")))["models"]["prov/abc-x"]
|
||||
self.assertEqual((stored["class"], stored["maker"], stored["released"], stored["source"]),
|
||||
("flash", "abc", "2026-11-01", "fixture research"))
|
||||
self.assertIn("prov/abc-x: maker abc, class flash; released 2026-11-01", self.listing())
|
||||
|
||||
def test_bad_input_is_refused_and_nothing_is_recorded(self):
|
||||
self.seed([("prov/abc-5.3", 9, 9)])
|
||||
self.seed([("prov/abc-x", 9, 9)])
|
||||
for args in (("--class", "sol"), ("--class", "so l", "--source", "x"), ("--released", "next week", "--source", "x"),
|
||||
("--released", "2026-13-40", "--source", "x")):
|
||||
r = self.sisi("workers", "fact", "prov/abc-5.3", *args, env=self.env())
|
||||
self.assertEqual(r.returncode, 1, args)
|
||||
self.assertEqual(self.sisi("workers", "fact", "prov/abc-x", *args, env=self.env()).returncode, 1, args)
|
||||
self.assertFalse(os.path.exists(os.path.join(self.data, "worker-models.json")))
|
||||
|
||||
def test_the_fact_file_is_committed_with_the_other_worker_data(self):
|
||||
self.seed([("prov/abc-5.3", 9, 9)])
|
||||
self.sisi("workers", "fact", "prov/abc-5.3", "--class", "standard", "--source", "lead", env=self.env())
|
||||
import subprocess
|
||||
self.seed([("prov/abc-x", 9, 9)])
|
||||
self.record("prov/abc-x", "flash")
|
||||
out = subprocess.run(["git", "status", "--porcelain"], cwd=self.data, capture_output=True, text=True).stdout
|
||||
self.assertNotIn("worker-models.json", out)
|
||||
|
||||
@@ -95,69 +88,73 @@ class FactTests(ModelCase):
|
||||
class RouteSupersessionTests(ModelCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.priced = False
|
||||
self.ready = False
|
||||
|
||||
def route(self, difficulty=1, *extra, models=("abc-5.3", "abc-5.4")):
|
||||
if not self.priced: # a model is routable once it has a record, a price or a standing
|
||||
self.priced = True
|
||||
for w, price in (("muse/abc-5.3", "0.5"), ("muse/abc-5.4", "1")): # the older is the cheaper
|
||||
def route(self, difficulty=1, *extra, models=("abc-old", "abc-new")):
|
||||
if not self.ready: # a model is routable once it has a record, a price or a standing
|
||||
self.ready = True
|
||||
for w, price, rel in (("muse/abc-old", "0.5", "2026-03-01"), ("muse/abc-new", "1", "2026-09-01")): # the older is the cheaper
|
||||
self.sisi("workers", "fact", w, "--price", price, "--source", "fixture", env=self.env(models))
|
||||
self.record(w, "standard", rel, models=models)
|
||||
return super().route(difficulty, *extra, models=models)
|
||||
|
||||
def test_route_uses_the_newest_version_though_the_older_has_the_record(self):
|
||||
"""R-7.2-1: the newest usable version of a class is always taken; --explain says what it replaced."""
|
||||
self.seed([("muse/abc-5.3", 30, 30)], difficulty=1)
|
||||
self.seed([("muse/abc-old", 30, 30)], difficulty=1)
|
||||
r = self.route(1, "--explain")
|
||||
self.assertEqual(r.stdout.splitlines()[0], "muse/abc-5.4", r.stdout)
|
||||
self.assertIn("superseded by muse/abc-5.4", r.stdout)
|
||||
self.assertEqual(r.stdout.splitlines()[0], "muse/abc-new", r.stdout)
|
||||
self.assertIn("superseded by muse/abc-new", r.stdout)
|
||||
|
||||
def test_the_older_version_is_back_while_the_newer_is_marked_down(self):
|
||||
self.seed([("muse/abc-5.3", 30, 30)], difficulty=1)
|
||||
self.seed([("muse/abc-old", 30, 30)], difficulty=1)
|
||||
self.route(1)
|
||||
self.sisi("workers", "down", "muse/abc-5.4", "--reason", "limit", "--until", "2099-01-02", env=self.env(("abc-5.3", "abc-5.4")))
|
||||
self.assertEqual(self.route(1).stdout.splitlines()[0], "muse/abc-5.3")
|
||||
self.sisi("workers", "up", "muse/abc-5.4", env=self.env(("abc-5.3", "abc-5.4")))
|
||||
self.assertEqual(self.route(1).stdout.splitlines()[0], "muse/abc-5.4")
|
||||
env = self.env(("abc-old", "abc-new"))
|
||||
self.sisi("workers", "down", "muse/abc-new", "--reason", "limit", "--until", "2099-01-02", env=env)
|
||||
self.assertEqual(self.route(1).stdout.splitlines()[0], "muse/abc-old")
|
||||
self.sisi("workers", "up", "muse/abc-new", env=env)
|
||||
self.assertEqual(self.route(1).stdout.splitlines()[0], "muse/abc-new")
|
||||
|
||||
def test_only_recorded_classes_when_the_config_says_so(self):
|
||||
self.seed([("muse/abc-5.3", 30, 30)], difficulty=1)
|
||||
os.makedirs(self.data, exist_ok=True)
|
||||
json.dump({"route": {"supersede_guessed": False}}, open(os.path.join(self.data, "config.json"), "w"))
|
||||
self.assertEqual(self.route(1).stdout.splitlines()[0], "muse/abc-5.3")
|
||||
for w in ("muse/abc-5.3", "muse/abc-5.4"):
|
||||
self.sisi("workers", "fact", w, "--class", "standard", "--source", "lead", env=self.env(("abc-5.3", "abc-5.4")))
|
||||
self.assertEqual(self.route(1).stdout.splitlines()[0], "muse/abc-5.4")
|
||||
|
||||
def test_the_lead_agent_is_asked_once_for_a_class_that_cannot_be_read_and_then_not(self):
|
||||
"""A class read with confidence raises no question; an unreadable one does, in one line, until recorded."""
|
||||
models = ("abc-6.2-sol", "abc-6.3-luna")
|
||||
self.seed([("muse/abc-6.2-sol", 12, 12), ("muse/abc-6.3-luna", 12, 12)], difficulty=1)
|
||||
r = self.route(1, models=models)
|
||||
asks = [l for l in r.stdout.splitlines() if "cannot be read from its id" in l]
|
||||
def test_the_lead_agent_is_asked_once_for_workers_with_nothing_recorded_and_then_not(self):
|
||||
models = ("abc-old", "abc-new")
|
||||
self.seed([("muse/abc-old", 12, 12), ("muse/abc-new", 12, 12)], difficulty=1)
|
||||
r = self.route(1, models=models) # route() records facts first
|
||||
self.assertNotIn("no maker, class", r.stdout)
|
||||
self.seed([("muse/abc-zzz", 12, 12)], difficulty=1)
|
||||
r = self.sisi("route", "--kind", "impl", "--difficulty", "1", env=self.env(models + ("abc-zzz",)))
|
||||
asks = [l for l in r.stdout.splitlines() if "no maker, class and release date are recorded" in l]
|
||||
self.assertEqual(len(asks), 1, r.stdout)
|
||||
self.assertIn("muse/abc-zzz", asks[0])
|
||||
self.assertLessEqual(len(r.stdout.splitlines()), 7, r.stdout)
|
||||
for w, c in (("muse/abc-6.2-sol", "sol"), ("muse/abc-6.3-luna", "luna")):
|
||||
self.sisi("workers", "fact", w, "--class", c, "--maker", "abc", "--source", "lead", env=self.env(models))
|
||||
self.assertNotIn("cannot be read", self.route(1, models=models).stdout)
|
||||
self.seed([("muse/abc-5.3", 12, 12), ("muse/abc-5.4", 12, 12)], difficulty=1)
|
||||
self.assertNotIn("cannot be read", self.route(1).stdout)
|
||||
self.record("muse/abc-zzz", "flash", "2026-01-01", models=models + ("abc-zzz",))
|
||||
self.assertNotIn("no maker, class", self.sisi("route", "--kind", "impl", "--difficulty", "1",
|
||||
env=self.env(models + ("abc-zzz",))).stdout)
|
||||
|
||||
|
||||
class RouteInheritanceTests(ModelCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.ready = False
|
||||
|
||||
def route(self, difficulty=1, *extra, models=("abc-old", "abc-new")):
|
||||
if not self.ready:
|
||||
self.ready = True
|
||||
self.record("muse/abc-old", "standard", "2026-03-01", models=models)
|
||||
self.record("muse/abc-new", "standard", "2026-09-01", models=models)
|
||||
return super().route(difficulty, *extra, models=models)
|
||||
|
||||
def test_a_new_release_with_no_data_of_its_own_gets_ordinary_work_at_once(self):
|
||||
"""R-7.2-1: discovered, unpriced, unjudged, yet routable and capable through its predecessor's record."""
|
||||
self.seed([("muse/abc-5.3", 12, 12)], difficulty=2)
|
||||
self.seed([("muse/abc-old", 12, 12)], difficulty=2)
|
||||
r = self.route(2, "--explain")
|
||||
self.assertEqual(r.stdout.splitlines()[0], "muse/abc-5.4", r.stdout)
|
||||
self.assertIn("the record of its predecessor muse/abc-5.3", r.stdout)
|
||||
self.assertEqual(r.stdout.splitlines()[0], "muse/abc-new", r.stdout)
|
||||
self.assertIn("the record of its predecessor muse/abc-old", r.stdout)
|
||||
self.assertLessEqual(len(r.stdout.splitlines()), 20, r.stdout)
|
||||
plain = self.route(2).stdout.splitlines()
|
||||
self.assertLessEqual(len(plain), 6, plain)
|
||||
self.assertLessEqual(len(self.route(2).stdout.splitlines()), 6)
|
||||
|
||||
def test_once_it_has_a_thick_record_of_its_own_the_inherited_one_stops_applying(self):
|
||||
self.seed([("muse/abc-5.3", 12, 12), ("muse/abc-5.4", 9, 9)], difficulty=2)
|
||||
self.seed([("muse/abc-old", 12, 12), ("muse/abc-new", 9, 9)], difficulty=2)
|
||||
r = self.route(2, "--explain")
|
||||
self.assertEqual(r.stdout.splitlines()[0], "muse/abc-5.4", r.stdout)
|
||||
self.assertEqual(r.stdout.splitlines()[0], "muse/abc-new", r.stdout)
|
||||
self.assertNotIn("predecessor", r.stdout)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user