Item 2: sisi route and delegation honour learned routing adjustments. done 2 / next 3 (failed-check evidence)
This commit is contained in:
1 parent
c8aef3dc23
commit
23a7cc7aec
2 files changed
+45
-2
No files matched your search
+17
-2
@@ -656,6 +656,21 @@ def load_prefs():
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def effective_prefs(kind, difficulty, project):
|
||||||
|
"""The user's avoid/prefer patterns plus the routing adjustments a learning cycle wrote that apply in
|
||||||
|
this project for this kind (and difficulty, when the adjustment names one). A learned entry carries
|
||||||
|
its learning id as its reason, so `sisi route --explain` shows where it came from."""
|
||||||
|
from . import cycle
|
||||||
|
prefs = load_prefs()
|
||||||
|
for a in cycle.routing_adjustments(project):
|
||||||
|
if a.get("kind") != kind or a.get("difficulty") not in (None, difficulty):
|
||||||
|
continue
|
||||||
|
for key in ("avoid", "prefer"):
|
||||||
|
if a.get(key):
|
||||||
|
prefs[key].append({"pattern": str(a[key]), "why": "learning %s" % a.get("learning")})
|
||||||
|
return prefs
|
||||||
|
|
||||||
|
|
||||||
def _fact_dates():
|
def _fact_dates():
|
||||||
dates = []
|
dates = []
|
||||||
prices = load_prices()
|
prices = load_prices()
|
||||||
@@ -994,9 +1009,9 @@ def run_delegation(candidates, kind, difficulty, prompt, cwd, explicit=None, rev
|
|||||||
timeout = DEFAULT_RUN_TIMEOUT_S
|
timeout = DEFAULT_RUN_TIMEOUT_S
|
||||||
tried = []
|
tried = []
|
||||||
cand = explicit
|
cand = explicit
|
||||||
prefs = load_prefs()
|
|
||||||
while True:
|
while True:
|
||||||
if cand is None:
|
if cand is None:
|
||||||
|
prefs = effective_prefs(kind, difficulty, cwd)
|
||||||
result = routing.choose(candidates, read_records(), read_availability(), kind, difficulty,
|
result = routing.choose(candidates, read_records(), read_availability(), kind, difficulty,
|
||||||
review_of=review_of, now=time.time(), exclude=tried,
|
review_of=review_of, now=time.time(), exclude=tried,
|
||||||
avoid=prefs["avoid"], prefer=prefs["prefer"])
|
avoid=prefs["avoid"], prefer=prefs["prefer"])
|
||||||
@@ -1303,7 +1318,7 @@ def cmd_route(args=()):
|
|||||||
kind, difficulty = setup
|
kind, difficulty = setup
|
||||||
records = read_records()
|
records = read_records()
|
||||||
candidates, cold, excluded = routable_candidates(build_candidates(), records)
|
candidates, cold, excluded = routable_candidates(build_candidates(), records)
|
||||||
prefs = load_prefs()
|
prefs = effective_prefs(kind, difficulty, os.getcwd())
|
||||||
result = routing.choose(candidates, records, read_availability(), kind, difficulty,
|
result = routing.choose(candidates, records, read_availability(), kind, difficulty,
|
||||||
review_of=_opt(args, "--review-of"), now=time.time(),
|
review_of=_opt(args, "--review-of"), now=time.time(),
|
||||||
avoid=prefs["avoid"], prefer=prefs["prefer"])
|
avoid=prefs["avoid"], prefer=prefs["prefer"])
|
||||||
|
|||||||
@@ -542,6 +542,34 @@ class Mechanisms(Base):
|
|||||||
self.assertEqual(len(cycle.routing_adjustments(self.proj)), 1)
|
self.assertEqual(len(cycle.routing_adjustments(self.proj)), 1)
|
||||||
self.assertEqual(cycle.routing_adjustments(self.other_project()), [])
|
self.assertEqual(cycle.routing_adjustments(self.other_project()), [])
|
||||||
|
|
||||||
|
def test_a_promoted_routing_adjustment_changes_sisi_route_for_its_project_only(self):
|
||||||
|
"""R-11.1-7, R-7.1-1: the reader of routing-adjustments.json is `sisi route`: a cycle's avoid entry
|
||||||
|
moves the choice in its own project, names its learning in --explain, and leaves another project alone."""
|
||||||
|
bindir = os.path.join(self.tmp, "bin")
|
||||||
|
os.makedirs(bindir)
|
||||||
|
tool = os.path.join(bindir, "muse")
|
||||||
|
with open(tool, "w") as f:
|
||||||
|
f.write('#!/bin/sh\nif [ "$1 $2" = "exec --list-models" ]; then echo beta-1; echo beta-2; fi\nexit 0\n')
|
||||||
|
os.chmod(tool, 0o755)
|
||||||
|
env = {"PATH": bindir}
|
||||||
|
for m, price in (("beta-1", "1"), ("beta-2", "2")):
|
||||||
|
r = self.sisi("workers", "fact", "muse/" + m, "--price", price, "--source", "fixture", env=env)
|
||||||
|
self.assertEqual(r.returncode, 0, r.stderr)
|
||||||
|
other = self.other_project()
|
||||||
|
route = ("route", "--kind", "impl", "--difficulty", "2", "--explain")
|
||||||
|
before, before_other = self.sisi(*route, env=env), self.sisi(*route, cwd=other, env=env)
|
||||||
|
self.assertEqual(before.stdout.splitlines()[0], "muse/beta-1", before.stdout)
|
||||||
|
self.assertEqual(before_other.stdout, before.stdout)
|
||||||
|
self.propose()
|
||||||
|
self.assertEqual(self.apply([{"action": "promote", "learning": "L-0001", "mechanism_kind": "routing",
|
||||||
|
"kind": "impl", "avoid": "beta-1"}]).returncode, 0)
|
||||||
|
after, after_other = self.sisi(*route, env=env), self.sisi(*route, cwd=other, env=env)
|
||||||
|
self.assertEqual(after.stdout.splitlines()[0], "muse/beta-2", after.stdout)
|
||||||
|
self.assertIn("learning L-0001", after.stdout)
|
||||||
|
self.assertEqual(after_other.stdout, before_other.stdout)
|
||||||
|
unrelated = self.sisi("route", "--kind", "review", "--difficulty", "2", env=env)
|
||||||
|
self.assertEqual(unrelated.stdout.splitlines()[0], "muse/beta-1")
|
||||||
|
|
||||||
def test_earned_scope_widens_what_a_cycle_may_apply(self):
|
def test_earned_scope_widens_what_a_cycle_may_apply(self):
|
||||||
"""R-11.6-2: once a learning has earned scope (two units, two projects) its risk adjustment
|
"""R-11.6-2: once a learning has earned scope (two units, two projects) its risk adjustment
|
||||||
reaches both projects and a rule it motivates needs no approval for reach alone."""
|
reaches both projects and a rule it motivates needs no approval for reach alone."""
|
||||||
|
|||||||
Reference in new issue
Block a user