-
Notifications
You must be signed in to change notification settings - Fork 694
Codex/optimize and paginate read console tool #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
664bd56
7be1e3a
03ea5d1
7bd3976
a4bc5aa
66c82f6
0ef3536
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,7 @@ async def test_read_console_full_default(monkeypatch): | |
|
|
||
| captured = {} | ||
|
|
||
| async def fake_send(cmd, params, **kwargs): | ||
| async def fake_send(_cmd, params, **_kwargs): | ||
| captured["params"] = params | ||
| return { | ||
| "success": True, | ||
|
|
@@ -54,10 +54,10 @@ async def fake_send(cmd, params, **kwargs): | |
| resp = await read_console(ctx=DummyContext(), action="get", count=10) | ||
| assert resp == { | ||
| "success": True, | ||
| "data": {"lines": [{"level": "error", "message": "oops", "stacktrace": "trace", "time": "t"}]}, | ||
| "data": {"lines": [{"level": "error", "message": "oops", "time": "t"}]}, | ||
| } | ||
| assert captured["params"]["count"] == 10 | ||
| assert captured["params"]["includeStacktrace"] is True | ||
| assert captured["params"]["includeStacktrace"] is False | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (testing): Paging integration test payload is now out of sync with the Unity handler’s paging response shape
|
||
|
|
@@ -67,7 +67,7 @@ async def test_read_console_truncated(monkeypatch): | |
|
|
||
| captured = {} | ||
|
|
||
| async def fake_send(cmd, params, **kwargs): | ||
| async def fake_send(_cmd, params, **_kwargs): | ||
| captured["params"] = params | ||
| return { | ||
| "success": True, | ||
|
|
@@ -86,3 +86,100 @@ async def fake_send(cmd, params, **kwargs): | |
| assert resp == {"success": True, "data": { | ||
| "lines": [{"level": "error", "message": "oops"}]}} | ||
| assert captured["params"]["includeStacktrace"] is False | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_read_console_default_count(monkeypatch): | ||
| """Test that read_console defaults to count=10 when not specified.""" | ||
| tools = setup_tools() | ||
| read_console = tools["read_console"] | ||
|
|
||
| captured = {} | ||
|
|
||
| async def fake_send(_cmd, params, **_kwargs): | ||
| captured["params"] = params | ||
| return { | ||
| "success": True, | ||
| "data": {"lines": [{"level": "error", "message": f"error {i}"} for i in range(15)]}, | ||
| } | ||
|
|
||
| # Patch the send_command_with_retry function in the tools module | ||
| import services.tools.read_console | ||
| monkeypatch.setattr( | ||
| services.tools.read_console, | ||
| "async_send_command_with_retry", | ||
| fake_send, | ||
| ) | ||
|
|
||
| # Call without specifying count - should default to 10 | ||
| resp = await read_console(ctx=DummyContext(), action="get") | ||
| assert resp["success"] is True | ||
| # Verify that the default count of 10 was used | ||
| assert captured["params"]["count"] == 10 | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_read_console_paging(monkeypatch): | ||
| """Test that read_console paging works with page_size and cursor.""" | ||
| tools = setup_tools() | ||
| read_console = tools["read_console"] | ||
|
|
||
| captured = {} | ||
|
|
||
| async def fake_send(_cmd, params, **_kwargs): | ||
| captured["params"] = params | ||
| # Simulate Unity returning paging info matching C# structure | ||
| page_size = params.get("pageSize", 10) | ||
| cursor = params.get("cursor", 0) | ||
| # Simulate 25 total messages | ||
| all_messages = [{"level": "error", "message": f"error {i}"} for i in range(25)] | ||
|
|
||
| # Return a page of results | ||
| start = cursor | ||
| end = min(start + page_size, len(all_messages)) | ||
| messages = all_messages[start:end] | ||
|
|
||
| return { | ||
| "success": True, | ||
| "data": { | ||
| "items": messages, | ||
| "cursor": cursor, | ||
| "pageSize": page_size, | ||
| "nextCursor": str(end) if end < len(all_messages) else None, | ||
| "truncated": end < len(all_messages), | ||
| "total": len(all_messages), | ||
| }, | ||
| } | ||
|
|
||
| # Patch the send_command_with_retry function in the tools module | ||
| import services.tools.read_console | ||
| monkeypatch.setattr( | ||
| services.tools.read_console, | ||
| "async_send_command_with_retry", | ||
| fake_send, | ||
| ) | ||
|
|
||
| # First page - get first 5 entries | ||
| resp = await read_console(ctx=DummyContext(), action="get", page_size=5, cursor=0) | ||
| assert resp["success"] is True | ||
| assert captured["params"]["pageSize"] == 5 | ||
| assert captured["params"]["cursor"] == 0 | ||
| assert len(resp["data"]["items"]) == 5 | ||
| assert resp["data"]["truncated"] is True | ||
| assert resp["data"]["nextCursor"] == "5" | ||
| assert resp["data"]["total"] == 25 | ||
|
|
||
| # Second page - get next 5 entries | ||
| resp = await read_console(ctx=DummyContext(), action="get", page_size=5, cursor=5) | ||
| assert resp["success"] is True | ||
| assert captured["params"]["cursor"] == 5 | ||
| assert len(resp["data"]["items"]) == 5 | ||
| assert resp["data"]["truncated"] is True | ||
| assert resp["data"]["nextCursor"] == "10" | ||
|
|
||
| # Last page - get remaining entries | ||
| resp = await read_console(ctx=DummyContext(), action="get", page_size=5, cursor=20) | ||
| assert resp["success"] is True | ||
| assert len(resp["data"]["items"]) == 5 | ||
| assert resp["data"]["truncated"] is False | ||
| assert resp["data"]["nextCursor"] is None | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarify where paging defaults are applied.
The annotations state "Defaults to 50 when omitted" and "Defaults to 0", but the Python code passes
Noneto the Unity handler (lines 52-53). The actual defaults are applied in the C# handler (ReadConsole.cslines 259-260), not here.Consider revising to: "Page size for paginated reads. Unity handler defaults to 50 if omitted." and "Paging cursor (0-based offset). Unity handler defaults to 0 if omitted."
🤖 Prompt for AI Agents