forked from mtusi2026/mtusi2026lab5
Render crop and optimized variants next to the thumbnail
The worker decodes the original once (JPEG draft down to the optimized box, EXIF orientation applied in place, alpha composed on white) and encodes three variants: the 256 px thumbnail, a centred 128x128 JPEG crop that may upscale and a WebP fitted into 1280x1280 without upscaling, quality 80, method 4. No EXIF, ICC or XMP is written. The byte limit is checked before decoding. ready is set by the transaction that stores all three rows, so a partial set is never published. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
045d631c12
commit
431b82fd43
@@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
import json
|
||||
import re
|
||||
from typing import Any
|
||||
from uuid import uuid4
|
||||
|
||||
@@ -74,8 +75,13 @@ async def test_job_is_processed_once_and_staging_is_cleaned(client: AsyncClient)
|
||||
assert (done["status"], done["job_status"], done["published_version"]) == ("ready", "done", 1)
|
||||
assert done["original_key"] == f"originals/{attachment_id}"
|
||||
assert done["staging_key"] == f"staging/{attachment_id}"
|
||||
(thumbnail,) = await variants(attachment_id)
|
||||
assert thumbnail["object_key"].startswith(f"variants/{attachment_id}/1/thumbnail-")
|
||||
pattern = rf"variants/{attachment_id}/1/(crop|optimized|thumbnail)-[0-9a-f]{{16}}\.(jpg|webp)"
|
||||
found = [re.fullmatch(pattern, row["object_key"]) for row in await variants(attachment_id)]
|
||||
assert [match.groups() for match in found if match] == [
|
||||
("crop", "jpg"),
|
||||
("optimized", "webp"),
|
||||
("thumbnail", "jpg"),
|
||||
]
|
||||
assert await pipeline.clean() >= 1
|
||||
assert (await state(attachment_id))["staging_key"] is None
|
||||
objects = (await storage(client)).objects
|
||||
@@ -127,10 +133,29 @@ async def test_two_copies_in_flight_give_one_result(client: AsyncClient) -> None
|
||||
job = await job_of(attachment_id)
|
||||
outcomes = await asyncio.gather(pipeline.process(job), pipeline.process(job))
|
||||
assert sorted(outcomes) == sorted([Outcome.DONE, Outcome.DUPLICATE])
|
||||
assert len(await variants(attachment_id)) == 1
|
||||
assert len(await variants(attachment_id)) == 3
|
||||
assert (await state(attachment_id))["claims"] == 1
|
||||
|
||||
|
||||
async def test_partial_variant_set_is_never_published(client: AsyncClient) -> None:
|
||||
_, _, attachment_id = await accepted(client)
|
||||
pipeline = await pipeline_of(client)
|
||||
await pipeline.publish()
|
||||
store = await storage(client)
|
||||
|
||||
async def refuse(key: str) -> None:
|
||||
if "/optimized-" in key:
|
||||
raise Unavailable("S3 недоступно")
|
||||
|
||||
store.after_put = refuse
|
||||
try:
|
||||
assert await pipeline.process(await job_of(attachment_id)) is Outcome.RESCHEDULED
|
||||
finally:
|
||||
store.after_put = None
|
||||
assert (await state(attachment_id))["status"] == "queued"
|
||||
assert await variants(attachment_id) == []
|
||||
|
||||
|
||||
async def test_transient_error_reschedules_with_the_same_job(client: AsyncClient) -> None:
|
||||
_, _, attachment_id = await accepted(client)
|
||||
pipeline = await pipeline_of(client)
|
||||
|
||||
Reference in New Issue
Block a user