@@ -304,6 +304,54 @@ async def test_get_history_filter_by_params_http(
304304 assert all (9.0 == item ["params" ].get ("a" ) for item in data )
305305
306306
307+ async def test_get_history_filter_by_tags (
308+ cli_db : TaskClient , task_manager_db : TaskConsumer , db_plugin : TaskDbPlugin
309+ ) -> None :
310+ task_run = await task_manager_db .queue_and_wait ("dummy" , timeout = 5 )
311+ await wait_for_task_run (db_plugin , task_run .id )
312+ # "dummy" carries the "slow" tag, "add" has no tags
313+ data = await get_history (cli_db , tags = ["slow" ])
314+ assert any (item ["id" ] == task_run .id for item in data )
315+ assert all (item ["task" ] == "dummy" for item in data )
316+
317+
318+ async def test_get_history_filter_by_tags_any (
319+ cli_db : TaskClient , task_manager_db : TaskConsumer , db_plugin : TaskDbPlugin
320+ ) -> None :
321+ dummy_run = await task_manager_db .queue_and_wait ("dummy" , timeout = 5 )
322+ fast_run = await task_manager_db .queue_and_wait ("fast" , timeout = 5 )
323+ await wait_for_task_run (db_plugin , dummy_run .id )
324+ await wait_for_task_run (db_plugin , fast_run .id )
325+ # OR semantics across tags: "fast" and "dummy" share the "test" tag
326+ data = await get_history (cli_db , tags = ["fast" , "slow" ])
327+ assert all (item ["task" ] in {"fast" , "dummy" } for item in data )
328+ ids = {item ["id" ] for item in data }
329+ assert dummy_run .id in ids
330+ assert fast_run .id in ids
331+
332+
333+ async def test_get_history_filter_by_tags_no_match (
334+ cli_db : TaskClient , task_manager_db : TaskConsumer , db_plugin : TaskDbPlugin
335+ ) -> None :
336+ task_run = await task_manager_db .queue_and_wait ("dummy" , timeout = 5 )
337+ await wait_for_task_run (db_plugin , task_run .id )
338+ data = await get_history (cli_db , tags = ["does-not-exist" ])
339+ assert data == []
340+
341+
342+ async def test_get_history_filter_by_tags_and_task (
343+ cli_db : TaskClient , task_manager_db : TaskConsumer , db_plugin : TaskDbPlugin
344+ ) -> None :
345+ task_run = await task_manager_db .queue_and_wait ("dummy" , timeout = 5 )
346+ await wait_for_task_run (db_plugin , task_run .id )
347+ # task + tags combine with AND: "dummy" has "slow" but not "fast"
348+ data = await get_history (cli_db , task = "dummy" , tags = ["slow" ])
349+ assert any (item ["id" ] == task_run .id for item in data )
350+ assert all (item ["task" ] == "dummy" for item in data )
351+ data_empty = await get_history (cli_db , task = "dummy" , tags = ["fast" ])
352+ assert data_empty == []
353+
354+
307355async def test_get_history_filter_by_params_http_negative (
308356 cli_db : TaskClient , task_manager_db : TaskConsumer , db_plugin : TaskDbPlugin
309357) -> None :
0 commit comments