charisma-cli 0.5.3__tar.gz → 0.5.5__tar.gz
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.
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/PKG-INFO +1 -1
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/pyproject.toml +1 -1
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/src/charisma_cli/__init__.py +1 -1
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/src/charisma_cli/models.py +3 -1
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/src/charisma_cli/read_models.py +0 -1
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/src/charisma_cli/uploader.py +48 -6
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_models.py +22 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_read_client_results.py +8 -8
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_read_client_single_result.py +2 -3
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_uploader.py +210 -3
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/.gitignore +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/README.md +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/src/charisma_cli/config.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/src/charisma_cli/launch_url.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/src/charisma_cli/main.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/src/charisma_cli/parser.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/src/charisma_cli/read_client.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/src/charisma_cli/retry.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/src/charisma_cli/subprocess_mgr.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/src/charisma_cli/watcher.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/__init__.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/conftest.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_bamboo_labels.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_cli.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_config.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_integration.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_launch_url.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_open_launch_payload.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_parser.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_read_client.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_read_client_attachments.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_read_client_integration.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_read_client_launches.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_read_client_pagination.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_retry.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_silent_mode.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_subprocess_mgr.py +0 -0
- {charisma_cli-0.5.3 → charisma_cli-0.5.5}/tests/test_watcher.py +0 -0
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
# is generated from pyproject.toml [project].version, so keeping this literal
|
|
5
5
|
# equal to pyproject guarantees `--version` reports the published version. The
|
|
6
6
|
# prepare-commit step owns the PATCH bump — do not hand-bump here.
|
|
7
|
-
__version__ = "0.5.
|
|
7
|
+
__version__ = "0.5.5"
|
|
@@ -133,7 +133,9 @@ class AttachmentRef:
|
|
|
133
133
|
return None
|
|
134
134
|
return cls(
|
|
135
135
|
source=source,
|
|
136
|
-
name
|
|
136
|
+
# An empty/blank/null Allure name must not become a blank label:
|
|
137
|
+
# fall back to the source filename.
|
|
138
|
+
name=(attachment.get("name") or "").strip() or source,
|
|
137
139
|
mime_type=attachment.get("type", "application/octet-stream"),
|
|
138
140
|
result_uuid=result_uuid,
|
|
139
141
|
)
|
|
@@ -173,7 +173,6 @@ class TestResultRecord(_CamelModel):
|
|
|
173
173
|
ended_at: datetime | None = None
|
|
174
174
|
duration_ms: int | None = None
|
|
175
175
|
retry_count: int | None = None
|
|
176
|
-
attempt_number: int | None = None
|
|
177
176
|
is_final: bool | None = None
|
|
178
177
|
history_id: str | None = None
|
|
179
178
|
effective_retention_policy: str | None = None
|
|
@@ -83,6 +83,10 @@ def _resolve_apigw_safe_bytes() -> int:
|
|
|
83
83
|
# presign-signed Content-Type and the PUT Content-Type match byte-for-byte.
|
|
84
84
|
_SPILL_CONTENT_TYPE = "text/plain; charset=utf-8"
|
|
85
85
|
|
|
86
|
+
# The backend rejects a displayName longer than this (400). Truncate the Allure
|
|
87
|
+
# label client-side so an overlong name never costs the attachment itself.
|
|
88
|
+
_MAX_DISPLAY_NAME_LEN = 255
|
|
89
|
+
|
|
86
90
|
# Sentinel expectedTests for CLI launches: the total count is unknown at open
|
|
87
91
|
# time (directory-watch streaming), so we send the backend maximum. This keeps
|
|
88
92
|
# the launch in 'receiving' across all appends; close_launch() finalizes it.
|
|
@@ -130,6 +134,10 @@ class Uploader:
|
|
|
130
134
|
# Allure's own structure: results own attachments and have a uuid;
|
|
131
135
|
# containers reference their children by uuid).
|
|
132
136
|
self._attachment_result_map: dict[str, str] = {}
|
|
137
|
+
# Map source filename → Allure attachment name (the human label such as
|
|
138
|
+
# "actual image"). Sent as ``displayName`` so listings are not the bare
|
|
139
|
+
# ``<uuid>-attachment.png`` filename. Written beside the result map.
|
|
140
|
+
self._attachment_name_map: dict[str, str] = {}
|
|
133
141
|
# Map Allure result uuid → historyId. Attachments reference their owning
|
|
134
142
|
# result by Allure uuid; the backend keys results by historyId, so the
|
|
135
143
|
# uuid must be translated to its historyId. Populated as result files are
|
|
@@ -755,6 +763,7 @@ class Uploader:
|
|
|
755
763
|
return
|
|
756
764
|
for ref in refs:
|
|
757
765
|
self._attachment_result_map[ref.source] = ref.result_uuid
|
|
766
|
+
self._attachment_name_map[ref.source] = ref.name
|
|
758
767
|
# A newly-registered mapping may unblock attachments that were dequeued
|
|
759
768
|
# before their owning result/container arrived (watch-mode ordering).
|
|
760
769
|
self._retry_pending_attachments()
|
|
@@ -861,10 +870,23 @@ class Uploader:
|
|
|
861
870
|
# would diverge from the signature). Same fallback the backend's own
|
|
862
871
|
# handle_upload_attachment uses.
|
|
863
872
|
content_type = mimetypes.guess_type(path.name)[0] or "application/octet-stream"
|
|
864
|
-
self._post_attachment(
|
|
873
|
+
self._post_attachment(
|
|
874
|
+
path.name,
|
|
875
|
+
content,
|
|
876
|
+
result_id,
|
|
877
|
+
content_type,
|
|
878
|
+
display_name=self._attachment_name_map.get(path.name, path.name)[
|
|
879
|
+
:_MAX_DISPLAY_NAME_LEN
|
|
880
|
+
],
|
|
881
|
+
)
|
|
865
882
|
|
|
866
883
|
def _post_attachment(
|
|
867
|
-
self,
|
|
884
|
+
self,
|
|
885
|
+
filename: str,
|
|
886
|
+
content: bytes,
|
|
887
|
+
result_id: str,
|
|
888
|
+
content_type: str,
|
|
889
|
+
display_name: str | None = None,
|
|
868
890
|
) -> None:
|
|
869
891
|
"""POST attachment bytes to Charisma, routing by size.
|
|
870
892
|
|
|
@@ -887,6 +909,10 @@ class Uploader:
|
|
|
887
909
|
content: Raw attachment bytes.
|
|
888
910
|
result_id: Backend-assigned ``test_results.id`` for the owning result.
|
|
889
911
|
content_type: Concrete MIME type (never None).
|
|
912
|
+
display_name: Human label (the Allure attachment name) sent as
|
|
913
|
+
``displayName`` so listings show it instead of the filename.
|
|
914
|
+
``None`` omits the field (e.g. oversized-field spills have no
|
|
915
|
+
Allure name).
|
|
890
916
|
"""
|
|
891
917
|
if self._client is None or not self._launch_id:
|
|
892
918
|
self._summary.attachments_skipped += 1
|
|
@@ -894,11 +920,13 @@ class Uploader:
|
|
|
894
920
|
return
|
|
895
921
|
|
|
896
922
|
if len(content) > self._attachment_apigw_safe_bytes:
|
|
897
|
-
self._post_attachment_via_s3(filename, content, result_id, content_type)
|
|
923
|
+
self._post_attachment_via_s3(filename, content, result_id, content_type, display_name)
|
|
898
924
|
else:
|
|
899
|
-
self._post_attachment_apigw(filename, content, result_id)
|
|
925
|
+
self._post_attachment_apigw(filename, content, result_id, display_name)
|
|
900
926
|
|
|
901
|
-
def _post_attachment_apigw(
|
|
927
|
+
def _post_attachment_apigw(
|
|
928
|
+
self, filename: str, content: bytes, result_id: str, display_name: str | None = None
|
|
929
|
+
) -> None:
|
|
902
930
|
"""POST attachment bytes via the API-Gateway multipart route, with retry.
|
|
903
931
|
|
|
904
932
|
The original (and still default, for content at or below the routing
|
|
@@ -913,9 +941,12 @@ class Uploader:
|
|
|
913
941
|
content: Raw attachment bytes.
|
|
914
942
|
result_id: Backend-assigned ``test_results.id`` for the owning result
|
|
915
943
|
(from the append-results response), sent as ``resultId``.
|
|
944
|
+
display_name: Allure attachment label, sent as ``displayName`` when set.
|
|
916
945
|
"""
|
|
917
946
|
files = {"file": (filename, content)}
|
|
918
947
|
data = {"name": filename, "resultId": result_id}
|
|
948
|
+
if display_name:
|
|
949
|
+
data["displayName"] = display_name
|
|
919
950
|
|
|
920
951
|
for attempt in range(MAX_RETRIES + 1):
|
|
921
952
|
try:
|
|
@@ -1006,7 +1037,12 @@ class Uploader:
|
|
|
1006
1037
|
return None
|
|
1007
1038
|
|
|
1008
1039
|
def _post_attachment_via_s3(
|
|
1009
|
-
self,
|
|
1040
|
+
self,
|
|
1041
|
+
filename: str,
|
|
1042
|
+
content: bytes,
|
|
1043
|
+
result_id: str,
|
|
1044
|
+
content_type: str,
|
|
1045
|
+
display_name: str | None = None,
|
|
1010
1046
|
) -> None:
|
|
1011
1047
|
"""Upload a large attachment via presign -> direct S3 PUT -> complete.
|
|
1012
1048
|
|
|
@@ -1036,6 +1072,8 @@ class Uploader:
|
|
|
1036
1072
|
result_id: Backend-assigned ``test_results.id`` for the owning result.
|
|
1037
1073
|
content_type: Concrete MIME type, signed into the presigned URL and
|
|
1038
1074
|
echoed verbatim on the PUT and complete steps.
|
|
1075
|
+
display_name: Allure attachment label, sent as ``displayName`` on the
|
|
1076
|
+
presign and complete requests when set.
|
|
1039
1077
|
"""
|
|
1040
1078
|
presign_body = {
|
|
1041
1079
|
"resultId": result_id,
|
|
@@ -1043,6 +1081,8 @@ class Uploader:
|
|
|
1043
1081
|
"contentType": content_type,
|
|
1044
1082
|
"size": len(content),
|
|
1045
1083
|
}
|
|
1084
|
+
if display_name:
|
|
1085
|
+
presign_body["displayName"] = display_name
|
|
1046
1086
|
presign_resp = self._request_with_retry(
|
|
1047
1087
|
"presign",
|
|
1048
1088
|
filename,
|
|
@@ -1102,6 +1142,8 @@ class Uploader:
|
|
|
1102
1142
|
"contentType": content_type,
|
|
1103
1143
|
"s3Key": s3_key,
|
|
1104
1144
|
}
|
|
1145
|
+
if display_name:
|
|
1146
|
+
complete_body["displayName"] = display_name
|
|
1105
1147
|
complete_resp = self._request_with_retry(
|
|
1106
1148
|
"complete",
|
|
1107
1149
|
filename,
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
5
7
|
from charisma_cli.models import (
|
|
6
8
|
AttachmentRef,
|
|
7
9
|
CharismaResult,
|
|
@@ -148,6 +150,26 @@ class TestAttachmentRef:
|
|
|
148
150
|
assert ref.mime_type == "image/png"
|
|
149
151
|
assert ref.result_uuid == "result-uuid-456"
|
|
150
152
|
|
|
153
|
+
def test_from_allure_keeps_allure_name(self) -> None:
|
|
154
|
+
"""A set Allure name is the human label (e.g. 'actual image')."""
|
|
155
|
+
ref = AttachmentRef.from_allure(
|
|
156
|
+
{"source": "9f2-attachment.png", "name": "actual image", "type": "image/png"},
|
|
157
|
+
"res-1",
|
|
158
|
+
)
|
|
159
|
+
assert ref is not None
|
|
160
|
+
assert ref.name == "actual image"
|
|
161
|
+
assert ref.source == "9f2-attachment.png"
|
|
162
|
+
|
|
163
|
+
@pytest.mark.parametrize("attachment_name", ["", " ", None])
|
|
164
|
+
def test_from_allure_empty_name_falls_back_to_source(self, attachment_name) -> None:
|
|
165
|
+
"""An empty/blank/null Allure name must not yield a blank label."""
|
|
166
|
+
attachment = {"source": "9f2-attachment.png", "type": "image/png"}
|
|
167
|
+
if attachment_name is not None:
|
|
168
|
+
attachment["name"] = attachment_name
|
|
169
|
+
ref = AttachmentRef.from_allure(attachment, "res-1")
|
|
170
|
+
assert ref is not None
|
|
171
|
+
assert ref.name == "9f2-attachment.png"
|
|
172
|
+
|
|
151
173
|
def test_different_mime_types(self) -> None:
|
|
152
174
|
for mime in ["text/plain", "application/json", "video/mp4", "image/jpeg"]:
|
|
153
175
|
ref = AttachmentRef(source="file", name="f", mime_type=mime, result_uuid="r")
|
|
@@ -114,7 +114,6 @@ def _test_result_row(result_id: str, name: str, status: str, attempt: int, is_fi
|
|
|
114
114
|
"endedAt": "2026-06-20T09:14:12.640000+00:00",
|
|
115
115
|
"durationMs": 2540,
|
|
116
116
|
"retryCount": 1 if attempt > 1 else 0,
|
|
117
|
-
"attemptNumber": attempt,
|
|
118
117
|
"isFinal": is_final,
|
|
119
118
|
"historyId": "hist-7d3e9a1b",
|
|
120
119
|
"effectiveRetentionPolicy": "default-90d",
|
|
@@ -180,15 +179,15 @@ class TestListLaunchResultsEnvelope:
|
|
|
180
179
|
|
|
181
180
|
@respx.mock
|
|
182
181
|
def test_items_are_flat_per_attempt_rows(self) -> None:
|
|
183
|
-
"""Items are flat per-attempt rows: the same result id appears once per
|
|
182
|
+
"""Items are flat per-attempt rows: the same result id appears once per execution."""
|
|
184
183
|
respx.get(RESULTS_URL).mock(return_value=httpx.Response(200, json=RESULTS_ENVELOPE))
|
|
185
184
|
client = _make_client()
|
|
186
185
|
items = client.list_launch_results(LAUNCH_ID).items
|
|
187
|
-
attempts = [(item.name, item.
|
|
186
|
+
attempts = [(item.name, item.is_final) for item in items]
|
|
188
187
|
assert attempts == [
|
|
189
|
-
("test_pay_with_card",
|
|
190
|
-
("test_pay_with_card",
|
|
191
|
-
("test_apply_coupon",
|
|
188
|
+
("test_pay_with_card", False),
|
|
189
|
+
("test_pay_with_card", True),
|
|
190
|
+
("test_apply_coupon", True),
|
|
192
191
|
]
|
|
193
192
|
|
|
194
193
|
@respx.mock
|
|
@@ -199,7 +198,7 @@ class TestListLaunchResultsEnvelope:
|
|
|
199
198
|
first = client.list_launch_results(LAUNCH_ID).items[0]
|
|
200
199
|
snake_attrs = (
|
|
201
200
|
"launch_id", "launch_created_at", "project_id", "full_name", "error_message",
|
|
202
|
-
"stack_trace", "error_phase", "duration_ms", "retry_count",
|
|
201
|
+
"stack_trace", "error_phase", "duration_ms", "retry_count",
|
|
203
202
|
"is_final", "history_id", "effective_retention_policy", "retention_policy_name",
|
|
204
203
|
"expires_at", "feature_name", "feature_description", "base_test_name",
|
|
205
204
|
"is_parameterized", "workflow_status", "component_id", "metadata_tags",
|
|
@@ -210,7 +209,7 @@ class TestListLaunchResultsEnvelope:
|
|
|
210
209
|
wire = first.model_dump(by_alias=True)
|
|
211
210
|
for key in (
|
|
212
211
|
"launchId", "launchCreatedAt", "projectId", "fullName", "errorMessage",
|
|
213
|
-
"stackTrace", "errorPhase", "durationMs", "retryCount",
|
|
212
|
+
"stackTrace", "errorPhase", "durationMs", "retryCount",
|
|
214
213
|
"isFinal", "historyId", "effectiveRetentionPolicy", "retentionPolicyName",
|
|
215
214
|
"expiresAt", "featureName", "featureDescription", "baseTestName",
|
|
216
215
|
"isParameterized", "workflowStatus", "componentId", "metadataTags",
|
|
@@ -219,6 +218,7 @@ class TestListLaunchResultsEnvelope:
|
|
|
219
218
|
assert key in wire
|
|
220
219
|
|
|
221
220
|
|
|
221
|
+
|
|
222
222
|
class TestListLaunchResultsTagsPopulated:
|
|
223
223
|
"""results-list path: tags / metadataTags / zephyrIds are POPULATED (contrast get_result, where they are [])."""
|
|
224
224
|
|
|
@@ -133,7 +133,6 @@ RESULT_RECORD = {
|
|
|
133
133
|
"endedAt": "2026-06-20T09:14:12.640000+00:00",
|
|
134
134
|
"durationMs": 2540,
|
|
135
135
|
"retryCount": 0,
|
|
136
|
-
"attemptNumber": 1,
|
|
137
136
|
"isFinal": True,
|
|
138
137
|
"historyId": "hist-7d3e9a1b",
|
|
139
138
|
"effectiveRetentionPolicy": "default-90d",
|
|
@@ -274,14 +273,14 @@ class TestGetResultVerbatim:
|
|
|
274
273
|
client = _make_client()
|
|
275
274
|
result = client.get_result(RESULT_ID)
|
|
276
275
|
for attr in (
|
|
277
|
-
"launch_id", "project_id", "full_name", "duration_ms",
|
|
276
|
+
"launch_id", "project_id", "full_name", "duration_ms",
|
|
278
277
|
"is_final", "history_id", "base_test_name", "workflow_status", "component_id",
|
|
279
278
|
"created_at",
|
|
280
279
|
):
|
|
281
280
|
assert hasattr(result, attr)
|
|
282
281
|
wire = result.model_dump(by_alias=True)
|
|
283
282
|
for key in (
|
|
284
|
-
"launchId", "projectId", "fullName", "durationMs", "
|
|
283
|
+
"launchId", "projectId", "fullName", "durationMs", "isFinal",
|
|
285
284
|
"historyId", "baseTestName", "workflowStatus", "componentId", "createdAt",
|
|
286
285
|
):
|
|
287
286
|
assert key in wire
|
|
@@ -570,9 +570,8 @@ class TestAttachmentResultIdContract:
|
|
|
570
570
|
"""The attachment `resultId` must be the backend id returned by /results.
|
|
571
571
|
|
|
572
572
|
Regression for the `attachments_sent=0, attachments_skipped=N` production bug.
|
|
573
|
-
Under retries (ADR-031) the backend
|
|
574
|
-
|
|
575
|
-
and unknown to the client. The client therefore reads the backend-assigned
|
|
573
|
+
Under retries (ADR-031) the backend assigns test_results.id server-side
|
|
574
|
+
(uuid4), unknown to the client. The client therefore reads the backend-assigned
|
|
576
575
|
resultId from the append-results response (`results: [{testId, resultId}]`)
|
|
577
576
|
and sends THAT exact id on the attachment. Sending the raw Allure `uuid`, the
|
|
578
577
|
historyId, or a client-computed uuid5 never matches and every attachment is
|
|
@@ -2060,3 +2059,211 @@ class TestUploaderStopTimeoutAndWarning:
|
|
|
2060
2059
|
"Uploader.stop must accept a configurable 'timeout' (the 10s join "
|
|
2061
2060
|
"was hardcoded, cutting off large/slow uploads)"
|
|
2062
2061
|
)
|
|
2062
|
+
|
|
2063
|
+
|
|
2064
|
+
class TestAttachmentDisplayName:
|
|
2065
|
+
"""The Allure attachment name reaches the backend as ``displayName``.
|
|
2066
|
+
|
|
2067
|
+
Bug: attachments showed as ``<uuid>-attachment.png`` because the CLI sent the
|
|
2068
|
+
on-disk filename as the only ``name`` and never the Allure label ("actual
|
|
2069
|
+
image" / "expected image"). ``name`` must stay the real filename (the backend
|
|
2070
|
+
derives extension, MIME and S3 key from it); the human label travels in
|
|
2071
|
+
``displayName`` on every transport (multipart, presign, complete). An empty
|
|
2072
|
+
Allure name falls back to the filename so the label is never blank.
|
|
2073
|
+
"""
|
|
2074
|
+
|
|
2075
|
+
LAUNCH = "launch-1"
|
|
2076
|
+
RESULTS_URL = f"https://charisma.test/api/v1/launches/{LAUNCH}/results"
|
|
2077
|
+
APIGW_URL = f"https://charisma.test/api/v1/launches/{LAUNCH}/attachments"
|
|
2078
|
+
PRESIGN_URL = f"https://charisma.test/api/v1/launches/{LAUNCH}/attachments/presign"
|
|
2079
|
+
COMPLETE_URL = f"https://charisma.test/api/v1/launches/{LAUNCH}/attachments/complete"
|
|
2080
|
+
S3_PUT_URL = "https://s3.amazonaws.com/charisma-bucket/attachments/p/l/r/obj.png?sig=abc"
|
|
2081
|
+
SOURCE = "9f2c1a7e-attachment.png"
|
|
2082
|
+
|
|
2083
|
+
@staticmethod
|
|
2084
|
+
def _multipart_field(route, field: str) -> str | None:
|
|
2085
|
+
"""Return a multipart form field value from the first recorded request."""
|
|
2086
|
+
body = route.calls[0].request.content.decode("utf-8", errors="replace")
|
|
2087
|
+
marker = f'name="{field}"'
|
|
2088
|
+
idx = body.find(marker)
|
|
2089
|
+
if idx == -1:
|
|
2090
|
+
return None
|
|
2091
|
+
value = body[idx + len(marker):].split("\r\n\r\n", 1)[1]
|
|
2092
|
+
return value.split("\r\n", 1)[0]
|
|
2093
|
+
|
|
2094
|
+
@staticmethod
|
|
2095
|
+
def _json_body(route) -> dict:
|
|
2096
|
+
import json
|
|
2097
|
+
|
|
2098
|
+
return json.loads(route.calls[0].request.content)
|
|
2099
|
+
|
|
2100
|
+
def _run(self, tmp_path: Path, result: dict, files: dict[str, bytes], monkeypatch,
|
|
2101
|
+
threshold: int = 1024 * 1024) -> Uploader:
|
|
2102
|
+
"""Upload one result plus its attachment files through a real Uploader."""
|
|
2103
|
+
import json
|
|
2104
|
+
|
|
2105
|
+
monkeypatch.setenv("CHARISMA_ATTACHMENT_APIGW_SAFE_BYTES", str(threshold))
|
|
2106
|
+
monkeypatch.setattr("charisma_cli.uploader.exponential_backoff", lambda attempt: 0.0)
|
|
2107
|
+
queue: PriorityQueue = PriorityQueue()
|
|
2108
|
+
uploader = Uploader(_make_config(), queue)
|
|
2109
|
+
uploader._launch_id = self.LAUNCH
|
|
2110
|
+
|
|
2111
|
+
result_file = tmp_path / "r1-result.json"
|
|
2112
|
+
result_file.write_text(json.dumps(result), encoding="utf-8")
|
|
2113
|
+
queue.put(FileEvent(path=result_file, category=FileCategory.RESULT))
|
|
2114
|
+
for fname, content in files.items():
|
|
2115
|
+
(tmp_path / fname).write_bytes(content)
|
|
2116
|
+
queue.put(FileEvent(path=tmp_path / fname, category=FileCategory.ATTACHMENT))
|
|
2117
|
+
|
|
2118
|
+
uploader.start()
|
|
2119
|
+
uploader.drain(timeout=5.0)
|
|
2120
|
+
uploader.stop()
|
|
2121
|
+
return uploader
|
|
2122
|
+
|
|
2123
|
+
@staticmethod
|
|
2124
|
+
def _result(attachments: list[dict], steps: list[dict] | None = None) -> dict:
|
|
2125
|
+
result = {
|
|
2126
|
+
"uuid": "r1", "historyId": "hist-r1", "fullName": "atd.png_check",
|
|
2127
|
+
"status": "failed", "start": 1000, "stop": 2000, "attachments": attachments,
|
|
2128
|
+
}
|
|
2129
|
+
if steps is not None:
|
|
2130
|
+
result["steps"] = steps
|
|
2131
|
+
return result
|
|
2132
|
+
|
|
2133
|
+
def _mock_results(self) -> None:
|
|
2134
|
+
respx.post(self.RESULTS_URL).mock(
|
|
2135
|
+
return_value=httpx.Response(200, json={
|
|
2136
|
+
"accepted": 1, "results": [{"testId": "hist-r1", "resultId": "rid-r1"}],
|
|
2137
|
+
})
|
|
2138
|
+
)
|
|
2139
|
+
|
|
2140
|
+
@respx.mock
|
|
2141
|
+
def test_multipart_sends_allure_name_as_display_name_and_filename_as_name(
|
|
2142
|
+
self, tmp_path: Path, monkeypatch
|
|
2143
|
+
) -> None:
|
|
2144
|
+
"""API-GW multipart: ``displayName`` is the Allure label, ``name`` the filename."""
|
|
2145
|
+
self._mock_results()
|
|
2146
|
+
route = respx.post(self.APIGW_URL).mock(return_value=httpx.Response(201, json={"id": "a"}))
|
|
2147
|
+
|
|
2148
|
+
uploader = self._run(
|
|
2149
|
+
tmp_path,
|
|
2150
|
+
self._result([{"source": self.SOURCE, "name": "actual image", "type": "image/png"}]),
|
|
2151
|
+
{self.SOURCE: b"\x89PNG fake"},
|
|
2152
|
+
monkeypatch,
|
|
2153
|
+
)
|
|
2154
|
+
|
|
2155
|
+
assert uploader.summary.attachments_sent == 1
|
|
2156
|
+
assert self._multipart_field(route, "displayName") == "actual image"
|
|
2157
|
+
assert self._multipart_field(route, "name") == self.SOURCE
|
|
2158
|
+
|
|
2159
|
+
@respx.mock
|
|
2160
|
+
def test_two_attachments_keep_their_own_labels(self, tmp_path: Path, monkeypatch) -> None:
|
|
2161
|
+
"""The ATD pattern: 'actual image' and 'expected image' stay distinguishable."""
|
|
2162
|
+
self._mock_results()
|
|
2163
|
+
route = respx.post(self.APIGW_URL).mock(return_value=httpx.Response(201, json={"id": "a"}))
|
|
2164
|
+
expected_src = "77ab-attachment.png"
|
|
2165
|
+
|
|
2166
|
+
self._run(
|
|
2167
|
+
tmp_path,
|
|
2168
|
+
self._result([
|
|
2169
|
+
{"source": self.SOURCE, "name": "actual image", "type": "image/png"},
|
|
2170
|
+
{"source": expected_src, "name": "expected image", "type": "image/png"},
|
|
2171
|
+
]),
|
|
2172
|
+
{self.SOURCE: b"actual-bytes", expected_src: b"expected-bytes"},
|
|
2173
|
+
monkeypatch,
|
|
2174
|
+
)
|
|
2175
|
+
|
|
2176
|
+
labels_by_filename = {}
|
|
2177
|
+
for call in route.calls:
|
|
2178
|
+
body = call.request.content.decode("utf-8", errors="replace")
|
|
2179
|
+
def field(f: str) -> str:
|
|
2180
|
+
value = body[body.find(f'name="{f}"') + len(f'name="{f}"'):]
|
|
2181
|
+
return value.split("\r\n\r\n", 1)[1].split("\r\n", 1)[0]
|
|
2182
|
+
labels_by_filename[field("name")] = field("displayName")
|
|
2183
|
+
assert labels_by_filename == {
|
|
2184
|
+
self.SOURCE: "actual image",
|
|
2185
|
+
expected_src: "expected image",
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2188
|
+
@respx.mock
|
|
2189
|
+
def test_empty_allure_name_falls_back_to_filename(self, tmp_path: Path, monkeypatch) -> None:
|
|
2190
|
+
"""An empty Allure name must not produce a blank displayName."""
|
|
2191
|
+
self._mock_results()
|
|
2192
|
+
route = respx.post(self.APIGW_URL).mock(return_value=httpx.Response(201, json={"id": "a"}))
|
|
2193
|
+
|
|
2194
|
+
self._run(
|
|
2195
|
+
tmp_path,
|
|
2196
|
+
self._result([{"source": self.SOURCE, "name": "", "type": "image/png"}]),
|
|
2197
|
+
{self.SOURCE: b"\x89PNG fake"},
|
|
2198
|
+
monkeypatch,
|
|
2199
|
+
)
|
|
2200
|
+
|
|
2201
|
+
assert self._multipart_field(route, "displayName") == self.SOURCE
|
|
2202
|
+
|
|
2203
|
+
@respx.mock
|
|
2204
|
+
def test_overlong_allure_name_is_truncated_not_dropped(
|
|
2205
|
+
self, tmp_path: Path, monkeypatch
|
|
2206
|
+
) -> None:
|
|
2207
|
+
"""The backend caps displayName at 255; a longer label must not cost the attachment."""
|
|
2208
|
+
self._mock_results()
|
|
2209
|
+
route = respx.post(self.APIGW_URL).mock(return_value=httpx.Response(201, json={"id": "a"}))
|
|
2210
|
+
|
|
2211
|
+
uploader = self._run(
|
|
2212
|
+
tmp_path,
|
|
2213
|
+
self._result([{"source": self.SOURCE, "name": "L" * 400, "type": "image/png"}]),
|
|
2214
|
+
{self.SOURCE: b"\x89PNG fake"},
|
|
2215
|
+
monkeypatch,
|
|
2216
|
+
)
|
|
2217
|
+
|
|
2218
|
+
assert uploader.summary.attachments_sent == 1
|
|
2219
|
+
assert self._multipart_field(route, "displayName") == "L" * 255
|
|
2220
|
+
|
|
2221
|
+
@respx.mock
|
|
2222
|
+
def test_step_nested_attachment_label_is_sent(self, tmp_path: Path, monkeypatch) -> None:
|
|
2223
|
+
"""Allure stores most attachments inside steps; their label must survive too."""
|
|
2224
|
+
self._mock_results()
|
|
2225
|
+
route = respx.post(self.APIGW_URL).mock(return_value=httpx.Response(201, json={"id": "a"}))
|
|
2226
|
+
|
|
2227
|
+
self._run(
|
|
2228
|
+
tmp_path,
|
|
2229
|
+
self._result([], steps=[{
|
|
2230
|
+
"name": "compare images",
|
|
2231
|
+
"attachments": [{"source": self.SOURCE, "name": "expected image",
|
|
2232
|
+
"type": "image/png"}],
|
|
2233
|
+
}]),
|
|
2234
|
+
{self.SOURCE: b"\x89PNG fake"},
|
|
2235
|
+
monkeypatch,
|
|
2236
|
+
)
|
|
2237
|
+
|
|
2238
|
+
assert self._multipart_field(route, "displayName") == "expected image"
|
|
2239
|
+
|
|
2240
|
+
@respx.mock
|
|
2241
|
+
def test_presigned_path_sends_display_name_in_presign_and_complete(
|
|
2242
|
+
self, tmp_path: Path, monkeypatch
|
|
2243
|
+
) -> None:
|
|
2244
|
+
"""Large attachments (presign -> PUT -> complete) carry the label on both JSON calls."""
|
|
2245
|
+
self._mock_results()
|
|
2246
|
+
presign = respx.post(self.PRESIGN_URL).mock(
|
|
2247
|
+
return_value=httpx.Response(201, json={
|
|
2248
|
+
"uploadUrl": self.S3_PUT_URL, "attachmentId": "att-1",
|
|
2249
|
+
"s3Key": "attachments/p/l/r/obj.png",
|
|
2250
|
+
})
|
|
2251
|
+
)
|
|
2252
|
+
respx.put(self.S3_PUT_URL).mock(return_value=httpx.Response(200))
|
|
2253
|
+
complete = respx.post(self.COMPLETE_URL).mock(
|
|
2254
|
+
return_value=httpx.Response(201, json={"attachmentId": "att-1"})
|
|
2255
|
+
)
|
|
2256
|
+
|
|
2257
|
+
uploader = self._run(
|
|
2258
|
+
tmp_path,
|
|
2259
|
+
self._result([{"source": self.SOURCE, "name": "actual image", "type": "image/png"}]),
|
|
2260
|
+
{self.SOURCE: b"y" * 4096},
|
|
2261
|
+
monkeypatch,
|
|
2262
|
+
threshold=1024,
|
|
2263
|
+
)
|
|
2264
|
+
|
|
2265
|
+
assert uploader.summary.attachments_sent == 1
|
|
2266
|
+
for route in (presign, complete):
|
|
2267
|
+
body = self._json_body(route)
|
|
2268
|
+
assert body["displayName"] == "actual image"
|
|
2269
|
+
assert body["name"] == self.SOURCE
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|