fix: review of phase-2 stage 0 and fronts 5, 6 and 11
All checks were successful
Build and deploy / Publish images (push) Successful in 1m5s
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 5m7s
Build and deploy / Secret scan and release gate (push) Successful in 6s

- A paid treatment adds its 24 h to Arte recebida's acceptable time, on
  the card and in Números (fronts 5 and 11).
- TINY_PRODUCT_TREATMENT is a required Tiny setting once the treatment
  has a price, instead of every treated order failing at the Tiny.
- A quote reads each PDF once: Files caches the header and the DPI.
- A proof made from the parent's final split into parts uses the part
  that holds the finest stroke, not the last one (0.1).
- Prumo report: one format line per item, the time from the claim (kept
  on the finished print file), and the stroke class in customer words.
- The Site says the Prumo checks the art, and a too-tall PNG no longer
  says "Este PDF".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-09 10:45:43 -03:00
parent 5a51084c8f
commit 5aafd9ee91
11 changed files with 227 additions and 37 deletions

View File

@@ -36,7 +36,20 @@ def run():
board = client.call('/operator/board', operator=True)
mine = next(o for o in board['orders'] if o['id'] == str(order))
assert mine['late'] == 'bad' and mine['limit_hours'] == 1, mine
print('PASS: stage limits are editable and a card past the limit is yellow/red')
# A paid treatment gives Art received its extra hours (front 5).
with db.connect() as c:
c.execute('UPDATE dtf_local.orders SET snapshot = snapshot || %s WHERE id=%s',
(Jsonb({'treatment': {'cents': 990, 'hours': 3}}), order))
board = client.call('/operator/board', operator=True)
mine = next(o for o in board['orders'] if o['id'] == str(order))
assert mine['late'] is None and mine['limit_hours'] == 4, mine
with db.connect() as c:
c.execute("UPDATE dtf_local.orders SET snapshot = snapshot - 'treatment' WHERE id=%s", (order,))
board = client.call('/operator/board', operator=True)
mine = next(o for o in board['orders'] if o['id'] == str(order))
assert mine['late'] == 'bad' and mine['limit_hours'] == 1, mine
print('PASS: stage limits are editable, a card past the limit is yellow/red, '
'and a paid treatment adds its hours')
finally:
client.call('/operator/stage-limits', {'limits': defaults}, operator=True)
with db.connect() as c:

View File

@@ -5,6 +5,7 @@ Runs where Pillow and pikepdf are installed (the API image).
import io
import tempfile
import unittest
from unittest import mock
import pikepdf
from PIL import Image
@@ -26,6 +27,25 @@ class FakeFiles:
return grade_check.pdf_dpi(handle.name)
class CountingStorage:
"""A storage that counts every read, keyed by object_key as the real one."""
def __init__(self, blobs):
self.bucket = 'bucket'
self.blobs = blobs
self.downloads = 0
self.heads = 0
self.client = self
def get_object(self, Bucket, Key, Range=None):
self.heads += 1
return {'Body': io.BytesIO(self.blobs[Key][:grade_check.HEAD_BYTES])}
def download_fileobj(self, bucket, key, handle):
self.downloads += 1
handle.write(self.blobs[key])
def encoded(fmt, size, **options):
out = io.BytesIO()
Image.new('RGBA' if fmt in ('PNG', 'WEBP') else 'RGB', size, (200, 30, 30)).save(out, fmt, **options)
@@ -81,6 +101,19 @@ class GradeCheckTests(unittest.TestCase):
self.assertEqual(claim(40, [('x.cdr', 57, 0)]), 'Nota não conferida no servidor')
self.assertIsNone(claim(0, [('x.cdr', 57, 0)]))
def test_a_file_is_read_once_per_quote(self):
storage = CountingStorage({'k.pdf': b'%PDF-1.4 test', 'k.png': encoded('PNG', (100, 50))})
files = grade_check.Files(storage)
pdf_row = {'object_key': 'k.pdf', 'size': 15, 'name': 'a.pdf'}
with mock.patch.object(grade_check, 'pdf_dpi', return_value=300):
self.assertEqual(files.pdf_dpi(pdf_row), 300)
self.assertEqual(files.pdf_dpi(pdf_row), 300)
self.assertEqual(storage.downloads, 1)
png_row = {'object_key': 'k.png', 'size': 1, 'name': 'a.png'}
self.assertEqual(files.head(png_row)[:8], b'\x89PNG\r\n\x1a\n')
self.assertEqual(files.head(png_row)[:8], b'\x89PNG\r\n\x1a\n')
self.assertEqual(storage.heads, 1)
def test_resolution_boundaries_and_consent(self):
width = lambda dpi: int(dpi * 57 / 2.54) + 1
files = FakeFiles({f'{dpi}.png': encoded('PNG', (width(dpi), 20))

View File

@@ -2,9 +2,25 @@
import unittest
from decimal import Decimal
from app.printjobs import proof_part
from app.printpng import proof_cut
class ProofPartTests(unittest.TestCase):
def test_one_part_keeps_the_same_fraction(self):
self.assertEqual(proof_part([100], 100, 0.5), (0, 0.5))
self.assertEqual(proof_part([30], 30, 0.8), (0, 0.8))
def test_the_part_holding_the_finest_stroke_is_chosen(self):
self.assertEqual(proof_part([1000, 1000, 1000], 3000, 0.1), (0, 0.3))
self.assertEqual(proof_part([1000, 1000, 1000], 3000, 0.5), (1, 0.5))
self.assertEqual(proof_part([1000, 1000, 1000], 3000, 0.75), (2, 0.25))
def test_the_fraction_is_recalculated_inside_the_chosen_part(self):
self.assertEqual(proof_part([1500, 1500], 3000, 0.75), (1, 0.5))
self.assertEqual(proof_part([1500, 1500], 3000, 1), (1, 1))
class ProofCutTests(unittest.TestCase):
def test_centres_the_window_on_the_finest_stroke(self):
self.assertEqual(proof_cut(100, 15, 0.5), [Decimal('42.5'), Decimal('57.5')])

View File

@@ -17,7 +17,8 @@ class PrumoReportTests(unittest.TestCase):
}
started = datetime(2026, 11, 5, 14, 0, tzinfo=timezone.utc)
return {'snapshot': {'items': [item]}, 'print_files': [{
'item_index': 0, 'status': 'ready', 'created_at': started, 'finished_at': started + timedelta(seconds=41),
'item_index': 0, 'status': 'ready', 'created_at': started - timedelta(minutes=5),
'claimed_at': started, 'finished_at': started + timedelta(seconds=41),
'detail': {'format': 'png', 'dpi': 300, 'parts': [
{'from_cm': '0', 'to_cm': '15'}, {'from_cm': '15', 'to_cm': '16'}]},
}]}
@@ -34,13 +35,36 @@ class PrumoReportTests(unittest.TestCase):
self.assertIn('cliente escolheu imprimir em C1', text)
self.assertIn('2 partes (15,00 + 1,00)', text)
self.assertIn('Prumo levou 41 s', text)
self.assertNotIn('Prumo levou 341 s', text)
def test_without_a_claim_time_the_generation_line_is_hidden(self):
order = self.order()
del order['print_files'][0]['claimed_at']
text = '\n'.join(report(order, {'u1': {'name': 'arte.pdf', 'original_name': 'arte.cdr'}}))
self.assertNotIn('Prumo levou', text)
def test_one_format_line_per_item(self):
order = self.order()
item = order['snapshot']['items'][0]
item['uploads'] = ['u1', 'u2', 'u3']
uploads = {uid: {'name': f'arte-{uid}.png'} for uid in item['uploads']}
text = '\n'.join(report(order, uploads))
self.assertEqual(text.count('Formato detectado'), 1)
self.assertIn('Formato detectado: PNG (3 arquivos)', text)
# Mixed formats name them once, sorted, and the per-file changes stay.
uploads['u2'] = {'name': 'arte-u2.pdf', 'original_name': 'arte-u2.cdr'}
mixed = '\n'.join(report(order, uploads))
self.assertEqual(mixed.count('Formatos detectados'), 1)
self.assertIn('Formatos detectados: PDF, PNG', mixed)
self.assertIn('Chegou CDR, era PDF por dentro', mixed)
def test_customer_summary_is_plain_language(self):
lines = customer_summary(self.order()['snapshot']['items'])
text = ' '.join(lines)
self.assertIn('96 DPI', text)
self.assertIn('3 pontinhos', text)
self.assertIn('C2', text)
self.assertIn('Sua arte tem traços médios; a impressão foi ajustada para eles.', text)
self.assertNotIn('O traço mais fino foi medido em C2.', text)
self.assertIn('C1', text)
self.assertIn('será preparado', text)
self.assertNotIn('foi ampliada', text)

View File

@@ -801,5 +801,16 @@ class DefaultSkuTests(unittest.TestCase):
self.assertEqual(tiny.mode_codes('uvfile'), tiny.sku_codes('UV.P'))
class TreatmentSettingTests(unittest.TestCase):
"""A paid treatment needs its own Tiny product, asked with the rest."""
def test_the_treatment_product_is_required_only_when_it_is_paid(self):
from app.tiny import required_settings
with mock.patch.dict(os.environ, {'TREATMENT_CENTS': '0'}):
self.assertNotIn('TINY_PRODUCT_TREATMENT', required_settings())
with mock.patch.dict(os.environ, {'TREATMENT_CENTS': '5000'}):
self.assertIn('TINY_PRODUCT_TREATMENT', required_settings())
if __name__ == '__main__':
unittest.main()