Skip to content
Closed
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
7 changes: 6 additions & 1 deletion services/torghut/scripts/run_governance_policy_dry_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ def _int_field_or_default(
default: int,
) -> int:
value = payload.get(key)
return default if value is None else int(value)
if value is None or (isinstance(value, str) and not value.strip()):
return default
try:
return int(value)
Comment on lines +279 to +280

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject non-integral route counts before coercion

When the gate-report JSON supplies a malformed numeric count such as 0.5 (or a boolean such as false), int(value) silently produces 0 instead of using the default. The dry run then emits an expert-router artifact that fails the configured minimum-route gate, whereas these inputs should receive the same missing-input treatment as blank and non-integer strings; route counts generated by the real registry are integer len(...) values.

Useful? React with 👍 / 👎.

except (OverflowError, TypeError, ValueError):
return default


def main() -> int:
Expand Down
17 changes: 16 additions & 1 deletion services/torghut/tests/test_governance_policy_dry_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,25 @@ def test_dry_run_preserves_zero_expert_router_route_count(self) -> None:
reasons = output["promotion_prerequisites"]["reasons"]
self.assertIn("expert_router_registry_route_count_below_minimum", reasons)

def test_dry_run_defaults_blank_expert_router_route_count(self) -> None:
output = self._run_harness(expert_router_route_count="")

self.assertTrue(output["promotion_progression_allowed"])

def test_dry_run_defaults_invalid_expert_router_route_count(self) -> None:
output = self._run_harness(expert_router_route_count="not-an-integer")

self.assertTrue(output["promotion_progression_allowed"])

def test_dry_run_defaults_infinite_expert_router_route_count(self) -> None:
output = self._run_harness(expert_router_route_count=float("inf"))

self.assertTrue(output["promotion_progression_allowed"])

def _run_harness(
self,
*extra_args: str,
expert_router_route_count: int | None = None,
expert_router_route_count: object | None = None,
) -> dict[str, object]:
now = datetime.now(timezone.utc)
repo_root = Path(__file__).resolve().parents[3]
Expand Down
Loading