-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_models.py
More file actions
76 lines (63 loc) · 2.27 KB
/
Copy pathtest_models.py
File metadata and controls
76 lines (63 loc) · 2.27 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
72
73
74
75
76
from typing import Any
import pytest
from pydantic import ValidationError
from cas_reference_product.models import Actor, PromptEnvelope, RunEvent, TraceContext
def test_prompt_envelope_rejects_extra_properties(envelope: "Any") -> None:
payload = envelope.model_dump()
payload["secret"] = "not-allowed"
with pytest.raises(ValidationError):
PromptEnvelope.model_validate(payload)
def test_prompt_envelope_matches_cas_contract_metadata(envelope: "Any") -> None:
payload = envelope.model_dump(mode="json")
assert payload["kind"] == "PromptEnvelope"
assert payload["schemaVersion"] == "0.1.0"
assert payload["traceContext"]["traceparent"].startswith("00-")
@pytest.mark.parametrize(
"constraints",
[
[""],
["x" * 1_001],
["No secrets", "No secrets"],
],
)
def test_prompt_envelope_enforces_cas_contract_constraints(
envelope: "Any", constraints: "Any"
) -> None:
payload = envelope.model_dump()
payload["constraints"] = constraints
with pytest.raises(ValidationError):
PromptEnvelope.model_validate(payload)
@pytest.mark.parametrize(
("model", "payload"),
[
(Actor, {"id": "developer", "type": "human", "displayName": None}),
(
TraceContext,
{
"traceparent": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01",
"tracestate": None,
},
),
(
RunEvent,
{
"correlationId": "corr-001",
"promptId": "prompt-001",
"runId": "run-001",
"repo": "Coding-Autopilot-System/cas-reference-product",
"actor": {"id": "workflow", "type": "workflow"},
"timestamp": "2026-06-11T00:00:00Z",
"traceContext": {
"traceparent": "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
},
"eventType": "workflow.started",
"sequence": 0,
"status": "running",
"message": None,
},
),
],
)
def test_contract_models_reject_explicit_null_optional_fields(model: "Any", payload: "Any") -> None:
with pytest.raises(ValidationError):
model.model_validate(payload)