fix: 96 DPI is accepted as the Site shows it; big carts upload 4 at a time (Sentry 12/11)

The server compared the raw lowest resolution (95,6) with 96 but printed
it rounded, refusing '96 DPI abaixo do mínimo de 96'; it now decides on the
same rounded value the Site shows. A big cart started every upload at once
and hit the limit of 10 pending uploads (429): the limit is 30, that
refusal carries Retry-After so the Site retries by itself, and the Site
runs at most 4 uploads at a time.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-12 09:38:51 -03:00
parent d3918e83dc
commit 31776ca353
8 changed files with 76 additions and 12 deletions

View File

@@ -4,8 +4,12 @@ takes up to 200 files per item (Sentry DTF-WEB-1).
Run against the local stack: python -m tests.upload_limits_test
"""
import json
import os
import secrets
from pathlib import Path
from urllib.error import HTTPError
from urllib.request import Request
from uuid import UUID, uuid4
from fastapi import HTTPException
@@ -13,7 +17,7 @@ from fastapi import HTTPException
from app.api.uploads import UPLOAD_START_IP_LIMIT, UPLOAD_START_LIMIT
from app.core import db
from app.core.auth import rate_limit
from tests.smoke_test import Client, upload_bytes
from tests.smoke_test import BASE, Client, upload_bytes, with_host
PNG = (Path(__file__).resolve().parent / 'fixtures' / 'final-300.png').read_bytes()
TOO_MANY = 'Este item tem mais de 200 arquivos. Divida em dois itens.'
@@ -59,6 +63,25 @@ def run():
else:
raise AssertionError('the per-source upload bucket accepted above its limit')
# DTF-WEB-3: a burst above MAX_PENDING_UPLOADS (now 30). The 31st start
# answers 429 with Retry-After 15, so the Site waits and retries alone.
assert int(os.environ.get('MAX_PENDING_UPLOADS', '30')) == 30
pending = []
for index in range(30):
pending.append(client.call('/uploads', {'name': f'PENDING-{index}.png', 'size': 1})['id'])
burst = Request(BASE + '/api/uploads',
data=json.dumps({'name': 'PENDING-31.png', 'size': 1}).encode(),
headers=with_host({'Content-Type': 'application/json'}), method='POST')
try:
with client.opener.open(burst, timeout=30) as response:
raise AssertionError('the pending-upload cap accepted the 31st upload')
except HTTPError as error:
assert error.code == 429, error
assert error.headers.get('Retry-After') == '15', error.headers
assert json.load(error)['detail'] == 'Muitos envios ao mesmo tempo. O site tenta de novo sozinho.'
for uid in pending:
client.call(f'/uploads/{uid}', expected=200, method='DELETE')
# Sentry DTF-WEB-1: 66 sheets in one ready-sheet item is quoted and
# approved; the old cap of 20 refused it with a generic 422.
uploads = [upload_bytes(client, PNG, name=f'SHEET66-{index}.png') for index in range(66)]