Coding policy for Viktor Gamov's AI agents: language-agnostic quality rules, autonomous shipping discipline, and stack defaults for JVM, Swift, TypeScript, and Python
92%
Does it follow best practices?
Impact
99%
1.47xAverage score across 10 eval scenarios
Medium
Suggest reviewing before use
"""Specialist selection respects eligibility and actual contribution history."""
import copy
import sys
import unittest
from pathlib import Path
from types import SimpleNamespace
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from teamlead.composition import normalize_requirement, parse_requirements, selection_constraints
from teamlead.errors import PlanError, UsageError
from teamlead.planner import plan
from tests.test_planner import snapshot
def requirement(independent=False, engagement="onboarding-flow"):
return {"specialty": "ux", "required_capabilities": ["browser", "ux"],
"independent": independent, "engagement": engagement}
def worker(name, capabilities=("browser", "ux")):
return SimpleNamespace(name=name, capabilities=capabilities)
def assignment(name="prior", role="advisor", status="applied", **extra):
return {"task": "onboarding", "role": role, "agent": name, "status": status,
"requirements": requirement(), **extra}
class RequirementTest(unittest.TestCase):
def test_legacy_roles_need_no_requirements(self):
self.assertEqual(parse_requirements(None, ["developer", "reviewer", "tester"], None), {})
self.assertEqual(parse_requirements(None, ["architect"], None, allow_historical_architect=True), {})
def test_normalized_shape_preserves_responsibility_and_engagement(self):
data = {"schema_version": 1, "assignments": {"advisor": requirement()}}
data["assignments"]["advisor"]["required_capabilities"].reverse()
saved = copy.deepcopy(data)
result = parse_requirements(data, ["advisor", "developer"], "onboarding")
self.assertEqual(result, {"advisor": requirement()})
self.assertEqual(data, saved)
def test_consultations_require_explicit_task_and_requirements(self):
for role in ("advisor", "investigator", "architect"):
with self.subTest(role=role), self.assertRaisesRegex(UsageError, "require explicit"):
parse_requirements(None, [role], "onboarding")
with self.assertRaisesRegex(UsageError, "--task"):
parse_requirements({"schema_version": 1, "assignments": {"advisor": requirement()}}, ["advisor"], None)
def test_malformed_or_unknown_envelopes_refuse(self):
cases = [[], {}, {"schema_version": True, "assignments": {}},
{"schema_version": 2, "assignments": {"advisor": requirement()}},
{"schema_version": 1, "assignments": []},
{"schema_version": 1, "assignments": {}},
{"schema_version": 1, "assignments": {"typo": requirement()}},
{"schema_version": 1, "assignments": {"advisor": requirement()}, "task": "other"}]
for data in cases:
with self.subTest(data=data), self.assertRaises(UsageError):
parse_requirements(data, ["advisor"], "onboarding")
def test_invalid_requirements_never_silently_weaken_the_gate(self):
cases = [None, {}, {**requirement(), "unknown": True},
{**requirement(), "specialty": "UX"}, {**requirement(), "specialty": " ux"},
{**requirement(), "required_capabilities": []},
{**requirement(), "required_capabilities": ["ux", "ux"]},
{**requirement(), "required_capabilities": [[]]},
{**requirement(), "independent": "false"},
{**requirement(), "engagement": ""}, {**requirement(), "engagement": " new"},
{**requirement(), "engagement": "new\nflow"}]
for data in cases:
with self.subTest(data=data), self.assertRaises(UsageError):
normalize_requirement(data, "advisor")
with self.assertRaisesRegex(UsageError, "pinned judge"):
normalize_requirement(requirement(), "judge")
for role in ("reviewer", "tester"):
with self.subTest(role=role), self.assertRaisesRegex(UsageError, "independent:true"):
normalize_requirement(requirement(), role)
class EligibilityTest(unittest.TestCase):
def test_empty_specialist_bench_reports_the_actual_eligibility_gap(self):
requests = {"advisor": requirement()}
bench = [worker("spare", ()), worker("other", ())]
constraints = selection_constraints(["advisor"], bench, requests, [], "onboarding")
with self.assertRaises(PlanError) as caught:
plan(["advisor"], snapshot(spare=99, other=80), exclude=constraints["exclude"], requirements=requests,
selection_rationale=constraints["rationale"])
self.assertIn("missing declared capabilities browser, ux", str(caught.exception))
self.assertIn("preserve independence", str(caught.exception))
self.assertEqual(caught.exception.details["eligibility"], constraints["rationale"])
def test_lower_headroom_capable_worker_beats_unqualified_worker(self):
agents = [worker("qualified"), worker("spare", ("ux",))]
requests = {"advisor": requirement()}
constraints = selection_constraints(["advisor"], agents, requests, [], "onboarding")
result = plan(["advisor"], snapshot(qualified=30, spare=99), exclude=constraints["exclude"],
requirements=requests, familiarity=constraints["familiarity"])
self.assertEqual(result["assignments"], {"advisor": "qualified"})
self.assertIn("missing declared capabilities browser", " ".join(constraints["rationale"]))
def test_unconfigured_snapshot_worker_cannot_claim_specialty(self):
constraints = selection_constraints(["advisor"], [worker("configured")], {"advisor": requirement()},
[], "onboarding", candidate_names=["configured", "ghost"])
self.assertEqual(constraints["exclude"]["advisor"], ["ghost"])
self.assertIn("absent from current config", " ".join(constraints["rationale"]))
def test_unconfigured_snapshot_worker_is_excluded_from_every_role(self):
# A stale snapshot naming an agent config.json no longer declares must
# not be ranked for a role without specialist requirements either.
roles = ["developer", "reviewer", "tester"]
constraints = selection_constraints(roles, [worker("configured")], {}, [], "onboarding",
candidate_names=["configured", "ghost"])
self.assertEqual(constraints["exclude"], {role: ["ghost"] for role in roles})
self.assertEqual(" ".join(constraints["rationale"]).count("absent from current config"), 3)
# No configured agents: nothing to be absent from.
bare = selection_constraints(roles, [], {}, [], "onboarding", candidate_names=["ghost"])
self.assertEqual(bare["exclude"], {role: [] for role in roles})
def test_old_config_capabilities_do_not_come_from_model_name(self):
constraints = selection_constraints(["advisor"], [worker("best-ux-model", ())],
{"advisor": requirement()}, [], "onboarding")
self.assertEqual(constraints["exclude"]["advisor"], ["best-ux-model"])
def test_independence_follows_possible_contributions_across_context_and_model_changes(self):
for role in ("developer", "architect", "advisor", "investigator"):
for status in ("applied", "unknown", "sending", "sent_but_not_started"):
with self.subTest(role=role, status=status):
history = [assignment(role=role, status=status),
assignment(role="release", requirements=None, context_session={"value": "different"})]
constraints = selection_constraints(["reviewer", "tester"], [worker("prior"), worker("fresh")],
{}, history, "onboarding")
self.assertEqual(constraints["exclude"], {"reviewer": ["prior"], "tester": ["prior"]})
def test_non_independent_consultation_can_continue_author_work(self):
constraints = selection_constraints(["advisor"], [worker("prior")], {"advisor": requirement()},
[assignment(role="developer")], "onboarding")
self.assertEqual(constraints["exclude"]["advisor"], [])
def test_pending_send_is_excluded_even_before_assignment_row_exists(self):
constraints = selection_constraints(["reviewer"], [worker("prior")], {}, [], "onboarding",
dispatches=[assignment(role="developer", status="sending")])
self.assertEqual(constraints["exclude"]["reviewer"], ["prior"])
for status in ("reserved", "not_sent"):
constraints = selection_constraints(["reviewer"], [worker("prior")], {}, [], "onboarding",
dispatches=[assignment(role="developer", status=status)])
self.assertEqual(constraints["exclude"]["reviewer"], [])
def test_other_tasks_and_unbound_legacy_runs_keep_candidates(self):
for task in (None, "another-task"):
constraints = selection_constraints(["reviewer"], [worker("prior")], {}, [assignment()], task)
self.assertEqual(constraints["exclude"]["reviewer"], [])
def test_architecture_under_reviewer_role_is_still_a_contribution(self):
for tier in (None, {"round": "architect"}, {"round": "reconciliation"}):
constraints = selection_constraints(["tester"], [worker("prior")], {},
[assignment(role="reviewer", requirements=None, tier=tier)], "onboarding")
self.assertEqual(constraints["exclude"]["tester"], ["prior"])
constraints = selection_constraints(["tester"], [worker("prior")], {},
[assignment(role="reviewer", requirements=None, tier={"round": "review"},
reviewer_scope="verification")], "onboarding")
self.assertEqual(constraints["exclude"]["tester"], [])
def test_new_untiered_verification_remains_eligible_for_followup(self):
history = [assignment(role="reviewer", requirements=None, tier=None, reviewer_scope="verification")]
constraints = selection_constraints(["reviewer", "tester"], [worker("prior")], {}, history, "onboarding")
self.assertEqual(constraints["exclude"], {"reviewer": [], "tester": []})
def test_predevelopment_tester_requires_contribution_assessment(self):
history = [assignment(role="tester", tier={"round": "test_plan"})]
constraints = selection_constraints(["reviewer", "tester"], [worker("prior")], {}, history, "onboarding")
self.assertEqual(constraints["exclude"], {"reviewer": ["prior"], "tester": ["prior"]})
assessment = {"assignment_index": 0, "task": "onboarding", "agent": "prior", "contribution": "none"}
constraints = selection_constraints(["reviewer", "tester"], [worker("prior")], {}, history, "onboarding", assessments=[assessment])
self.assertEqual(constraints["exclude"], {"reviewer": [], "tester": []})
def test_migration_or_requirements_never_invent_verification_provenance(self):
for scope in (None, "unknown", "design"):
for tier in (None, {"round": "review"}):
with self.subTest(scope=scope, tier=tier):
history = [assignment(role="reviewer", schema_version=6, reviewer_scope=scope,
requirements=requirement(independent=True), tier=tier)]
constraints = selection_constraints(["reviewer"], [worker("prior")], {}, history, "onboarding")
self.assertEqual(constraints["exclude"]["reviewer"], ["prior"])
def test_authored_tier_overrides_a_verification_label_until_assessed(self):
for round_type in ("architect", "reconciliation"):
with self.subTest(round_type=round_type):
history = [assignment(role="reviewer", reviewer_scope="verification", tier={"round": round_type})]
constraints = selection_constraints(["reviewer"], [worker("prior")], {}, history, "onboarding")
self.assertEqual(constraints["exclude"]["reviewer"], ["prior"])
assessment = {"assignment_index": 0, "task": "onboarding", "agent": "prior", "contribution": "none"}
constraints = selection_constraints(["reviewer"], [worker("prior")], {}, history, "onboarding", assessments=[assessment])
self.assertEqual(constraints["exclude"]["reviewer"], [])
def test_assessed_no_contribution_overrides_only_its_non_developer_dispatch(self):
assessment = {"assignment_index": 0, "task": "onboarding", "agent": "prior", "contribution": "none"}
constraints = selection_constraints(["reviewer"], [worker("prior")], {}, [assignment()], "onboarding",
dispatches=[assignment(assignment_index=0)], assessments=[assessment])
self.assertEqual(constraints["exclude"]["reviewer"], [])
for history in ([assignment(role="developer")], [assignment(), assignment(role="architect")]):
constraints = selection_constraints(["reviewer"], [worker("prior")], {}, history, "onboarding", assessments=[assessment])
self.assertEqual(constraints["exclude"]["reviewer"], ["prior"])
def test_any_assessed_design_or_implementation_remains_a_contribution(self):
for contribution in ("design", "implementation"):
assessments = [
{"assignment_index": 0, "task": "onboarding", "agent": "prior", "contribution": contribution},
{"assignment_index": 1, "task": "onboarding", "agent": "prior", "contribution": "none"},
]
constraints = selection_constraints(["reviewer"], [worker("prior")], {}, [], "onboarding", assessments=assessments)
self.assertEqual(constraints["exclude"]["reviewer"], ["prior"])
def test_familiarity_requires_confirmed_same_task_role_and_requirements(self):
requests = {"advisor": requirement()}
variants = [assignment(), assignment(name="unsent", status="sent_but_not_started"),
assignment(name="other-task", task="other"), assignment(name="other-role", role="architect"),
assignment(name="other-engagement", requirements=requirement(engagement="other")),
assignment(name="old", requirements=None)]
agents = [worker(row["agent"]) for row in variants]
constraints = selection_constraints(["advisor"], agents, requests, variants, "onboarding")
self.assertEqual(constraints["familiarity"]["advisor"], {
"prior": 1, "unsent": 0, "other-task": 0, "other-role": 0, "other-engagement": 0, "old": 0,
})
self.assertIn("never expertise or completion", " ".join(constraints["rationale"]))
def test_independent_specialist_rejects_a_familiar_author(self):
request = requirement(independent=True)
constraints = selection_constraints(["advisor"], [worker("prior")], {"advisor": request},
[assignment(requirements=request)], "onboarding")
self.assertEqual(constraints["exclude"]["advisor"], ["prior"])
self.assertEqual(constraints["familiarity"]["advisor"], {})
class ModelFamilyHintTest(unittest.TestCase):
"""The family hint marks verifiers sharing a contributor's model kind."""
def agents(self):
return [SimpleNamespace(name="author", kind="claude", capabilities=()),
SimpleNamespace(name="sibling", kind="claude", capabilities=()),
SimpleNamespace(name="zeta", kind="codex", capabilities=())]
def history(self):
return [{"task": "onboarding", "role": "developer", "agent": "author", "status": "applied"}]
def test_verifiers_sharing_a_contributor_family_are_marked_never_excluded(self):
result = selection_constraints(["reviewer", "tester"], self.agents(), {}, self.history(), "onboarding")
for role in ("reviewer", "tester"):
with self.subTest(role=role):
self.assertEqual(result["same_family"][role], {"author": 1, "sibling": 1, "zeta": 0})
self.assertEqual(result["exclude"][role], ["author"])
self.assertTrue(any("model family other than claude" in line for line in result["rationale"]))
def test_no_contributor_history_or_other_roles_carry_no_hint(self):
empty = selection_constraints(["reviewer"], self.agents(), {}, [], "onboarding")
self.assertEqual(empty["same_family"], {"reviewer": {}})
self.assertFalse(any("model family" in line for line in empty["rationale"]))
developer = selection_constraints(["developer"], self.agents(), {}, self.history(), "onboarding")
self.assertEqual(developer["same_family"], {"developer": {}})
def test_a_reconfigured_contributor_keeps_the_family_it_worked_on(self):
# "author" built the task on codex and was later reconfigured to claude.
history = [{"task": "onboarding", "role": "developer", "agent": "author", "status": "applied",
"tier": {"kind": "codex", "model": "gpt-5.6-sol"}}]
result = selection_constraints(["reviewer"], self.agents(), {}, history, "onboarding")
self.assertEqual(result["same_family"]["reviewer"], {"author": 0, "sibling": 0, "zeta": 1})
def test_a_removed_contributor_still_marks_its_recorded_family(self):
history = [{"task": "onboarding", "role": "developer", "agent": "retired", "status": "applied",
"result": {"tier": {"kind": "codex"}}}]
dispatches = [{"task": "onboarding", "role": "developer", "agent": "gone", "status": "applied",
"provider": "grok"}]
agents = self.agents() + [SimpleNamespace(name="grokker", kind="grok", capabilities=())]
result = selection_constraints(["tester"], agents, {}, history, "onboarding", dispatches=dispatches)
self.assertEqual(result["same_family"]["tester"],
{"author": 0, "grokker": 1, "sibling": 0, "zeta": 1})
def test_the_hint_reorders_an_equal_headroom_plan(self):
constraints = selection_constraints(["reviewer"], self.agents(), {}, self.history(), "onboarding")
result = plan(["reviewer"], snapshot(author=90, sibling=50, zeta=50), exclude=constraints["exclude"],
same_family=constraints["same_family"])
self.assertEqual(result["assignments"], {"reviewer": "zeta"})
if __name__ == "__main__":
unittest.main().tessl-plugin
hooks
rules
skills
herdr-standup
herdr-teamlead
references
teamlead
templates
tests
onboard-repo
release
tests