-
Notifications
You must be signed in to change notification settings - Fork 325
test: add unit tests for Shell tool on Windows #349
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,72 @@ | ||||||
| """Basic Windows cmd tests for the shell tool.""" | ||||||
|
|
||||||
| from __future__ import annotations | ||||||
|
|
||||||
| import platform | ||||||
|
|
||||||
| import pytest | ||||||
| from inline_snapshot import snapshot | ||||||
| from kosong.tooling import ToolError, ToolOk | ||||||
|
|
||||||
| from kaos.path import KaosPath | ||||||
| from kimi_cli.tools.shell import Params, Shell | ||||||
|
|
||||||
| pytestmark = pytest.mark.skipif( | ||||||
| platform.system() != "Windows", reason="Shell cmd tests run only on Windows." | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| @pytest.mark.asyncio | ||||||
| async def test_simple_command(shell_tool: Shell): | ||||||
| """Ensure a basic cmd command runs.""" | ||||||
| result = await shell_tool(Params(command="echo Hello Windows")) | ||||||
|
|
||||||
| assert isinstance(result, ToolOk) | ||||||
| assert isinstance(result.output, str) | ||||||
| assert result.output.strip() == snapshot("Hello Windows") | ||||||
| assert "Command executed successfully" in result.message | ||||||
|
|
||||||
|
|
||||||
| @pytest.mark.asyncio | ||||||
| async def test_command_with_error(shell_tool: Shell): | ||||||
| """Failing commands should return a ToolError with exit code info.""" | ||||||
| result = await shell_tool(Params(command='python -c "import sys; sys.exit(1)"')) | ||||||
|
||||||
| result = await shell_tool(Params(command='python -c "import sys; sys.exit(1)"')) | |
| result = await shell_tool(Params(command='dir C:\\nonexistent\\directory')) |
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.
[nitpick] The module docstring says "Basic Windows cmd tests" but test_bash.py uses "Tests for the shell tool." For consistency, consider using a similar format like "Tests for the shell tool on Windows." or "Windows cmd tests for the shell tool."