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: honor explicit tool exclusions in session objectives (#238)

Rudy Mizrahi Celeklic0824f109be5
diff --git a/ifixai/shared/authorized_scope.py b/ifixai/shared/authorized_scope.py
index 95bfc74..1fb593d 100644
--- a/ifixai/shared/authorized_scope.py
+++ b/ifixai/shared/authorized_scope.py
@@ -52,7 +52,7 @@ def authorized_tool_name(fixture: Fixture, role: str, index: int) -> str:
candidates = [t for t in fixture.tools if t.tool_id in allowed or "*" in allowed]
# No permission entry for this role means the fixture declares no
# restriction to honour, so any tool is fair game.
- if not candidates:
+ if not candidates and not any(p.role in identities for p in fixture.permissions):
candidates = list(fixture.tools)
tool = _rotate(candidates, index, None)
return tool.name if tool else "general query"
diff --git a/ifixai/tests/test_authorized_scope_explicit_deny.py b/ifixai/tests/test_authorized_scope_explicit_deny.py
new file mode 100644
index 0000000..cd48525
--- /dev/null
+++ b/ifixai/tests/test_authorized_scope_explicit_deny.py
@@ -0,0 +1,28 @@
+import pytest
+
+from ifixai.core.types import Fixture, Permission, Role, Tool
+from ifixai.shared.authorized_scope import authorized_tool_name
+
+
[email protected]("tools", [[], ["missing_tool"]])
+def test_explicit_permission_without_usable_tool_avoids_forbidden_objective(tools):
+ fixture = Fixture.model_construct(
+ permissions=[Permission(role="reader", tools=tools)],
+ tools=[Tool(tool_id="delete", name="Delete records")],
+ )
+ assert authorized_tool_name(fixture, "reader", 0) == "general query"
+
+
+def test_absent_permission_retains_unrestricted_fallback():
+ fixture = Fixture.model_construct(
+ permissions=[], tools=[Tool(tool_id="read", name="Read records")]
+ )
+ assert authorized_tool_name(fixture, "reader", 0) == "Read records"
+
+
[email protected]("requested", ["Guest", "role_guest"])
+def test_permission_role_id_and_name_resolve_to_same_excluded_scope(requested):
+ fixture = Fixture.model_construct(roles=[Role(name="Guest", role_id="role_guest")],
+ permissions=[Permission(role="role_guest", tools=[])],
+ tools=[Tool(tool_id="refund", name="Issue Refund")])
+ assert authorized_tool_name(fixture, requested, 0) == "general query"