@@ -129,6 +129,7 @@ public CommandLineRunner teaQLConsoleStartup(
129129 school .auditAs ("Create the School Query conformance fixture" ).save (context );
130130 }
131131
132+ verifyDynamicSearch (context );
132133 assertQuery (context , "string equality" , Q .schools ().withNameIs ("Riverside Primary School" ), 1 );
133134 assertQuery (context , "string inequality" , Q .schools ().withNameIsNot ("Another School" ), 1 );
134135 assertQuery (context , "string membership" , Q .schools ().withNameIn ("Riverside Primary School" , "Another School" ), 1 );
@@ -226,4 +227,48 @@ private static void assertQuery(
226227 private static void require (boolean condition , String message ) {
227228 if (!condition ) throw new IllegalStateException (message );
228229 }
230+
231+ private static void verifyDynamicSearch (UserContext context ) {
232+ var models = java .util .Map .of (
233+ "School" , new io .teaql .query .json .LocalDynamicSearch .Model (
234+ java .util .Map .of ("name" , "string" ), java .util .Map .of ("platform" , "Platform" )),
235+ "Platform" , new io .teaql .query .json .LocalDynamicSearch .Model (
236+ java .util .Map .of ("name" , "string" ), java .util .Map .of ()));
237+ String input = """
238+ {"filter":{"name":"Riverside Primary School","platform.name":"Campus Learning Platform",
239+ "removed":"SECRET_VALUE","platform.removed":"SECRET_VALUE"},
240+ "orderBy":[{"field":"removed","direction":"asc"}]}
241+ """ ;
242+ // Authorization input is server-owned, never accepted from the JSON form.
243+ for (long authorizedPlatform : new long [] {1L , 2L }) {
244+ for (String searchInput : new String [] {input , "{}" }) {
245+ SchoolRequest <School > request = Q .schools ().withNameIs ("Riverside Primary School" )
246+ .withPlatformMatching (Q .platforms ().withIdIs (authorizedPlatform ));
247+ request .setSize (2 );
248+ request .orderByIdDescending ();
249+ int hardLimit = request .hardLimit ();
250+ var warnings = new java .util .ArrayList <io .teaql .query .json .LocalDynamicSearch .Warning >();
251+ io .teaql .query .json .LocalDynamicSearch .merge (request , searchInput , models , filter -> {
252+ if (!"$eq" .equals (filter .operator ())) {
253+ throw new IllegalArgumentException ("This demo binding supports equality only" );
254+ }
255+ return switch (filter .fieldPath ()) {
256+ case "name" -> Q .schools ().withNameIs (filter .value ().textValue ()).getSearchCriteria ();
257+ case "platform.name" -> Q .schools ().withPlatformMatching (
258+ Q .platforms ().withIdIs (authorizedPlatform ).withNameIs (filter .value ().textValue ()))
259+ .getSearchCriteria ();
260+ default -> throw new IllegalArgumentException ("Missing trusted demo binding" );
261+ };
262+ }, order -> { throw new IllegalArgumentException ("No demo order binding required" ); }, warnings ::add );
263+ SmartList <School > rows = request .comment ("what: generated School dynamic search" )
264+ .purpose ("why: verify stale fields cannot bypass related authorization" ).executeForList (context );
265+ require (rows .size () == (authorizedPlatform == 1L ? 1 : 0 ),
266+ "Dynamic search lost its related authorization filter" );
267+ require (warnings .size () == (searchInput .equals ("{}" ) ? 0 : 3 )
268+ && request .hardLimit () == hardLimit && request .getSize () == 2 ,
269+ "Dynamic search warning or limit contract failed" );
270+ }
271+ }
272+ System .out .println ("PASS Java generated School dynamic search: related scope, drift warnings, typed bindings" );
273+ }
229274}
0 commit comments