Skip to content

Commit 05a1b65

Browse files
feat: act result acknowledges tools (#106)
* feat: refactor CommandResult to use Command model and add get_command_string method * feat: update command execution in BashBackend and SliverBackend to use Command object for result creation * feat: refactor command handling to use Command model across various components and tests * style: format code for consistency and readability across command-related files * style: clean up whitespace in command and command_result files for improved readability * docs: update graph visualization * feat: update command structure in integration tests to use Command model for improved consistency * docs: update graph visualization --------- Co-authored-by: GitHub Action <action@github.com>
1 parent 57840e8 commit 05a1b65

File tree

30 files changed

+326
-72
lines changed

30 files changed

+326
-72
lines changed

wish-api/tests/test_placeholder.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Placeholder test file for wish-api."""
2+
3+
def test_placeholder():
4+
"""Placeholder test to satisfy pytest configuration."""
5+
assert True

wish-command-execution/src/wish_command_execution/backend/bash.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,14 @@ async def execute_command(self, wish: Wish, command: str, cmd_num: int, log_file
132132
Commands are executed in the working directory /app/{run_id}/ to isolate
133133
command execution from the application source code.
134134
"""
135-
# Create command result
136-
result = CommandResult.create(cmd_num, command, log_files, timeout_sec)
135+
# Create command result with Command object
136+
from wish_models.command_result.command import Command, CommandType
137+
command_obj = Command(
138+
command=command,
139+
tool_type=CommandType.BASH,
140+
tool_parameters={"timeout": timeout_sec}
141+
)
142+
result = CommandResult.create(cmd_num, command_obj, log_files, timeout_sec)
137143

138144
wish.command_results.append(result)
139145

wish-command-execution/src/wish_command_execution/backend/sliver.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,14 @@ async def execute_command(self, wish: Wish, command: str, cmd_num: int, log_file
6767
log_files: The log files to write output to.
6868
timeout_sec: The timeout in seconds for this command.
6969
"""
70-
# Create command result
71-
result = CommandResult.create(cmd_num, command, log_files, timeout_sec)
70+
# Create command result with Command object
71+
from wish_models.command_result.command import Command, CommandType
72+
command_obj = Command(
73+
command=command,
74+
tool_type=CommandType.BASH, # Sliver executes shell commands
75+
tool_parameters={"timeout": timeout_sec, "session_id": self.session_id}
76+
)
77+
result = CommandResult.create(cmd_num, command_obj, log_files, timeout_sec)
7278
wish.command_results.append(result)
7379

7480
try:

wish-command-execution/tests/backend/test_bash_backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ async def test_execute_command(self, mock_makedirs, mock_open, mock_popen, backe
7676

7777
# Verify that the command result was added to the wish
7878
assert len(wish.command_results) == 1
79-
assert wish.command_results[0].command == cmd
79+
assert wish.command_results[0].command.command == cmd
8080
assert wish.command_results[0].num == cmd_num
8181

8282
# Verify that the command was added to running_commands
@@ -113,7 +113,7 @@ async def test_execute_command_subprocess_error(
113113

114114
# Verify that the command result was added to the wish
115115
assert len(wish.command_results) == 1
116-
assert wish.command_results[0].command == cmd
116+
assert wish.command_results[0].command.command == cmd
117117
assert wish.command_results[0].num == cmd_num
118118

119119
# Verify that the command result was updated with the error state

wish-command-execution/tests/backend/test_sliver_backend.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ async def test_execute_command(sliver_backend, wish, log_files, mock_sliver_clie
9292

9393
# Check that the command result was added to the wish
9494
assert len(wish.command_results) == 1
95-
assert wish.command_results[0].command == "whoami"
95+
assert wish.command_results[0].command.command == "whoami"
9696
assert wish.command_results[0].num == 1
9797

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

113115
# Cancel the command

wish-command-generation-api/src/wish_command_generation_api/nodes/network_error_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def handle_network_error(state: Annotated[GraphState, "Current state"], settings
9999

100100
# Format the feedback as JSON string
101101
feedback_str = (
102-
json.dumps([result.model_dump() for result in state.failed_command_results], ensure_ascii=False)
102+
json.dumps([result.model_dump(mode="json") for result in state.failed_command_results], ensure_ascii=False)
103103
if state.failed_command_results else "[]"
104104
)
105105

wish-command-generation-api/src/wish_command_generation_api/nodes/timeout_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def handle_timeout(state: Annotated[GraphState, "Current state"], settings_obj:
107107

108108
# Format the feedback as JSON string
109109
feedback_str = (
110-
json.dumps([result.model_dump() for result in state.failed_command_results], ensure_ascii=False)
110+
json.dumps([result.model_dump(mode="json") for result in state.failed_command_results], ensure_ascii=False)
111111
if state.failed_command_results else "[]"
112112
)
113113

wish-command-generation-api/tests/integrated/test_api_with_feedback.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ def test_lambda_handler_with_feedback(settings):
2121
act_result = [
2222
{
2323
"num": 1,
24-
"command": "nmap -p- 10.10.10.40",
24+
"command": {
25+
"command": "nmap -p- 10.10.10.40",
26+
"tool_type": "bash",
27+
"tool_parameters": {}
28+
},
2529
"state": "TIMEOUT",
2630
"exit_code": 1,
2731
"log_summary": "timeout",
@@ -78,7 +82,11 @@ def test_lambda_handler_with_network_error_feedback(settings):
7882
act_result = [
7983
{
8084
"num": 1,
81-
"command": "nmap -p- 10.10.10.40",
85+
"command": {
86+
"command": "nmap -p- 10.10.10.40",
87+
"tool_type": "bash",
88+
"tool_parameters": {}
89+
},
8290
"state": "NETWORK_ERROR",
8391
"exit_code": 1,
8492
"log_summary": "Connection closed by peer",
@@ -135,7 +143,11 @@ def test_lambda_handler_with_multiple_feedback(settings):
135143
act_result = [
136144
{
137145
"num": 1,
138-
"command": "nmap -p1-1000 10.10.10.40",
146+
"command": {
147+
"command": "nmap -p1-1000 10.10.10.40",
148+
"tool_type": "bash",
149+
"tool_parameters": {}
150+
},
139151
"state": "SUCCESS",
140152
"exit_code": 0,
141153
"log_summary": "Scan completed successfully",
@@ -148,7 +160,11 @@ def test_lambda_handler_with_multiple_feedback(settings):
148160
},
149161
{
150162
"num": 2,
151-
"command": "nmap -p1001-65535 10.10.10.40",
163+
"command": {
164+
"command": "nmap -p1001-65535 10.10.10.40",
165+
"tool_type": "bash",
166+
"tool_parameters": {}
167+
},
152168
"state": "TIMEOUT",
153169
"exit_code": 1,
154170
"log_summary": "timeout",

wish-command-generation-api/tests/integrated/test_docs_integration.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66
from wish_models.command_result import CommandResult, CommandState, LogFiles
7+
from wish_models.command_result.command import Command, CommandType
78
from wish_models.settings import Settings
89
from wish_models.utc_datetime import UtcDatetime
910

@@ -63,7 +64,11 @@ def test_command_generation_with_network_error_feedback(settings):
6364
act_result = [
6465
CommandResult(
6566
num=1,
66-
command="smbclient -N //10.10.10.40/Users --option='client min protocol'=LANMAN1",
67+
command=Command(
68+
command="smbclient -N //10.10.10.40/Users --option='client min protocol'=LANMAN1",
69+
tool_type=CommandType.BASH,
70+
tool_parameters={}
71+
),
6772
state=CommandState.NETWORK_ERROR,
6873
exit_code=1,
6974
log_summary="Connection closed by peer",
@@ -118,7 +123,11 @@ def test_command_generation_with_timeout_feedback(settings):
118123
act_result = [
119124
CommandResult(
120125
num=1,
121-
command="nmap -p- 10.10.10.40",
126+
command=Command(
127+
command="nmap -p- 10.10.10.40",
128+
tool_type=CommandType.BASH,
129+
tool_parameters={}
130+
),
122131
state=CommandState.TIMEOUT,
123132
exit_code=1,
124133
log_summary="timeout",

wish-command-generation-api/tests/integrated/test_graph_with_feedback.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66
from wish_models.command_result import CommandResult, CommandState, LogFiles
7+
from wish_models.command_result.command import Command, CommandType
78
from wish_models.settings import Settings
89
from wish_models.utc_datetime import UtcDatetime
910

@@ -66,7 +67,11 @@ def test_graph_with_timeout_feedback(settings):
6667
act_result = [
6768
CommandResult(
6869
num=1,
69-
command="nmap -p- 10.10.10.40",
70+
command=Command(
71+
command="nmap -p- 10.10.10.40",
72+
tool_type=CommandType.BASH,
73+
tool_parameters={}
74+
),
7075
state=CommandState.TIMEOUT,
7176
exit_code=1,
7277
log_summary="timeout",
@@ -126,7 +131,11 @@ def test_graph_with_network_error_feedback(settings):
126131
act_result = [
127132
CommandResult(
128133
num=1,
129-
command="nmap -p- 10.10.10.40",
134+
command=Command(
135+
command="nmap -p- 10.10.10.40",
136+
tool_type=CommandType.BASH,
137+
tool_parameters={}
138+
),
130139
state=CommandState.NETWORK_ERROR,
131140
exit_code=1,
132141
log_summary="Connection closed by peer",
@@ -186,7 +195,11 @@ def test_graph_with_unknown_error_feedback(settings):
186195
act_result = [
187196
CommandResult(
188197
num=1,
189-
command="nmap -p- 10.10.10.40",
198+
command=Command(
199+
command="nmap -p- 10.10.10.40",
200+
tool_type=CommandType.BASH,
201+
tool_parameters={}
202+
),
190203
state=CommandState.OTHERS,
191204
exit_code=1,
192205
log_summary="Unknown error",

0 commit comments

Comments
 (0)