-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_workflow.py
More file actions
71 lines (56 loc) · 2.42 KB
/
Copy pathtest_workflow.py
File metadata and controls
71 lines (56 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from datetime import UTC, datetime
from typing import Any
from unittest.mock import patch
import pytest
from cas_reference_product.models import Actor, PromptEnvelope, TraceContext
from cas_reference_product.workflow import WorkflowOrchestrator
class SuccessfulService:
def run(self: "Any", envelope: "Any") -> str:
return f"processed:{envelope.promptId}"
class FailingService:
def run(self: "Any", envelope: "Any") -> str:
raise RuntimeError("expected")
def test_orchestrator_returns_traceable_events(envelope: "Any") -> None:
fixed = datetime(2026, 6, 11, 10, 0, tzinfo=UTC)
# Patch current_traceparent so this unit test is provider-independent.
with patch(
"cas_reference_product.workflow.current_traceparent",
side_effect=lambda fallback: fallback,
):
result = WorkflowOrchestrator(
SuccessfulService(), envelope.repo, clock=lambda: fixed
).execute(envelope)
assert result.output == "processed:prompt-001"
assert [event.eventType for event in result.events] == [
"workflow.started",
"workflow.completed",
]
assert all(event.timestamp == fixed for event in result.events)
assert all(event.traceContext == envelope.traceContext for event in result.events)
def test_orchestrator_propagates_failure(envelope: "Any") -> None:
with pytest.raises(RuntimeError, match="expected"):
WorkflowOrchestrator(FailingService(), envelope.repo).execute(envelope)
def test_event_includes_tracestate_when_present(envelope: "Any") -> None:
envelope_with_tracestate = PromptEnvelope(
correlationId=envelope.correlationId,
promptId=envelope.promptId,
runId=envelope.runId,
repo=envelope.repo,
actor=Actor(id="developer", type="human"),
timestamp=envelope.timestamp,
traceContext=TraceContext(
traceparent="00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
tracestate="vendor1=value1",
),
intent=envelope.intent,
prompt=envelope.prompt,
constraints=envelope.constraints,
)
with patch(
"cas_reference_product.workflow.current_traceparent",
side_effect=lambda fallback: fallback,
):
result = WorkflowOrchestrator(
SuccessfulService(), envelope.repo
).execute(envelope_with_tracestate)
assert all(event.traceContext.tracestate == "vendor1=value1" for event in result.events)