Skip to content

Commit 06dfb65

Browse files
committed
fix(signatures): various small fixes (#284)
1 parent 74cd46f commit 06dfb65

4 files changed

Lines changed: 34 additions & 29 deletions

File tree

pyoaev/signatures/models.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ToolTimeoutInfo(BaseModel):
3434

3535
model_config = ConfigDict(extra="allow")
3636

37-
partial_results: list[str] = []
37+
partial_results: list[str] = Field(default_factory=list)
3838

3939

4040
class ToolOutput(BaseModel):
@@ -173,7 +173,8 @@ class ExecutionDetails(BaseModel):
173173
@computed_field
174174
@property
175175
def execution_message(self) -> str:
176-
return f"Current action: {self.execution_action.value} - Current status: {self.execution_status}"
176+
action = self.execution_action.value if self.execution_action else "unknown"
177+
return f"Current action: {action} - Current status: {self.execution_status}"
177178

178179
@computed_field
179180
@property
@@ -192,7 +193,9 @@ def post_execution_update(self, tool_output: ToolOutput, now: datetime) -> None:
192193
if tool_output.error_info and tool_output.error_info.exit_code != 0:
193194
self.execution_status = "failed"
194195
if tool_output.error_info.crash_timestamp:
195-
self.end_time = tool_output.error_info.crash_timestamp
196+
self.end_time = datetime.strptime(
197+
tool_output.error_info.crash_timestamp, "%Y-%m-%dT%H:%M:%SZ"
198+
)
196199
elif tool_output.timeout_info:
197200
self.execution_status = "timeout"
198201
elif tool_output.status == "partial":
@@ -216,7 +219,9 @@ class SignatureCallbackPayload(BaseModel):
216219

217220
@field_validator("execution_output_structured", mode="after")
218221
@classmethod
219-
def is_proper_signature_output_structure(cls, value: str) -> str:
222+
def is_proper_signature_output_structure(cls, value: str) -> str | None:
223+
if value is None:
224+
return None
220225
TypeAdapter(SignatureOutputStructure).validate_json(value)
221226
return value
222227

pyoaev/signatures/signature_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def post_execution_updates(
148148
@staticmethod
149149
def build_payload(
150150
execution_signatures: ExecutionSignature | list[ExecutionSignature],
151-
targets_meta: dict[str, str] | list[dict[str, str]],
151+
targets_meta: Any | list[Any],
152152
expectation_types: list[str],
153153
extra_signatures: ExtraSignatureData = ExtraSignatureData(),
154154
) -> dict[str, Any]:
@@ -235,7 +235,7 @@ def resolve_container_ip(self) -> str:
235235
"""Sniff the container's primary IPv4. Env var, hostname, then ``hostname -i``.
236236
237237
Returns:
238-
The IPv4 string, or ``'unknown'`` with a single warning when all strategies fail.
238+
The IPv4 string, or ``'unknown'`` with a warning when all strategies fail.
239239
"""
240240
if self._cached_ipv4 and self._cached_ipv4 != "unknown":
241241
return self._cached_ipv4

test/signatures/constraints/signature_manager_post_execution_constraints.feature

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,30 @@ Feature: SignatureManager post-execution constraints
1010
| source_ipv4 | 172.17.0.2 |
1111
| target_ipv4 | 10.0.0.1 |
1212
| target_hostname | host-a.internal |
13-
| start_time | 2024-06-26T06:00:00Z |
13+
| start_time | 2024-06-26T06:00:00Z |
1414
And a execution_details object containing:
1515
| key | value |
16-
| start_time | 2024-06-26T06:00:00Z |
16+
| start_time | 2024-06-26T06:00:00Z |
1717

1818
Scenario: Tool crash sets execution_status to failed and uses crash timestamp as end_time
1919
Given a tool_output containing error_info with exit_code=1 and crash_timestamp="2024-06-26T06:05:00Z"
20-
When I call post_execution_updates with the execution_details, execution_signatures and tool_output
20+
When I call post_execution_updates with the execution_details, execution_signatures and tool_output
2121
Then execution_status equals "failed"
2222
And end_time equals "2024-06-26T06:05:00Z"
23-
And the execution signature model contains every previous parameter unchanged
24-
And the execution details model contain every previous parameter pair unchanged
23+
And the execution signature model contains every previous parameter unchanged
24+
And the execution details model contain every previous parameter pair unchanged
2525

2626
Scenario: Timeout sets execution_status to timeout and includes available partial results
2727
Given a tool_output containing timeout_info with partial_results=["result-A", "result-B"]
28-
When I call post_execution_updates with the execution_details, execution_signatures and tool_output
28+
When I call post_execution_updates with the execution_details, execution_signatures and tool_output
2929
Then execution_status equals "timeout"
3030
And the returned dict contains the partial results ["result-A", "result-B"] from timeout_info
31-
And the execution signature model contains every previous parameter unchanged
32-
And the execution details model contain every previous parameter pair unchanged
31+
And the execution signature model contains every previous parameter unchanged
32+
And the execution details model contain every previous parameter pair unchanged
3333

3434
Scenario: Timeout with no partial results still sets execution_status to timeout
3535
Given a tool_output containing timeout_info with no partial results available
36-
When I call post_execution_updates with the execution_details, execution_signatures and tool_output
36+
When I call post_execution_updates with the execution_details, execution_signatures and tool_output
3737
Then execution_status equals "timeout"
38-
And the execution signature model contains every previous parameter unchanged
39-
And the execution details model contain every previous parameter pair unchanged
38+
And the execution signature model contains every previous parameter unchanged
39+
And the execution details model contain every previous parameter pair unchanged

test/signatures/features/signature_manager_post_execution.feature

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ Feature: SignatureManager post-execution execution elements update
1010
| source_ipv4 | 172.17.0.2 |
1111
| target_ipv4 | 10.0.0.1 |
1212
| target_hostname | host-a.internal |
13-
| start_time | 2024-06-26T06:00:00Z |
13+
| start_time | 2024-06-26T06:00:00Z |
1414
And a execution_details object containing:
1515
| key | value |
16-
| start_time | 2024-06-26T06:00:00Z |
16+
| start_time | 2024-06-26T06:00:00Z |
1717

1818
Scenario: Successful execution updates end_time and execution_status in execution signatures and execution details
19-
Given a tool_output indicating successful completion with no errors and no timeout
20-
When I call post_execution_updates with the execution_details, execution_signatures and tool_output
21-
Then the execution signature model contains every previous parameter unchanged
22-
And the end_time parameter in the execution signature model is a UTC ISO 8601 string
23-
And this end_time is chronologically greater than or equal to start_time "2024-06-26T06:00:00Z"
24-
And the execution details model contain every previous parameter pair unchanged
25-
And the end_time parameter in the execution details model is a datetime object
26-
And this end_time is chronologically greater than or equal to start_time "2024-06-26T06:00:00Z"
27-
And the execution_status parameter in the execution details model is equal to "success"
28-
And the execution_action parameter in the execution details model is equal to "complete"
19+
Given a tool_output indicating successful completion with no errors and no timeout
20+
When I call post_execution_updates with the execution_details, execution_signatures and tool_output
21+
Then the execution signature model contains every previous parameter unchanged
22+
And the end_time parameter in the execution signature model is a UTC ISO 8601 string
23+
And this end_time is chronologically greater than or equal to start_time "2024-06-26T06:00:00Z"
24+
And the execution details model contain every previous parameter pair unchanged
25+
And the end_time parameter in the execution details model is a datetime object
26+
And this end_time is chronologically greater than or equal to start_time "2024-06-26T06:00:00Z"
27+
And the execution_status parameter in the execution details model is equal to "success"
28+
And the execution_action parameter in the execution details model is equal to "complete"

0 commit comments

Comments
 (0)