-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
130 lines (103 loc) · 3.45 KB
/
Copy pathconftest.py
File metadata and controls
130 lines (103 loc) · 3.45 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"""Shared copies of the bundled synthetic reference inputs."""
import json
from datetime import date
from pathlib import Path
from typing import Any
import pytest
from contextsafe.evidence import (
CANONICAL_JSON_MEDIA_TYPE,
CANONICAL_JSON_SOURCE_TYPE,
EvidenceMetadata,
EvidenceScope,
build_evidence_scope,
parse_evidence_metadata,
)
from contextsafe.models import Checkpoint
from contextsafe.plan import (
CleanupContract,
EnvironmentContract,
ExecutionPlan,
PlanOwners,
SyntheticNamespace,
)
ROOT = Path(__file__).resolve().parents[1]
REFERENCE = ROOT / "fixtures" / "reference"
def _read_json(name: str) -> dict[str, Any]:
value = json.loads((REFERENCE / name).read_text(encoding="utf-8"))
assert isinstance(value, dict)
return value
@pytest.fixture
def case_json() -> dict[str, Any]:
"""Return a fresh canonical case object."""
return _read_json("case.json")
@pytest.fixture
def observations_json() -> dict[str, Any]:
"""Return a fresh canonical observation-set object."""
return _read_json("observations.json")
@pytest.fixture
def rules_json() -> dict[str, Any]:
"""Return a fresh rule-set object."""
return _read_json("rules.json")
@pytest.fixture
def evidence_source_json() -> dict[str, Any]:
"""Return a fresh code-only boundary envelope."""
return _read_json("evidence-source.json")
@pytest.fixture
def execution_plan() -> ExecutionPlan:
"""Return a parsed-shape, visibly synthetic unsigned execution plan."""
environment = EnvironmentContract(
classification="staging",
name="SYNTHETIC-STAGING-A",
non_production_attested=True,
production_access_prohibited=True,
)
owners = PlanOwners(
technical_owner_id="TEST-TECHNICAL-OWNER",
clinical_owner_id="TEST-CLINICAL-OWNER",
privacy_owner_id="TEST-PRIVACY-OWNER",
cleanup_owner_id="TEST-CLEANUP-OWNER",
)
cleanup = CleanupContract(
owner_id=owners.cleanup_owner_id,
system_ids=("SYS-STAGING-EHR",),
due_on=date(2026, 8, 1),
)
return ExecutionPlan(
schema_version="contextsafe.plan/1.0.0",
plan_id="PLAN-SYNTHETIC-TEST",
engagement_id="ENG-SYNTHETIC-TEST",
engagement_sha256="1" * 64,
compiled_pack_sha256="2" * 64,
environment=environment,
target_hosts=("staging.contextsafe.invalid",),
synthetic_namespace=SyntheticNamespace(
system="urn:contextsafe:synthetic", value_prefix="CSYN-"
),
owners=owners,
cleanup=cleanup,
checkpoints=tuple(Checkpoint),
case_tokens=("CSYN-CTP-I01",),
valid_from=date(2026, 7, 13),
valid_until=date(2026, 8, 1),
)
@pytest.fixture
def evidence_scope(execution_plan: ExecutionPlan) -> EvidenceScope:
"""Bind the reference source to its synthetic EHR checkpoint."""
return build_evidence_scope(
execution_plan,
case_token=execution_plan.case_tokens[0],
checkpoint="ehr",
source_type=CANONICAL_JSON_SOURCE_TYPE,
media_type=CANONICAL_JSON_MEDIA_TYPE,
)
@pytest.fixture
def evidence_metadata() -> EvidenceMetadata:
"""Return deterministic, opaque provenance for store tests."""
return parse_evidence_metadata(
{
"captured_at": "2026-07-13T12:00:00Z",
"collector_id": "TEST-COLLECTOR",
"system_id": "SYS-STAGING-EHR",
"system_version": "fixture-1.0",
}
)