gts-agency-python-sdk 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. agency_sdk/__init__.py +0 -0
  2. agency_sdk/auth_hooks.py +55 -0
  3. agency_sdk/client.py +212 -0
  4. agency_sdk/credentials.py +54 -0
  5. agency_sdk/delegates/__init__.py +0 -0
  6. agency_sdk/delegates/annotations_client.py +495 -0
  7. agency_sdk/delegates/annotations_dto.py +200 -0
  8. agency_sdk/delegates/base_client.py +126 -0
  9. agency_sdk/delegates/datasets_client.py +109 -0
  10. agency_sdk/delegates/datasets_dto.py +81 -0
  11. agency_sdk/delegates/datasource_client.py +44 -0
  12. agency_sdk/delegates/datasource_dto.py +107 -0
  13. agency_sdk/delegates/files_client.py +184 -0
  14. agency_sdk/delegates/files_dto.py +36 -0
  15. agency_sdk/delegates/gateway_client.py +81 -0
  16. agency_sdk/delegates/gateway_dto.py +37 -0
  17. agency_sdk/delegates/ontology_client.py +203 -0
  18. agency_sdk/delegates/ontology_dto.py +221 -0
  19. agency_sdk/delegates/prompts_client.py +56 -0
  20. agency_sdk/delegates/rules_client.py +33 -0
  21. agency_sdk/delegates/rules_dto.py +108 -0
  22. agency_sdk/delegates/session_client.py +95 -0
  23. agency_sdk/delegates/session_dto.py +94 -0
  24. agency_sdk/delegates/session_templates_client.py +23 -0
  25. agency_sdk/delegates/session_templates_dto.py +27 -0
  26. agency_sdk/delegates/session_vault_client.py +135 -0
  27. agency_sdk/delegates/session_vault_dto.py +75 -0
  28. agency_sdk/delegates/work_queue_client.py +230 -0
  29. agency_sdk/delegates/work_queue_dto.py +127 -0
  30. agency_sdk/domain.py +140 -0
  31. agency_sdk/observability/__init__.py +60 -0
  32. agency_sdk/observability/auth.py +15 -0
  33. agency_sdk/observability/bootstrap.py +344 -0
  34. agency_sdk/test/__init__.py +0 -0
  35. agency_sdk/test/conftest.py +106 -0
  36. agency_sdk/test/test_annotations_client.py +599 -0
  37. agency_sdk/test/test_annotations_dto.py +299 -0
  38. agency_sdk/test/test_base_client.py +153 -0
  39. agency_sdk/test/test_client_facade.py +105 -0
  40. agency_sdk/test/test_credentials.py +67 -0
  41. agency_sdk/test/test_files_client.py +264 -0
  42. agency_sdk/test/test_files_dto.py +93 -0
  43. agency_sdk/test/test_gateway_dto.py +70 -0
  44. agency_sdk/test/test_gateway_facade.py +229 -0
  45. agency_sdk/test/test_gateway_openai.py +76 -0
  46. agency_sdk/test/test_observability_auth.py +125 -0
  47. agency_sdk/test/test_observability_facade_threadsafety.py +50 -0
  48. agency_sdk/test/test_observability_langfuse.py +76 -0
  49. agency_sdk/test/test_observability_packaging.py +78 -0
  50. agency_sdk/test/test_observability_pipeline.py +246 -0
  51. agency_sdk/test/test_ontology_client.py +152 -0
  52. agency_sdk/test/test_ontology_dto.py +158 -0
  53. agency_sdk/test/test_session_client.py +128 -0
  54. agency_sdk/test/test_session_dto.py +75 -0
  55. agency_sdk/test/test_session_templates_client.py +36 -0
  56. agency_sdk/test/test_session_templates_dto.py +45 -0
  57. agency_sdk/test/test_session_vault_client.py +151 -0
  58. agency_sdk/test/test_session_vault_dto.py +27 -0
  59. agency_sdk/test/test_stub_requests.py +39 -0
  60. agency_sdk/test/test_work_queue_client.py +388 -0
  61. agency_sdk/test/test_work_queue_dto.py +233 -0
  62. gts_agency_python_sdk-0.0.1.dist-info/METADATA +221 -0
  63. gts_agency_python_sdk-0.0.1.dist-info/RECORD +66 -0
  64. gts_agency_python_sdk-0.0.1.dist-info/WHEEL +5 -0
  65. gts_agency_python_sdk-0.0.1.dist-info/licenses/LICENSE +201 -0
  66. gts_agency_python_sdk-0.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,152 @@
1
+ """Offline protocol tests for AgencyOntologyClient.export.
2
+
3
+ Pins the Control Plane contract for `GET /api/ontologies/{id}/export`
4
+ (query params `o`, `format`, `branch`, `version`; text body vs zip bytes)
5
+ documented in the ontology export API reference. `export_snapshot` is the
6
+ agent-facing path: JSON parsed into `OntologySnapshot`.
7
+ """
8
+
9
+ import pytest
10
+ import requests
11
+
12
+ from agency_sdk.delegates.ontology_client import AgencyOntologyClient
13
+ from agency_sdk.delegates.ontology_dto import Ontology, OntologySnapshot
14
+ from agency_sdk.test.test_ontology_dto import ONTOLOGY_JSON, SNAPSHOT_JSON
15
+
16
+
17
+ @pytest.fixture
18
+ def client(fake_credentials):
19
+ return AgencyOntologyClient(token_supplier=fake_credentials, base_url="http://cp.test/")
20
+
21
+
22
+ class TestList:
23
+ def test_list_hits_ontologies_endpoint_paged(self, client, stub_requests):
24
+ stub_requests.queue(json_data={"page": {"page": 0, "size": 10, "total": 1}, "items": [ONTOLOGY_JSON]})
25
+
26
+ result = client.list(organisation_id=2)
27
+
28
+ call = stub_requests.calls[0]
29
+ assert call.method == "GET"
30
+ assert call.url == "http://cp.test/api/ontologies"
31
+ assert call.kwargs["params"] == {"o": "2", "p": "0", "s": "10"}
32
+ assert [item.name for item in result.items] == ["claims"]
33
+ assert isinstance(result.items[0], Ontology)
34
+ assert result.items[0].id == ONTOLOGY_JSON["id"]
35
+ assert result.page.total == 1
36
+
37
+ def test_list_forwards_pagination(self, client, stub_requests):
38
+ stub_requests.queue(json_data={"page": {"page": 1, "size": 5, "total": 0}, "items": []})
39
+
40
+ client.list(organisation_id=9, page=1, size=5)
41
+
42
+ assert stub_requests.calls[0].kwargs["params"] == {"o": "9", "p": "1", "s": "5"}
43
+
44
+ def test_list_forwards_kind_filter(self, client, stub_requests):
45
+ stub_requests.queue(json_data={"page": {"page": 0, "size": 10, "total": 0}, "items": []})
46
+
47
+ client.list(organisation_id=2, kind="upper")
48
+
49
+ assert stub_requests.calls[0].kwargs["params"] == {"o": "2", "p": "0", "s": "10", "kind": "upper"}
50
+
51
+
52
+ class TestExport:
53
+ def test_default_export_sends_org_and_returns_text(self, client, stub_requests):
54
+ stub_requests.queue(text='{"entities":{},"relations":{}}')
55
+
56
+ body = client.export(ontology_id="ont-1", organisation_id=2)
57
+
58
+ call = stub_requests.calls[0]
59
+ assert call.method == "GET"
60
+ assert call.url == "http://cp.test/api/ontologies/ont-1/export"
61
+ assert call.kwargs["params"] == {"o": "2"}
62
+ assert "Content-Type" not in call.kwargs["headers"]
63
+ assert call.kwargs["headers"]["Authorization"] == "Bearer test-token"
64
+ assert body == '{"entities":{},"relations":{}}'
65
+
66
+ @pytest.mark.parametrize(
67
+ "export_format",
68
+ ["json", "owl", "turtle", "shacl", "shacl-package", "package"],
69
+ )
70
+ def test_text_formats_are_passed_as_query_param(self, client, stub_requests, export_format):
71
+ stub_requests.queue(text="export-body")
72
+
73
+ body = client.export(ontology_id="ont-1", organisation_id=2, export_format=export_format)
74
+
75
+ assert stub_requests.calls[0].kwargs["params"] == {"o": "2", "format": export_format}
76
+ assert body == "export-body"
77
+
78
+ def test_branch_and_version_are_forwarded(self, client, stub_requests):
79
+ stub_requests.queue(text="v")
80
+
81
+ client.export(
82
+ ontology_id="ont-1",
83
+ organisation_id=2,
84
+ export_format="turtle",
85
+ branch="main",
86
+ version="1.0.0",
87
+ )
88
+
89
+ assert stub_requests.calls[0].kwargs["params"] == {
90
+ "o": "2",
91
+ "format": "turtle",
92
+ "branch": "main",
93
+ "version": "1.0.0",
94
+ }
95
+
96
+ def test_http_errors_propagate(self, client, stub_requests):
97
+ stub_requests.queue(json_data={"error": "Unsupported format: ison"}, status_code=400)
98
+
99
+ with pytest.raises(requests.HTTPError):
100
+ client.export(ontology_id="ont-1", organisation_id=2, export_format="ison")
101
+
102
+ def test_zip_format_raises_rather_than_decoding_as_text(self, client, stub_requests):
103
+ with pytest.raises(ValueError, match="binary"):
104
+ client.export(ontology_id="ont-1", organisation_id=2, export_format="package-zip")
105
+
106
+ assert stub_requests.calls == []
107
+
108
+
109
+ class TestExportBytes:
110
+ def test_zip_returns_raw_bytes(self, client, stub_requests):
111
+ stub_requests.queue(content_bytes=b"PK\x03\x04zip-bytes")
112
+
113
+ body = client.export_bytes(ontology_id="ont-1", organisation_id=2, export_format="package-zip")
114
+
115
+ call = stub_requests.calls[0]
116
+ assert call.method == "GET"
117
+ assert call.url == "http://cp.test/api/ontologies/ont-1/export"
118
+ assert call.kwargs["params"] == {"o": "2", "format": "package-zip"}
119
+ assert body == b"PK\x03\x04zip-bytes"
120
+
121
+ def test_text_format_still_returns_content_bytes(self, client, stub_requests):
122
+ stub_requests.queue(content_bytes=b"<http://ex> a owl:Class .")
123
+
124
+ body = client.export_bytes(ontology_id="ont-1", organisation_id=2, export_format="turtle")
125
+
126
+ assert body == b"<http://ex> a owl:Class ."
127
+
128
+
129
+ class TestExportSnapshot:
130
+ def test_parses_json_export_into_typed_snapshot(self, client, stub_requests):
131
+ stub_requests.queue(json_data=SNAPSHOT_JSON)
132
+
133
+ snapshot = client.export_snapshot(ontology_id="ont-1", organisation_id=2)
134
+
135
+ call = stub_requests.calls[0]
136
+ assert call.url == "http://cp.test/api/ontologies/ont-1/export"
137
+ assert call.kwargs["params"] == {"o": "2", "format": "json"}
138
+ assert isinstance(snapshot, OntologySnapshot)
139
+ assert snapshot.entities["entity_1768310108685_hkrzizdts"].label == "Test"
140
+ assert len(snapshot.relations) == 1
141
+
142
+ def test_forwards_branch_and_version(self, client, stub_requests):
143
+ stub_requests.queue(json_data={"entities": {}, "relations": {}})
144
+
145
+ client.export_snapshot(ontology_id="ont-1", organisation_id=2, branch="dev", version="2.0.0")
146
+
147
+ assert stub_requests.calls[0].kwargs["params"] == {
148
+ "o": "2",
149
+ "format": "json",
150
+ "branch": "dev",
151
+ "version": "2.0.0",
152
+ }
@@ -0,0 +1,158 @@
1
+ """DTO tests for the ontology export snapshot.
2
+
3
+ JSON transcribed from `OntologySnapshot` / `EntitySnapshot` / `RelationSnapshot`
4
+ / `PropertySnapshot` in gts-agency `crates/ontology/src/api/dto.rs`. The export
5
+ handler pretty-prints that struct with serde's default snake_case field names
6
+ (no `rename_all`), so these models use raw snake_case — unlike the camelCase
7
+ mappings DTOs in the same module.
8
+ """
9
+
10
+ from agency_sdk.delegates.ontology_dto import (
11
+ BINARY_EXPORT_FORMATS,
12
+ EntitySnapshot,
13
+ Ontology,
14
+ OntologySnapshot,
15
+ OntologyStatus,
16
+ PropertySnapshot,
17
+ RelationSnapshot,
18
+ is_binary_export_format,
19
+ )
20
+
21
+ #: List-view item transcribed from `Ontology` in dto.rs (snake_case, no rename_all).
22
+ ONTOLOGY_JSON = {
23
+ "id": "b8a45108-9952-4202-88d6-5cb1fadea23d",
24
+ "name": "claims",
25
+ "display_name": "Claims",
26
+ "description": "Working claims ontology",
27
+ "status": "published",
28
+ "kind": "domain",
29
+ "created_at": "2026-08-01T00:00:00Z",
30
+ "updated_at": "2026-08-31T00:00:00Z",
31
+ "organization_id": 2,
32
+ }
33
+
34
+ #: Exact structure from `test_ontology_snapshot_from_raw_json` in dto.rs.
35
+ SNAPSHOT_JSON = {
36
+ "entities": {
37
+ "entity_1768310108685_hkrzizdts": {
38
+ "id": "entity_1768310108685_hkrzizdts",
39
+ "uri": "test",
40
+ "label": "Test",
41
+ "description": "A general test",
42
+ "entity_type": "Class",
43
+ "properties": {
44
+ "id": {"type": "string", "required": True},
45
+ "description": {"type": "string", "required": True},
46
+ },
47
+ },
48
+ "entity_1768310149294_rzjag4906": {
49
+ "id": "entity_1768310149294_rzjag4906",
50
+ "uri": "unit-test",
51
+ "label": "Unit Test",
52
+ "description": "A test for a single unit of work.",
53
+ "entity_type": "Class",
54
+ "properties": {
55
+ "id": {"type": "string", "required": True},
56
+ "description": {"type": "string", "required": True},
57
+ },
58
+ },
59
+ },
60
+ "relations": {
61
+ "relationship_1768310190610_vt4ivit9w": {
62
+ "id": "relationship_1768310190610_vt4ivit9w",
63
+ "uri": "isa",
64
+ "label": "isa",
65
+ "description": "",
66
+ "source_id": "entity_1768310149294_rzjag4906",
67
+ "target_id": "entity_1768310108685_hkrzizdts",
68
+ "relation_type": "ObjectProperty",
69
+ "properties": {},
70
+ }
71
+ },
72
+ }
73
+
74
+
75
+ def test_snapshot_deserialises_entities_and_relations():
76
+ snapshot = OntologySnapshot.model_validate(SNAPSHOT_JSON)
77
+
78
+ assert len(snapshot.entities) == 2
79
+ entity = snapshot.entities["entity_1768310108685_hkrzizdts"]
80
+ assert isinstance(entity, EntitySnapshot)
81
+ assert entity.label == "Test"
82
+ assert entity.entity_type == "Class"
83
+ assert entity.properties["id"] == {"type": "string", "required": True}
84
+ assert entity.aliases == []
85
+
86
+ relation = snapshot.relations["relationship_1768310190610_vt4ivit9w"]
87
+ assert isinstance(relation, RelationSnapshot)
88
+ assert relation.source_id == "entity_1768310149294_rzjag4906"
89
+ assert relation.target_id == "entity_1768310108685_hkrzizdts"
90
+ assert relation.relation_type == "ObjectProperty"
91
+ assert relation.property_id is None
92
+ assert relation.min_count is None
93
+ assert relation.max_count is None
94
+
95
+ assert snapshot.properties == {}
96
+
97
+
98
+ def test_empty_snapshot_defaults_all_maps():
99
+ snapshot = OntologySnapshot.model_validate({})
100
+
101
+ assert snapshot.entities == {}
102
+ assert snapshot.relations == {}
103
+ assert snapshot.properties == {}
104
+
105
+
106
+ def test_property_snapshot_optional_sub_property_of():
107
+ declared = PropertySnapshot.model_validate(
108
+ {
109
+ "id": "prop_has_role",
110
+ "uri": "hasRole",
111
+ "label": "has role",
112
+ "description": "A role held by the subject",
113
+ "sub_property_of": "prop_has_attribute",
114
+ }
115
+ )
116
+
117
+ assert declared.sub_property_of == "prop_has_attribute"
118
+ assert declared.properties == {}
119
+
120
+
121
+ def test_snapshot_accepts_additive_server_fields():
122
+ snapshot = OntologySnapshot.model_validate({**SNAPSHOT_JSON, "future_field": "ok"})
123
+
124
+ assert snapshot.entities["entity_1768310108685_hkrzizdts"].label == "Test"
125
+
126
+
127
+ def test_ontology_list_item_deserialises_snake_case_fields():
128
+ ontology = Ontology.model_validate(ONTOLOGY_JSON)
129
+
130
+ assert ontology.id == "b8a45108-9952-4202-88d6-5cb1fadea23d"
131
+ assert ontology.name == "claims"
132
+ assert ontology.display_name == "Claims"
133
+ assert ontology.status == OntologyStatus.PUBLISHED
134
+ assert ontology.kind == "domain"
135
+ assert ontology.organization_id == 2
136
+
137
+
138
+ def test_ontology_kind_defaults_to_domain_when_omitted():
139
+ payload = {k: v for k, v in ONTOLOGY_JSON.items() if k != "kind"}
140
+ ontology = Ontology.model_validate(payload)
141
+
142
+ assert ontology.kind == "domain"
143
+
144
+
145
+ def test_ontology_display_name_is_optional():
146
+ payload = {k: v for k, v in ONTOLOGY_JSON.items() if k != "display_name"}
147
+ ontology = Ontology.model_validate(payload)
148
+
149
+ assert ontology.display_name is None
150
+
151
+
152
+ def test_binary_export_formats_match_server_aliases():
153
+ assert BINARY_EXPORT_FORMATS == frozenset({"package-zip", "package-separate", "zip"})
154
+ assert is_binary_export_format("package-zip")
155
+ assert is_binary_export_format("ZIP")
156
+ assert not is_binary_export_format("package")
157
+ assert not is_binary_export_format(None)
158
+ assert not is_binary_export_format("json")
@@ -0,0 +1,128 @@
1
+ """Offline protocol tests for AgencySessionClient.
2
+
3
+ Pins the exact wire contract of the session update command
4
+ (`POST /api/sessions/{id}/_command {command:"update", organisation, update:{…}}`)
5
+ and the delegate's two-method surface. The agent INHERITS a dispatched session
6
+ via `attach` and reports progress via `update`; it must NEVER self-register, so
7
+ `register` is deliberately absent.
8
+ """
9
+
10
+ import pytest
11
+
12
+ from agency_sdk.delegates.session_client import AgencySessionClient
13
+ from agency_sdk.delegates.session_dto import SessionCommandResponse, SessionStatus
14
+
15
+
16
+ @pytest.fixture
17
+ def client(fake_credentials):
18
+ return AgencySessionClient(token_supplier=fake_credentials, base_url="http://cp.test/")
19
+
20
+
21
+ class TestAttach:
22
+ def test_attach_records_the_session_as_update_target(self, client, stub_requests):
23
+ client.attach("sess-abc")
24
+
25
+ assert client.session_id == "sess-abc"
26
+ assert stub_requests.calls == [] # no HTTP — inherit, do not create
27
+
28
+ def test_register_is_not_exposed(self, client):
29
+ assert not hasattr(client, "register")
30
+ assert not hasattr(client, "register_session")
31
+
32
+
33
+ class TestUpdate:
34
+ def test_update_posts_command_envelope_for_attached_session(self, client, stub_requests):
35
+ stub_requests.queue(json_data={"success": True, "message": "updated"})
36
+ client.attach("sess-abc")
37
+
38
+ result = client.update(organisation_id=2, status=SessionStatus.IN_PROGRESS)
39
+
40
+ call = stub_requests.calls[0]
41
+ assert call.method == "POST"
42
+ assert call.url == "http://cp.test/api/sessions/sess-abc/_command"
43
+ assert call.kwargs["params"] == {"o": "2"}
44
+ assert call.kwargs["json"] == {
45
+ "command": "update",
46
+ "organisation": 2,
47
+ "update": {"status": 2},
48
+ }
49
+ assert isinstance(result, SessionCommandResponse)
50
+ assert result.success is True
51
+
52
+ def test_update_marshals_plain_int_status_without_inferring(self, client, stub_requests):
53
+ stub_requests.queue(json_data={"success": True, "message": "ok"})
54
+
55
+ client.update(organisation_id=2, status=-1, session_id="sess-x")
56
+
57
+ assert stub_requests.calls[0].kwargs["json"]["update"] == {"status": -1}
58
+
59
+ def test_update_includes_only_provided_optional_fields(self, client, stub_requests):
60
+ stub_requests.queue(json_data={"success": True, "message": "ok"})
61
+
62
+ client.update(
63
+ organisation_id=2,
64
+ status=SessionStatus.COMPLETED,
65
+ session_id="sess-x",
66
+ result={"notes": 17},
67
+ events=[{"event_type": "done"}],
68
+ metrics={"tokens": 5},
69
+ error="boom",
70
+ logs="line1\nline2",
71
+ )
72
+
73
+ update = stub_requests.calls[0].kwargs["json"]["update"]
74
+ assert update == {
75
+ "status": 0,
76
+ "result": {"notes": 17},
77
+ "events": [{"event_type": "done"}],
78
+ "metrics": {"tokens": 5},
79
+ "error": "boom",
80
+ "logs": "line1\nline2",
81
+ }
82
+
83
+ def test_update_explicit_session_id_overrides_attached(self, client, stub_requests):
84
+ stub_requests.queue(json_data={"success": True, "message": "ok"})
85
+ client.attach("attached")
86
+
87
+ client.update(organisation_id=2, status=SessionStatus.IN_PROGRESS, session_id="explicit")
88
+
89
+ assert stub_requests.calls[0].url == "http://cp.test/api/sessions/explicit/_command"
90
+
91
+ def test_update_without_target_raises_before_network(self, client, stub_requests):
92
+ with pytest.raises(ValueError):
93
+ client.update(organisation_id=2, status=SessionStatus.IN_PROGRESS)
94
+
95
+ assert stub_requests.calls == []
96
+
97
+ def test_update_propagates_http_errors(self, client, stub_requests):
98
+ import requests
99
+
100
+ stub_requests.queue(json_data={"message": "not found"}, status_code=404)
101
+ client.attach("missing")
102
+
103
+ with pytest.raises(requests.HTTPError):
104
+ client.update(organisation_id=2, status=SessionStatus.IN_PROGRESS)
105
+
106
+ def test_update_retries_a_transient_connection_error(self, client, monkeypatch):
107
+ # update is idempotent, so it opts into connection-retry — a transient blip on the
108
+ # first send must not surface to the agent's reporting path.
109
+ import requests
110
+
111
+ from agency_sdk.test.conftest import StubResponse
112
+
113
+ monkeypatch.setattr("agency_sdk.delegates.base_client.time.sleep", lambda s: None)
114
+ calls = {"n": 0}
115
+
116
+ def flaky(**kwargs):
117
+ calls["n"] += 1
118
+ if calls["n"] == 1:
119
+ raise requests.ConnectionError("blip")
120
+ return StubResponse(json_data={"success": True, "message": "ok"})
121
+
122
+ monkeypatch.setattr(requests, "request", flaky)
123
+ client.attach("sess-abc")
124
+
125
+ result = client.update(organisation_id=2, status=SessionStatus.IN_PROGRESS)
126
+
127
+ assert result.success is True
128
+ assert calls["n"] == 2 # retried past the transient blip
@@ -0,0 +1,75 @@
1
+ """DTO tests for the session-reporting delegate.
2
+
3
+ `SessionCommandResponse` is transcribed from the live server schema
4
+ (`SessionCommandResponse` / `SessionUpdateCommand` in gts-agency-control, per the
5
+ design's §6.0 "transcribe, never assert" rule). `SessionStatus` encodes the
6
+ -1/0/2 status int map (③ `control_plane_client.py:176,179`). `AnalyticsEvent` is
7
+ the cross-agent shared event shape promoted verbatim from ③'s `event.py`.
8
+ """
9
+
10
+ from datetime import UTC, datetime
11
+
12
+ from agency_sdk.delegates.session_dto import AnalyticsEvent, SessionCommandResponse, SessionStatus
13
+
14
+
15
+ def test_session_status_int_map():
16
+ assert int(SessionStatus.FAILED) == -1
17
+ assert int(SessionStatus.COMPLETED) == 0
18
+ assert int(SessionStatus.IN_PROGRESS) == 2
19
+
20
+
21
+ def test_session_command_response_minimal():
22
+ response = SessionCommandResponse(**{"success": True, "message": "updated"})
23
+
24
+ assert response.success is True
25
+ assert response.message == "updated"
26
+ assert response.update is None
27
+
28
+
29
+ def test_session_command_response_carries_update_subresult():
30
+ response = SessionCommandResponse(**{"success": True, "message": "ok", "update": {"status": 2}})
31
+
32
+ assert response.update == {"status": 2}
33
+
34
+
35
+ def test_analytics_event_new_populates_id_and_defaults():
36
+ event = AnalyticsEvent.new(correlation="run-1", event_type="pipeline.start")
37
+
38
+ assert event.id is not None
39
+ assert event.correlation == "run-1"
40
+ assert event.event_type == "pipeline.start"
41
+ assert event.payload == {}
42
+ assert isinstance(event.timestamp, datetime)
43
+
44
+
45
+ def test_analytics_event_serializes_timestamp_in_fixed_format():
46
+ event = AnalyticsEvent(
47
+ id="e1",
48
+ correlation="run-1",
49
+ event_type="pipeline.step",
50
+ timestamp=datetime(2026, 7, 17, 9, 30, 5, tzinfo=UTC),
51
+ )
52
+
53
+ dumped = event.model_dump()
54
+
55
+ assert dumped["timestamp"] == "2026-07-17 09:30:05"
56
+
57
+
58
+ def test_analytics_event_step_event_sets_step_fields():
59
+ event = AnalyticsEvent.step_event(
60
+ correlation="run-1",
61
+ event_type="pipeline.step",
62
+ step_name="extract",
63
+ workflow_name="dbq",
64
+ duration_ms=1200,
65
+ )
66
+
67
+ assert event.step_name == "extract"
68
+ assert event.workflow_name == "dbq"
69
+ assert event.duration_ms == 1200
70
+
71
+
72
+ def test_analytics_event_allows_null_id():
73
+ event = AnalyticsEvent(id=None, correlation="c", event_type="t")
74
+
75
+ assert event.id is None
@@ -0,0 +1,36 @@
1
+ """Offline protocol tests for AgencySessionTemplatesClient.
2
+
3
+ The dispatcher resolves a template NAME → id via this list (client-side matching
4
+ + caching + degraded handling live in the agent, not here).
5
+ """
6
+
7
+ import pytest
8
+
9
+ from agency_sdk.delegates.session_templates_client import AgencySessionTemplatesClient
10
+ from agency_sdk.test.test_session_templates_dto import TEMPLATE_JSON
11
+
12
+
13
+ @pytest.fixture
14
+ def client(fake_credentials):
15
+ return AgencySessionTemplatesClient(token_supplier=fake_credentials, base_url="http://cp.test/")
16
+
17
+
18
+ def test_list_hits_session_templates_endpoint_paged(client, stub_requests):
19
+ stub_requests.queue(json_data={"page": {"page": 0, "size": 1, "total": 1}, "items": [TEMPLATE_JSON]})
20
+
21
+ result = client.list(organisation_id=2)
22
+
23
+ call = stub_requests.calls[0]
24
+ assert call.method == "GET"
25
+ assert call.url == "http://cp.test/api/session_templates"
26
+ assert call.kwargs["params"] == {"o": "2", "p": "0", "s": "50"}
27
+ assert [t.name for t in result.items] == ["Guideline Extraction (A)"]
28
+ assert result.items[0].id == "98d227ab-4495-4730-b93a-5a7b8251f977"
29
+
30
+
31
+ def test_list_forwards_pagination(client, stub_requests):
32
+ stub_requests.queue(json_data={"page": {"page": 1, "size": 5, "total": 0}, "items": []})
33
+
34
+ client.list(organisation_id=9, page=1, size=5)
35
+
36
+ assert stub_requests.calls[0].kwargs["params"] == {"o": "9", "p": "1", "s": "5"}
@@ -0,0 +1,45 @@
1
+ """DTO tests for the session-templates delegate (name→id resolution vehicle).
2
+
3
+ JSON transcribed from the live server `GET /api/session_templates?o=` items.
4
+ """
5
+
6
+ from agency_sdk.delegates.session_templates_dto import (
7
+ SessionTemplateResponse,
8
+ SessionTemplatesPagedResult,
9
+ )
10
+
11
+ TEMPLATE_JSON = {
12
+ "id": "98d227ab-4495-4730-b93a-5a7b8251f977",
13
+ "organisation_id": 2,
14
+ "name": "Guideline Extraction (A)",
15
+ "type": "A",
16
+ "executed": 0,
17
+ "audit_data": {"created_on": "2026-07-20 20:47:04Z", "created_by": "901"},
18
+ }
19
+
20
+
21
+ def test_session_template_response_deserialises():
22
+ template = SessionTemplateResponse(**TEMPLATE_JSON)
23
+
24
+ assert template.id == "98d227ab-4495-4730-b93a-5a7b8251f977"
25
+ assert template.name == "Guideline Extraction (A)"
26
+ assert template.organisation_id == 2
27
+ assert template.type == "A"
28
+ assert template.executed == 0
29
+ assert template.audit_data == {"created_on": "2026-07-20 20:47:04Z", "created_by": "901"}
30
+
31
+
32
+ def test_session_template_optional_fields_default_none():
33
+ template = SessionTemplateResponse(id="x", organisation_id=2, name="n")
34
+
35
+ assert template.type is None
36
+ assert template.executed is None
37
+ assert template.audit_data is None
38
+
39
+
40
+ def test_session_templates_paged_result_wraps_page_and_items():
41
+ result = SessionTemplatesPagedResult(**{"page": {"page": 0, "size": 1, "total": 1}, "items": [TEMPLATE_JSON]})
42
+
43
+ assert result.page.total == 1
44
+ assert [t.id for t in result.items] == ["98d227ab-4495-4730-b93a-5a7b8251f977"]
45
+ assert result.items[0].name == "Guideline Extraction (A)"