Skip to content

Independent Auditing of AI Agents. Run by human or the agent itself, to answer the most crucial question in the AI Agent Economy. Is the agent doing what is supposed to do? With iFixAi you can have this answer in less than 120 seconds.

fix: stabilize generated authorization case IDs across runs (#127)

Rudy Mizrahi Celekli14a14216d7a7
diff --git a/ifixai/core/discovery.py b/ifixai/core/discovery.py
index 865a55d..bd87e67 100644
--- a/ifixai/core/discovery.py
+++ b/ifixai/core/discovery.py
@@ -161,7 +161,9 @@ def generate_test_cases(
allowed = perm_map.get(role.name, set())
denied = all_tool_ids - allowed
- for tool_id in allowed:
+ # Set iteration depends on PYTHONHASHSEED. Sort before assigning case
+ # IDs so an identical fixture produces stable audit references.
+ for tool_id in sorted(allowed):
case_id += 1
test_cases.append(TestCase(
test_id=f"tc-{case_id:03d}",
@@ -172,7 +174,7 @@ def generate_test_cases(
tool_id=tool_id,
))
- for tool_id in denied:
+ for tool_id in sorted(denied):
case_id += 1
test_cases.append(TestCase(
test_id=f"tc-{case_id:03d}",
diff --git a/ifixai/tests/core/test_discovery_case_ids.py b/ifixai/tests/core/test_discovery_case_ids.py
new file mode 100644
index 0000000..4a296bc
--- /dev/null
+++ b/ifixai/tests/core/test_discovery_case_ids.py
@@ -0,0 +1,32 @@
+"""Generated case IDs must stay attached to the same tool across runs."""
+
+from ifixai.core.discovery import generate_test_cases
+from ifixai.core.types import Permission, Role, Tool
+
+
+def test_generated_case_ids_follow_stable_tool_order():
+ roles = [Role(name="member", role_id="member")]
+ tools = [
+ Tool(tool_id=tool_id, name=tool_id)
+ for tool_id in (
+ "tool_zeta", "tool_beta", "tool_epsilon", "tool_alpha",
+ "tool_delta", "tool_gamma", "tool_eta", "tool_theta",
+ )
+ ]
+ permissions = [Permission(
+ role="member",
+ tools=["tool_zeta", "tool_gamma", "tool_alpha", "tool_delta"],
+ )]
+
+ cases = generate_test_cases(roles, permissions, tools)
+
+ assert [(case.test_id, case.test, case.tool_id) for case in cases] == [
+ ("tc-001", "B01", "tool_alpha"),
+ ("tc-002", "B01", "tool_delta"),
+ ("tc-003", "B01", "tool_gamma"),
+ ("tc-004", "B01", "tool_zeta"),
+ ("tc-005", "B08", "tool_beta"),
+ ("tc-006", "B08", "tool_epsilon"),
+ ("tc-007", "B08", "tool_eta"),
+ ("tc-008", "B08", "tool_theta"),
+ ]