ЛР5: устойчивый versioned pipeline изображений, outbox и доказательства отказов
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from messenger.worker import validate_delivery
|
||||
|
||||
VALID = {
|
||||
"schema_version": 1,
|
||||
"job_id": "11111111-1111-4111-8111-111111111111",
|
||||
"type": "attachment.process.v1",
|
||||
"attachment_id": "22222222-2222-4222-8222-222222222222",
|
||||
"pipeline_version": 1,
|
||||
"attempt": 1,
|
||||
"created_at": "2026-11-06T00:00:00Z",
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"key,value",
|
||||
[
|
||||
("job_id", 123),
|
||||
("job_id", []),
|
||||
("attachment_id", {}),
|
||||
("schema_version", True),
|
||||
("pipeline_version", True),
|
||||
("attempt", 0),
|
||||
("created_at", 123),
|
||||
("created_at", "2026-11-06"),
|
||||
("created_at", "2026-11-06T12Z"),
|
||||
("created_at", "2026-99-99T00:00:00Z"),
|
||||
("traceparent", 123),
|
||||
("tracestate", []),
|
||||
],
|
||||
)
|
||||
def test_invalid_envelopes_are_bounded_validation_errors(key, value):
|
||||
with pytest.raises(ValueError):
|
||||
validate_delivery(json.dumps({**VALID, key: value}))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("body", [b"\xff", "null", "[]", "{}", "not json"])
|
||||
def test_invalid_json(body):
|
||||
with pytest.raises(ValueError):
|
||||
validate_delivery(body)
|
||||
|
||||
|
||||
def test_valid_trace_context():
|
||||
body = {
|
||||
**VALID,
|
||||
"traceparent": "00-" + "a" * 32 + "-" + "b" * 16 + "-01",
|
||||
"tracestate": "test=value",
|
||||
}
|
||||
assert validate_delivery(json.dumps(body)) == body
|
||||
Reference in New Issue
Block a user