feat: a 57 cm ready sheet whose real width is not 57 cm opens a pop-up and is not accepted (Marcus, 2026-12-01)
Some checks failed
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Failing after 2m34s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Has been skipped

Order #177: a 35,8 cm sheet at 300 DPI was stretched to the film's 57 cm,
the v0 Site rule for a ready sheet image. Marcus: a pop-up on upload, and
neither a narrower nor a wider sheet is accepted.

The real width is known for a PNG whose pHYs records 200 DPI or more (the
A1 threshold) and for a PDF page; tolerance 0,1 cm (6732 px at 300 DPI is
56,998 cm). Arquivo por metro and Premium only. UV, a PNG without pHYs or
under 200 DPI, and every existing order and approved cart are unchanged.

Site: medirFolha refuses it, the sheet leaves the list (its upload stops),
and #larguraDlg lists each refused file with its width and DPI; Entendi or
Escape closes it and focus returns to the upload area; the thin-stroke
dialog waits while it is open. Server: sheet_width_issue refuses the same
cart at checkout (POST /api/quotes, 422), so a reorder or an edited page
cannot get round it. Contract: output/revisao/contrato-largura-folha.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-12-01 17:41:02 -03:00
parent 12bc0c3e1a
commit 711199558f
9 changed files with 244 additions and 6 deletions

View File

@@ -13,7 +13,7 @@ from ..core import db
from ..core.auth import owner
from ..core.models import QuoteRequest
from .. import quote_review
from ..grade_check import Files, mismatch, proportion_issue, resolution_issue, source_dpi
from ..grade_check import Files, mismatch, proportion_issue, resolution_issue, sheet_width_issue, source_dpi
from ..runtime import freight, payment, quote_view, require_delivery_available, storage, upload_row
from ..scanning import require_clean
@@ -79,7 +79,8 @@ def create_quote(body: QuoteRequest, session_id=Depends(owner)):
dpis.append(dpi)
if dpis:
draft_item['source_dpi'] = round(min(dpis))
issue = proportion_issue(files, draft['items'], rows) or resolution_issue(files, draft['items'], rows)
issue = (proportion_issue(files, draft['items'], rows) or sheet_width_issue(files, draft['items'], rows)
or resolution_issue(files, draft['items'], rows))
if issue:
raise HTTPException(422, issue)
note = mismatch(files, draft['items'], rows) if reason is None else None

View File

@@ -324,6 +324,87 @@ def proportion_issue(files, items, rows):
return None
# A ready sheet in the 57 cm textile products must be 57 cm wide where its real
# width is known (Marcus, 2026-12-01: a pop-up on upload and refused, narrower
# or wider). Known means a PNG whose pHYs records TRUSTED_DPI or more (the A1
# threshold, rodada 5) or a PDF page; anything else keeps the v0 rule (the
# image stretched to the film). output/revisao/contrato-largura-folha.md;
# the Site has the same numbers (web/site-config.js LARGURA_EXATA).
EXACT_SHEET_WIDTH_CM = {'file': 57.0, 'premium': 57.0}
SHEET_WIDTH_TOLERANCE_CM = 0.1
TRUSTED_DPI = 200
def png_saved_dpi(head):
"""The DPI a PNG records in its pHYs chunk, rounded as the Site rounds it
(web/site-pdf.js dpiSalvoPng: Math.round(pixels per metre × 0.0254)), or
None: not a PNG, no pHYs before the first IDAT, a unit that is not the
metre, X and Y that differ, or a chunk cut off by the head's end."""
if head[:8] != b'\x89PNG\r\n\x1a\n':
return None
offset = 8
while offset + 8 <= len(head):
length = struct.unpack('>I', head[offset:offset + 4])[0]
kind = head[offset + 4:offset + 8]
if kind in (b'IDAT', b'IEND'):
return None
end = offset + 8 + length
if end + 4 > len(head):
return None # chunk cut off by the head's end
if kind == b'pHYs':
if length < 9:
return None
ppm_x, ppm_y, unit = struct.unpack('>IIB', head[offset + 8:offset + 17])
if unit == 1 and ppm_x == ppm_y > 0:
return js_round(ppm_x * 0.0254)
return None
offset = end + 4
return None
def sheet_width_issue(files, items, rows):
"""Why a cart cannot be approved: a ready sheet of a 57 cm textile item
(EXACT_SHEET_WIDTH_CM) whose real width is off by more than
SHEET_WIDTH_TOLERANCE_CM, or None. A PNG's real width is its pixels ÷ its
pHYs DPI × 2.54 when that DPI is TRUSTED_DPI or more; a PDF's is the
source's width_cm (the page the Site measured). Anything else passes."""
for index, item in enumerate(items, 1):
mode = item.get('mode')
if mode not in EXACT_SHEET_WIDTH_CM:
continue
expected = EXACT_SHEET_WIDTH_CM[mode]
expected_text = f'{expected:g}'
for number, source in enumerate(item['production']['sources'], 1):
if source.get('kind') != 'sheet':
continue
row = rows.get(str(source['upload_id']))
if not row:
continue
name = row['name'].lower()
if name.endswith('.pdf'):
cm = float(source['width_cm'])
dpi = None
elif name.endswith('.png'):
dpi = png_saved_dpi(files.head(row))
if dpi is None or dpi < TRUSTED_DPI:
continue
size = image_size(files.head(row))
if not size or not all(size):
continue
cm = size[0] / dpi * 2.54
else:
continue
if abs(cm - expected) <= SHEET_WIDTH_TOLERANCE_CM:
continue
cm_text = f'{cm:.1f}'.replace('.', ',')
if dpi is None:
return (f'Item {index}: a folha {number} tem {cm_text} cm de largura. '
f'A folha montada precisa ter {expected_text} cm.')
return (f'Item {index}: a folha {number} tem {cm_text} cm de largura ({dpi} DPI). '
f'A folha montada precisa ter {expected_text} cm.')
return None
def mismatch(files, items, rows):
"""Why a cart's grades cannot be approved at checkout, or None."""
for item in items: