test(pipeline): cover variant metadata and correct lab endpoint

This commit is contained in:
2026-11-15 22:33:09 +03:00
parent d3e156e8a1
commit bb4e8a2254
5 changed files with 90 additions and 4 deletions
+1
View File
@@ -0,0 +1 @@
{"result":"INVALID_ENVIRONMENT","cause":"Inherited student fixture default pointed to stopped lab4 port8084, not lab5 port8085; all connections refused; no API correctness conclusion.","failed":40,"errors":72,"seconds":8.77}
+10 -3
View File
@@ -3,6 +3,7 @@
import json import json
import os import os
import random import random
import re
import time import time
from datetime import UTC, datetime from datetime import UTC, datetime
from uuid import UUID from uuid import UUID
@@ -68,14 +69,20 @@ def validate_job(data):
): ):
raise ValueError("Invalid job type") raise ValueError("Invalid job type")
for k in ["job_id", "attachment_id"]: for k in ["job_id", "attachment_id"]:
if not isinstance(data[k], str):
raise ValueError("Invalid job UUID")
UUID(data[k]) UUID(data[k])
for k in ["pipeline_version", "attempt"]: for k in ["pipeline_version", "attempt"]:
if type(data[k]) is not int or data[k] < 1: if type(data[k]) is not int or data[k] < 1:
raise ValueError("Invalid job number") raise ValueError("Invalid job number")
datetime.fromisoformat(data["created_at"].replace("Z", "+00:00")) timestamp = data["created_at"]
if not isinstance(timestamp, str) or not re.fullmatch(
r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})",
timestamp,
):
raise ValueError("Invalid job timestamp")
datetime.fromisoformat(timestamp.replace("Z", "+00:00"))
if "traceparent" in data: if "traceparent" in data:
import re
if not isinstance(data["traceparent"], str) or not re.fullmatch( if not isinstance(data["traceparent"], str) or not re.fullmatch(
r"00-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}", data["traceparent"] r"00-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}", data["traceparent"]
): ):
+13
View File
@@ -69,6 +69,19 @@ def reconcile(db, store, *, apply=False, grace=None):
(reservation["id"],), (reservation["id"],),
) )
store.delete(key=obj.object_name) store.delete(key=obj.object_name)
for job in jobs:
if (
job["state"] == "failed"
and job["source_key"] == obj.object_name
):
conn.execute(
"UPDATE jobs SET error_code='source_expired' WHERE id=%s",
(job["id"],),
)
conn.execute(
"UPDATE attachments SET error_code='source_expired' WHERE id=%s AND pipeline_version=%s AND state='failed'",
(job["attachment_id"], job["pipeline_version"]),
)
actions.append(action) actions.append(action)
return {"apply": apply, "retention_seconds": grace, "actions": actions} return {"apply": apply, "retention_seconds": grace, "actions": actions}
+1 -1
View File
@@ -10,7 +10,7 @@ from jsonschema import Draft202012Validator, FormatChecker
CONTRACT = json.loads( CONTRACT = json.loads(
(Path(__file__).parents[1] / "contracts/openapi.json").read_text() (Path(__file__).parents[1] / "contracts/openapi.json").read_text()
) )
BASE_URL = os.environ.get("BASE_URL", "http://127.0.0.1:8084") BASE_URL = os.environ.get("BASE_URL", "http://127.0.0.1:8085")
PASSWORD = "Synthetic-Password-🌍-123" PASSWORD = "Synthetic-Password-🌍-123"
TOKENS = {} TOKENS = {}
+65
View File
@@ -210,3 +210,68 @@ def test_chunked_body_limit_without_content_length(client, actors, chat):
assert r.status_code == 413 assert r.status_code == 413
assert r.json()["error"]["code"] == "payload_too_large" assert r.json()["error"]["code"] == "payload_too_large"
assert r.json()["error"]["request_id"] == r.headers["x-request-id"] assert r.json()["error"]["request_id"] == r.headers["x-request-id"]
@pytest.mark.parametrize("size", [(1, 17), (320, 200), (1600, 900)])
def test_variant_geometry_and_alpha(client, actors, chat, size):
stream = io.BytesIO()
Image.new("RGBA", size, (0, 0, 0, 0)).save(stream, format="PNG")
a = check(
upload(client, actors[0], chat, data=stream.getvalue()),
202,
"Attachment",
)
a = wait_ready(client, actors[0], a)
for v in a["variants"]:
r = client.get(
f"/api/v1/attachments/{a['id']}/content",
headers=headers(actors[1]),
params={"variant": v["name"]},
)
assert len(r.content) == v["size_bytes"]
assert hashlib.sha256(r.content).hexdigest() == v["sha256"]
with Image.open(io.BytesIO(r.content)) as image:
assert image.size == (v["width"], v["height"])
assert not image.getexif()
assert min(image.convert("RGB").getpixel((0, 0))) >= 250
if v["name"] == "crop":
assert image.size == (128, 128)
else:
bound = 256 if v["name"] == "thumbnail" else 1280
assert max(image.size) <= bound
assert image.width <= size[0] and image.height <= size[1]
def test_exif_orientation_applied_but_original_preserved(client, actors, chat):
stream = io.BytesIO()
exif = Image.Exif()
exif[274] = 6
exif[270] = "Synthetic metadata must be removed"
Image.new("RGB", (320, 200), "red").save(stream, format="JPEG", exif=exif)
raw = stream.getvalue()
a = check(
upload(
client,
actors[0],
chat,
data=raw,
mime="image/jpeg",
filename="exif.jpg",
),
202,
"Attachment",
)
a = wait_ready(client, actors[0], a)
r = client.get(
f"/api/v1/attachments/{a['id']}/content", headers=headers(actors[1])
)
assert r.content == raw
v = next(v for v in a["variants"] if v["name"] == "thumbnail")
assert (v["width"], v["height"]) == (160, 256)
r = client.get(
f"/api/v1/attachments/{a['id']}/content",
headers=headers(actors[1]),
params={"variant": "thumbnail"},
)
with Image.open(io.BytesIO(r.content)) as image:
assert image.size == (160, 256) and not image.getexif()