2323import dev .cel .expr .ai .Agent ;
2424import dev .cel .expr .ai .AgentMessage ;
2525import dev .cel .expr .ai .Finding ;
26+ import dev .cel .expr .ai .Tool ;
27+ import dev .cel .expr .ai .ToolAnnotations ;
2628import dev .cel .expr .ai .ToolCall ;
2729import dev .cel .parser .CelStandardMacro ;
2830import dev .cel .policy .testing .PolicyTestSuiteHelper ;
@@ -48,15 +50,15 @@ public class AgenticPolicyCompilerTest {
4850 .setStandardMacros (CelStandardMacro .STANDARD_MACROS )
4951 .addMessageTypes (Agent .getDescriptor ())
5052 .addMessageTypes (ToolCall .getDescriptor ())
53+ .addMessageTypes (Tool .getDescriptor ())
54+ .addMessageTypes (ToolAnnotations .getDescriptor ())
5155 .addMessageTypes (AgentMessage .getDescriptor ())
5256 .addMessageTypes (Finding .getDescriptor ())
53-
54- // Granular Variables
5557 .addVar ("agent.input" , StructTypeReference .create ("cel.expr.ai.AgentMessage" ))
58+ .addVar ("tool.name" , SimpleType .STRING )
59+ .addVar ("tool.annotations" , StructTypeReference .create ("cel.expr.ai.ToolAnnotations" ))
5660 .addVar ("tool.call" , StructTypeReference .create ("cel.expr.ai.ToolCall" ))
57-
5861 .addFunctionDeclarations (
59- // ai.finding("name", confidence)
6062 newFunctionDeclaration (
6163 "ai.finding" ,
6264 newGlobalOverload (
@@ -66,7 +68,6 @@ public class AgenticPolicyCompilerTest {
6668 SimpleType .DOUBLE
6769 )
6870 ),
69- // agent.input.threats() -> List<Finding>
7071 newFunctionDeclaration (
7172 "threats" ,
7273 newMemberOverload (
@@ -75,7 +76,6 @@ public class AgenticPolicyCompilerTest {
7576 StructTypeReference .create ("cel.expr.ai.AgentMessage" )
7677 )
7778 ),
78- // tool.call.sensitivityLabel("pii") -> List<Finding> (Empty list if no match)
7979 newFunctionDeclaration (
8080 "sensitivityLabel" ,
8181 newMemberOverload (
@@ -85,7 +85,6 @@ public class AgenticPolicyCompilerTest {
8585 SimpleType .STRING
8686 )
8787 ),
88- // list(Finding).contains(list(Finding)) -> bool
8988 newFunctionDeclaration (
9089 "contains" ,
9190 newMemberOverload (
@@ -131,14 +130,11 @@ public class AgenticPolicyCompilerTest {
131130 (args ) -> {
132131 ToolCall tool = (ToolCall ) args [0 ];
133132 String label = (String ) args [1 ];
134-
135- // Mock PII detection: if tool name contains "PII", return a finding
136133 if ("pii" .equals (label ) && tool .getName ().contains ("PII" )) {
137134 return ImmutableList .of (
138135 Finding .newBuilder ().setValue ("pii" ).setConfidence (1.0 ).build ()
139136 );
140137 }
141- // Return empty list instead of Optional.empty()
142138 return ImmutableList .of ();
143139 }
144140 ),
@@ -148,18 +144,13 @@ public class AgenticPolicyCompilerTest {
148144 (args ) -> {
149145 List <Finding > actualFindings = (List <Finding >) args [0 ];
150146 List <Finding > expectedFindings = (List <Finding >) args [1 ];
151- for (Finding expected : expectedFindings ) {
152- boolean found = false ;
153- for (Finding actual : actualFindings ) {
154- if (actual .getValue ().equals (expected .getValue ()) &&
155- actual .getConfidence () >= expected .getConfidence ()) {
156- found = true ;
157- break ;
158- }
159- }
160- if (found ) return true ;
161- }
162- return false ;
147+
148+ return expectedFindings .stream ().anyMatch (expected ->
149+ actualFindings .stream ().anyMatch (actual ->
150+ actual .getValue ().equals (expected .getValue ()) &&
151+ actual .getConfidence () >= expected .getConfidence ()
152+ )
153+ );
163154 }
164155 )
165156 )
@@ -182,6 +173,10 @@ private enum AgenticPolicyTestCase {
182173 REQUIRE_USER_CONFIRMATION_FOR_TOOL (
183174 "require_user_confirmation_for_tool.celpolicy" ,
184175 "require_user_confirmation_for_tool_tests.yaml"
176+ ),
177+ OPEN_WORLD_TOOL_REPLAY (
178+ "open_world_tool_replay.celpolicy" ,
179+ "open_world_tool_replay_tests.yaml"
185180 );
186181
187182 private final String policyFilePath ;
0 commit comments