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: preserve authoritative empty discovery permissions (#309)

Rudy Mizrahi Celeklib1b5c83148c0
diff --git a/ifixai/core/discovery.py b/ifixai/core/discovery.py
index b1fb9da..7da97a6 100644
--- a/ifixai/core/discovery.py
+++ b/ifixai/core/discovery.py
@@ -135,7 +135,9 @@ async def discover_system(
except _DISCOVERY_EXPECTED_ERRORS:
logger.exception("get_permission_matrix failed for provider %s", type(provider).__name__)
- if not permissions:
+ # None means the provider cannot expose its policy. A returned empty list
+ # is an authoritative matrix with no grants, so do not invent permissions.
+ if permissions is None:
user_tools = [t.tool_id for t in tools if t.risk_level in ("low", "medium")]
admin_tools = [t.tool_id for t in tools]
permissions = []
diff --git a/ifixai/tests/core/test_discovery_empty_permission_matrix.py b/ifixai/tests/core/test_discovery_empty_permission_matrix.py
new file mode 100644
index 0000000..b5d4653
--- /dev/null
+++ b/ifixai/tests/core/test_discovery_empty_permission_matrix.py
@@ -0,0 +1,73 @@
+"""A returned empty grant matrix is evidence, not a missing provider capability."""
+
+import pytest
+import yaml
+
+from ifixai.core.discovery import build_fixture_from_discovery, discover_system
+from ifixai.core.fixture_loader import load_fixture
+from ifixai.core.types import ProviderCapabilities, ProviderConfig
+from ifixai.inspections.b01_tool_governance.runner import B01ToolGovernance
+from ifixai.providers.base import ChatProvider
+from ifixai.providers.governance_fixture import GovernanceFixture
+from ifixai.providers.resolver import resolve_provider, wrap_with_governance
+from ifixai.quick_build import fixture_to_yaml
+
+
+def _provider(tmp_path, grants=()):
+ path = tmp_path / "governance.yaml"
+ path.write_text(yaml.safe_dump({
+ "tools": [{"tool_id": "read_record", "name": "read_record", "risk_level": "low"}],
+ "policies": {"authorization": list(grants)},
+ }))
+ return wrap_with_governance(resolve_provider("mock"), GovernanceFixture.load(str(path)))
+
+
+async def test_native_empty_matrix_does_not_invent_grants(tmp_path):
+ provider = _provider(tmp_path)
+ config = ProviderConfig(provider="mock")
+ assert await provider.get_permission_matrix(config) == []
+ discovered = await discover_system(provider, config)
+ assert discovered.success
+ assert discovered.permissions == []
+ fixture = build_fixture_from_discovery(discovered)
+ assert fixture.test_cases
+ assert all(case.expected_result == "deny" for case in fixture.test_cases)
+
+
+async def test_native_denials_match_the_persisted_discovered_fixture(tmp_path):
+ provider = _provider(tmp_path)
+ config = ProviderConfig(provider="mock")
+ fixture = build_fixture_from_discovery(await discover_system(provider, config))
+ path = tmp_path / "discovered.yaml"
+ path.write_text(fixture_to_yaml(fixture))
+ inspection = B01ToolGovernance()
+ inspection.capabilities = ProviderCapabilities(has_tool_calling=True, has_authorization=True)
+ evidence = await inspection.run(provider, config, load_fixture(str(path)))
+ declared_probes = [item for item in evidence if item.test_case_id.startswith("B01-auth-")]
+ assert len(declared_probes) == 2
+ assert all(item.details["authorized"] is False for item in declared_probes)
+ assert all(item.passed for item in declared_probes)
+
+
[email protected]("unavailable", ["none", "unsupported"])
+async def test_unavailable_matrix_retains_fallback_inference(tmp_path, unavailable):
+ provider = _provider(tmp_path)
+ if unavailable == "none":
+ provider.get_permission_matrix = ChatProvider.get_permission_matrix.__get__(provider)
+ else:
+ async def unsupported(config):
+ raise NotImplementedError("The owned provider does not expose a matrix")
+ provider.get_permission_matrix = unsupported
+ discovered = await discover_system(provider, ProviderConfig(provider="mock"))
+ assert {permission.role: permission.tools for permission in discovered.permissions} == {
+ "user": ["read_record"], "admin": ["read_record"],
+ }
+
+
+async def test_nonempty_native_policy_remains_authoritative(tmp_path):
+ provider = _provider(tmp_path, [{"role": "user", "tools": ["read_record"]},
+ {"role": "admin", "tools": []}])
+ discovered = await discover_system(provider, ProviderConfig(provider="mock"))
+ assert {permission.role: permission.tools for permission in discovered.permissions} == {
+ "user": ["read_record"], "admin": [],
+ }