Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions host-setup/agent-safety/claude/model-tier-guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
allowed whatever it names. Using no fork for work meant to run below the session's tier therefore
stays a prose rule, in AGENTS.md "Model Tiers".

A config that is missing, unreadable, or lacks the keys cannot say which model is blocked. A call
naming any model is then denied, so the guard never goes quiet without saying so, and a call naming
none is allowed.
A config that is missing, unreadable, or lacks the keys cannot say which model is blocked. Nor can
one whose `inheritingAgentTypes` is not a list of strings, since the hook cannot tell which types it
names. A call naming any model is then denied, so the guard never goes quiet without saying so, and a
call naming none is allowed.

Run `model-tier-guard.py --selftest` to check the decision matrix without Claude Code.
"""
Expand Down Expand Up @@ -70,6 +71,8 @@ def load_tiers(path):
return None
if not isinstance(blocked, str) or not isinstance(default, str) or not blocked:
return None
if not isinstance(inheriting, list) or not all(isinstance(t, str) for t in inheriting):
return None
return {
"blocked": blocked,
"reserved": reserved,
Expand Down
14 changes: 14 additions & 0 deletions host-setup/agent-safety/claude/test_model_tier_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ def test_a_mapping_without_the_key_allows_an_inheriting_type(self):
self.assertIsNone(self.run_hook("Agent", {"subagent_type": "Explore"}))
self.assertDenied(self.run_hook("Agent", {"model": "fable"}))

def test_a_malformed_inheriting_list_is_treated_as_missing(self):
for value in (["Explore", 1], [None], "Explore", {"Explore": True}, 7):
with self.subTest(value=value):
cfg = json.loads(json.dumps(TIERS))
cfg["tools"]["claude-code"]["inheritingAgentTypes"] = value
self.write_config(cfg)
self.assertDenied(
self.run_hook("Agent", {"model": "fable"}), "missing or unreadable"
)
self.assertDenied(
self.run_hook("Agent", {"model": "opus"}), "missing or unreadable"
)
self.assertIsNone(self.run_hook("Agent", {}))

def test_unparseable_input_is_allowed(self):
done = subprocess.run(
[sys.executable, str(self.dir / "model-tier-guard.py")],
Expand Down
1 change: 1 addition & 0 deletions spec/fidelity_honesty.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def buckets(path):
if isinstance(d, dict)
and isinstance(d.get("path"), str)
and isinstance(d.get("repos"), list)
and d["repos"]
and all(isinstance(r, str) for r in d["repos"])
and isinstance(d.get("disposition"), str)
and isinstance(d.get("reason"), str)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_fidelity_honesty.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ def test_a_disposition_row_with_a_non_string_repo_is_dropped_rather_than_raising
out = fidelity_honesty.render_report([], [], {}, [], {"dispositions": [bad]}, {})
self.assertNotIn("x.md", out)

def test_a_disposition_row_with_no_repos_is_not_read_as_resolved(self) -> None:
empty = {"path": "x.md", "repos": [], "disposition": "accepted", "reason": "r"}
spread = {"differs": ["A"], "stale": [], "absent": [], "match": [], "unavailable": []}
spreads = [({"path": "x.md", "fidelity": "verbatim"}, spread)]
out = fidelity_honesty.render_report(spreads, [], {}, [], {"dispositions": [empty]}, {})
self.assertNotIn("## Resolved", out)
self.assertIn("x.md", out.split("## Untriaged", 1)[1])

def test_main_spec_carries_the_ledger_retired_paths(self) -> None:
"""Without the ledger in the spec, every path retired outright drops out of the gap pass."""
self.assertEqual(
Expand Down
7 changes: 5 additions & 2 deletions tests/test_spec_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import audit
import secret_names
import validate
from git_env import without_git_location

CHECK_TYPES = {"types": {"python": {"checks": [{"id": "python.typed"}]}}, "crossCutting": {}}

Expand Down Expand Up @@ -3088,10 +3089,12 @@ def test_the_drop_check_runs_where_the_ledger_is_absent(self) -> None:
encoding="utf-8",
)
(root / "spec" / "divergences.json").unlink()
subprocess.run(["git", "-C", str(root), "init", "-q"], check=True, timeout=60)
subprocess.run(["git", "-C", str(root), "add", "spec"], check=True, timeout=60)
env = without_git_location()
subprocess.run(["git", "-C", str(root), "init", "-q"], check=True, timeout=60, env=env)
subprocess.run(["git", "-C", str(root), "add", "spec"], check=True, timeout=60, env=env)
result = subprocess.run(
[sys.executable, str(root / "spec" / "validate.py")],
env=env,
capture_output=True,
text=True,
encoding="utf-8",
Expand Down
Loading