Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions wish-api/tests/test_placeholder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Placeholder test file for wish-api."""

def test_placeholder():
"""Placeholder test to satisfy pytest configuration."""
assert True
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,14 @@ async def execute_command(self, wish: Wish, command: str, cmd_num: int, log_file
Commands are executed in the working directory /app/{run_id}/ to isolate
command execution from the application source code.
"""
# Create command result
result = CommandResult.create(cmd_num, command, log_files, timeout_sec)
# Create command result with Command object
from wish_models.command_result.command import Command, CommandType
command_obj = Command(
command=command,
tool_type=CommandType.BASH,
tool_parameters={"timeout": timeout_sec}
)
result = CommandResult.create(cmd_num, command_obj, log_files, timeout_sec)

wish.command_results.append(result)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,14 @@ async def execute_command(self, wish: Wish, command: str, cmd_num: int, log_file
log_files: The log files to write output to.
timeout_sec: The timeout in seconds for this command.
"""
# Create command result
result = CommandResult.create(cmd_num, command, log_files, timeout_sec)
# Create command result with Command object
from wish_models.command_result.command import Command, CommandType
command_obj = Command(
command=command,
tool_type=CommandType.BASH, # Sliver executes shell commands
tool_parameters={"timeout": timeout_sec, "session_id": self.session_id}
)
result = CommandResult.create(cmd_num, command_obj, log_files, timeout_sec)
wish.command_results.append(result)

try:
Expand Down
4 changes: 2 additions & 2 deletions wish-command-execution/tests/backend/test_bash_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async def test_execute_command(self, mock_makedirs, mock_open, mock_popen, backe

# Verify that the command result was added to the wish
assert len(wish.command_results) == 1
assert wish.command_results[0].command == cmd
assert wish.command_results[0].command.command == cmd
assert wish.command_results[0].num == cmd_num

# Verify that the command was added to running_commands
Expand Down Expand Up @@ -113,7 +113,7 @@ async def test_execute_command_subprocess_error(

# Verify that the command result was added to the wish
assert len(wish.command_results) == 1
assert wish.command_results[0].command == cmd
assert wish.command_results[0].command.command == cmd
assert wish.command_results[0].num == cmd_num

# Verify that the command result was updated with the error state
Expand Down
6 changes: 4 additions & 2 deletions wish-command-execution/tests/backend/test_sliver_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def test_execute_command(sliver_backend, wish, log_files, mock_sliver_clie

# Check that the command result was added to the wish
assert len(wish.command_results) == 1
assert wish.command_results[0].command == "whoami"
assert wish.command_results[0].command.command == "whoami"
assert wish.command_results[0].num == 1

# Check that the log files were written to
Expand All @@ -107,7 +107,9 @@ async def test_cancel_command(sliver_backend, wish, log_files):
"""Test cancelling a command."""
# Add a command result to the wish
timeout_sec = 60
result = CommandResult.create(1, "whoami", log_files, timeout_sec)
from wish_models.command_result.command import Command
command = Command.create_bash_command("whoami")
result = CommandResult.create(1, command, log_files, timeout_sec)
wish.command_results.append(result)

# Cancel the command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def handle_network_error(state: Annotated[GraphState, "Current state"], settings

# Format the feedback as JSON string
feedback_str = (
json.dumps([result.model_dump() for result in state.failed_command_results], ensure_ascii=False)
json.dumps([result.model_dump(mode="json") for result in state.failed_command_results], ensure_ascii=False)
if state.failed_command_results else "[]"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def handle_timeout(state: Annotated[GraphState, "Current state"], settings_obj:

# Format the feedback as JSON string
feedback_str = (
json.dumps([result.model_dump() for result in state.failed_command_results], ensure_ascii=False)
json.dumps([result.model_dump(mode="json") for result in state.failed_command_results], ensure_ascii=False)
if state.failed_command_results else "[]"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def test_lambda_handler_with_feedback(settings):
act_result = [
{
"num": 1,
"command": "nmap -p- 10.10.10.40",
"command": {
"command": "nmap -p- 10.10.10.40",
"tool_type": "bash",
"tool_parameters": {}
},
"state": "TIMEOUT",
"exit_code": 1,
"log_summary": "timeout",
Expand Down Expand Up @@ -78,7 +82,11 @@ def test_lambda_handler_with_network_error_feedback(settings):
act_result = [
{
"num": 1,
"command": "nmap -p- 10.10.10.40",
"command": {
"command": "nmap -p- 10.10.10.40",
"tool_type": "bash",
"tool_parameters": {}
},
"state": "NETWORK_ERROR",
"exit_code": 1,
"log_summary": "Connection closed by peer",
Expand Down Expand Up @@ -135,7 +143,11 @@ def test_lambda_handler_with_multiple_feedback(settings):
act_result = [
{
"num": 1,
"command": "nmap -p1-1000 10.10.10.40",
"command": {
"command": "nmap -p1-1000 10.10.10.40",
"tool_type": "bash",
"tool_parameters": {}
},
"state": "SUCCESS",
"exit_code": 0,
"log_summary": "Scan completed successfully",
Expand All @@ -148,7 +160,11 @@ def test_lambda_handler_with_multiple_feedback(settings):
},
{
"num": 2,
"command": "nmap -p1001-65535 10.10.10.40",
"command": {
"command": "nmap -p1001-65535 10.10.10.40",
"tool_type": "bash",
"tool_parameters": {}
},
"state": "TIMEOUT",
"exit_code": 1,
"log_summary": "timeout",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
from wish_models.command_result import CommandResult, CommandState, LogFiles
from wish_models.command_result.command import Command, CommandType
from wish_models.settings import Settings
from wish_models.utc_datetime import UtcDatetime

Expand Down Expand Up @@ -63,7 +64,11 @@ def test_command_generation_with_network_error_feedback(settings):
act_result = [
CommandResult(
num=1,
command="smbclient -N //10.10.10.40/Users --option='client min protocol'=LANMAN1",
command=Command(
command="smbclient -N //10.10.10.40/Users --option='client min protocol'=LANMAN1",
tool_type=CommandType.BASH,
tool_parameters={}
),
state=CommandState.NETWORK_ERROR,
exit_code=1,
log_summary="Connection closed by peer",
Expand Down Expand Up @@ -118,7 +123,11 @@ def test_command_generation_with_timeout_feedback(settings):
act_result = [
CommandResult(
num=1,
command="nmap -p- 10.10.10.40",
command=Command(
command="nmap -p- 10.10.10.40",
tool_type=CommandType.BASH,
tool_parameters={}
),
state=CommandState.TIMEOUT,
exit_code=1,
log_summary="timeout",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
from wish_models.command_result import CommandResult, CommandState, LogFiles
from wish_models.command_result.command import Command, CommandType
from wish_models.settings import Settings
from wish_models.utc_datetime import UtcDatetime

Expand Down Expand Up @@ -66,7 +67,11 @@ def test_graph_with_timeout_feedback(settings):
act_result = [
CommandResult(
num=1,
command="nmap -p- 10.10.10.40",
command=Command(
command="nmap -p- 10.10.10.40",
tool_type=CommandType.BASH,
tool_parameters={}
),
state=CommandState.TIMEOUT,
exit_code=1,
log_summary="timeout",
Expand Down Expand Up @@ -126,7 +131,11 @@ def test_graph_with_network_error_feedback(settings):
act_result = [
CommandResult(
num=1,
command="nmap -p- 10.10.10.40",
command=Command(
command="nmap -p- 10.10.10.40",
tool_type=CommandType.BASH,
tool_parameters={}
),
state=CommandState.NETWORK_ERROR,
exit_code=1,
log_summary="Connection closed by peer",
Expand Down Expand Up @@ -186,7 +195,11 @@ def test_graph_with_unknown_error_feedback(settings):
act_result = [
CommandResult(
num=1,
command="nmap -p- 10.10.10.40",
command=Command(
command="nmap -p- 10.10.10.40",
tool_type=CommandType.BASH,
tool_parameters={}
),
state=CommandState.OTHERS,
exit_code=1,
log_summary="Unknown error",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest.mock import patch

import pytest
from wish_models import CommandState
from wish_models.test_factories.command_input_factory import CommandInputFactory
from wish_models.test_factories.command_result_factory import CommandResultSuccessFactory
from wish_models.test_factories.settings_factory import SettingsFactory
Expand Down Expand Up @@ -199,8 +200,7 @@ def test_modify_command_preserve_state(mock_modify, settings):
# Create a state with additional fields
processed_query = "processed test query"
failed_command_result = CommandResultSuccessFactory(
command="test command",
state="SUCCESS",
state=CommandState.SUCCESS,
exit_code=0,
log_summary="success",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def test_analyze_feedback_timeout(settings):
"""Test analyzing feedback with a TIMEOUT error."""
# Arrange
timeout_result = CommandResultSuccessFactory(
command="test command",
state=CommandState.TIMEOUT,
exit_code=1,
log_summary="timeout",
Expand All @@ -56,7 +55,6 @@ def test_analyze_feedback_network_error(settings):
"""Test analyzing feedback with a NETWORK_ERROR."""
# Arrange
network_error_result = CommandResultSuccessFactory(
command="test command",
state=CommandState.NETWORK_ERROR,
exit_code=1,
log_summary="network error",
Expand All @@ -77,21 +75,18 @@ def test_analyze_feedback_multiple_errors(settings):
# Arrange
success_result = CommandResultSuccessFactory(
num=1,
command="command1",
state=CommandState.SUCCESS,
exit_code=0,
log_summary="success",
)
network_error_result = CommandResultSuccessFactory(
num=2,
command="command2",
state=CommandState.NETWORK_ERROR,
exit_code=1,
log_summary="network error",
)
timeout_result = CommandResultSuccessFactory(
num=3,
command="command3",
state=CommandState.TIMEOUT,
exit_code=1,
log_summary="timeout",
Expand Down Expand Up @@ -132,7 +127,6 @@ def test_analyze_feedback_preserve_state(settings):
CommandInputFactory(command="find . -name '*.py'", timeout_sec=60)
]
timeout_result = CommandResultSuccessFactory(
command="test command",
state=CommandState.TIMEOUT,
exit_code=1,
log_summary="timeout",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_handle_network_error_success(settings, mock_network_error_response):
assert result.is_retry is True
assert result.error_type == "NETWORK_ERROR"
assert len(result.failed_command_results) == 1
assert result.failed_command_results[0].command == "nmap -p- 10.10.10.40"
assert result.failed_command_results[0].command.command == "nmap -p- 10.10.10.40"
assert result.failed_command_results[0].state == CommandState.NETWORK_ERROR


Expand Down Expand Up @@ -273,5 +273,5 @@ def test_handle_network_error_preserve_state(mock_handler, settings):
assert result.is_retry is True
assert result.error_type == "NETWORK_ERROR"
assert len(result.failed_command_results) == 1
assert result.failed_command_results[0].command == "nmap -p- 10.10.10.40"
assert result.failed_command_results[0].command.command == "nmap -p- 10.10.10.40"
assert result.failed_command_results[0].state == CommandState.NETWORK_ERROR
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def test_handle_timeout_not_timeout(settings):
"""Test handling timeout when the error is not a timeout."""
# Arrange
network_error_result = CommandResultSuccessFactory(
command="test command",
state=CommandState.NETWORK_ERROR,
exit_code=1,
log_summary="network error",
Expand Down Expand Up @@ -93,7 +92,7 @@ def test_handle_timeout_success(mock_handler, settings, mock_timeout_response):
assert result.is_retry is True
assert result.error_type == "TIMEOUT"
assert len(result.failed_command_results) == 1
assert result.failed_command_results[0].command == "nmap -p- 10.10.10.40"
assert result.failed_command_results[0].command.command == "nmap -p- 10.10.10.40"
assert result.failed_command_results[0].state == CommandState.TIMEOUT


Expand Down Expand Up @@ -239,5 +238,5 @@ def test_handle_timeout_preserve_state(mock_handler, settings):
assert result.is_retry is True
assert result.error_type == "TIMEOUT"
assert len(result.failed_command_results) == 1
assert result.failed_command_results[0].command == "nmap -p- 10.10.10.40"
assert result.failed_command_results[0].command.command == "nmap -p- 10.10.10.40"
assert result.failed_command_results[0].state == CommandState.TIMEOUT
8 changes: 4 additions & 4 deletions wish-log-analysis-api/docs/graph.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion wish-log-analysis-api/src/wish_log_analysis_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def lambda_handler(event: Dict[str, Any], context: Any) -> Dict[str, Any]:
"headers": {
"Content-Type": "application/json"
},
"body": json.dumps(response.model_dump())
"body": json.dumps(response.model_dump(mode="json"))
}
except Exception as e:
logger.exception("Error handling request")
Expand Down
Loading