From c9e85930951cabeb25205819ed7141baf7e3d5f5 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 26 May 2025 20:02:50 -0700 Subject: [PATCH] Assert specific order again thanks to monotonic ULIDs, refs #1099 --- tests/test_plugins.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 6ee3a31..9544eb6 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -431,18 +431,20 @@ def test_register_tools(tmpdir, logs_db): log_rows = json.loads( runner.invoke(cli.cli, ["logs", "-c", "-n", "0", "--json"]).output ) - # Workaround for bug in https://github.com/simonw/llm/issues/1073 and 1079 - # We use a set and don't check the order, because (esp on Windows) datetime_utc - # may not be accurate enough to order them correctly. - log_rows.sort(key=lambda row: row["datetime_utc"]) - results = { + results = tuple( (log_row["prompt"], json.dumps(log_row["tool_results"])) for log_row in log_rows - } - assert results == { + ) + assert results == ( + ('{"tool_calls": [{"name": "upper", "arguments": {"text": "one"}}]}', "[]"), ( "", - '[{"id": 4, "tool_id": 1, "name": "upper", "output": "THREE", "tool_call_id": null}]', + '[{"id": 2, "tool_id": 1, "name": "upper", "output": "ONE", "tool_call_id": null}]', + ), + ('{"tool_calls": [{"name": "upper", "arguments": {"text": "two"}}]}', "[]"), + ( + "", + '[{"id": 3, "tool_id": 1, "name": "upper", "output": "TWO", "tool_call_id": null}]', ), ( '{"tool_calls": [{"name": "upper", "arguments": {"text": "three"}}]}', @@ -450,15 +452,9 @@ def test_register_tools(tmpdir, logs_db): ), ( "", - '[{"id": 3, "tool_id": 1, "name": "upper", "output": "TWO", "tool_call_id": null}]', + '[{"id": 4, "tool_id": 1, "name": "upper", "output": "THREE", "tool_call_id": null}]', ), - ( - "", - '[{"id": 2, "tool_id": 1, "name": "upper", "output": "ONE", "tool_call_id": null}]', - ), - ('{"tool_calls": [{"name": "upper", "arguments": {"text": "one"}}]}', "[]"), - ('{"tool_calls": [{"name": "upper", "arguments": {"text": "two"}}]}', "[]"), - } + ) # Test the --td option result6 = runner.invoke( cli.cli,