feat: residue and a solid background stop a ready sheet before payment
Some checks failed
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Integration suite on a real stack (push) Failing after 4m10s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Has been skipped

Dropstar's items 2 and 3 (2026-10-21): both were warnings the customer
could pay past; now one dot is enough to stop the order.

- every pixel is read (images in strips at 1:1, large PNGs while they
  stream, PDFs rendered in strips at about 0,2 mm): the old check shrank
  the image first and could miss a small dot, or sampled every n-th pixel
- a residue is ink under 2 mm on both sides, measured from where the ink
  starts and ends in each cell: the same dot gets the same verdict wherever
  it falls on the grid, from 0,5 to 4 mm (his acceptance test)
- a solid background is under 1,5 % of transparent pixels; a JPG sheet
  always has one
- the sheet says how many dots there are, circles them on the preview, and
  asks to erase them and send again; the order waits for the check to end
- the page no longer offers JPG for a ready sheet

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-22 16:37:46 -03:00
parent fe7bf4ef07
commit e3c31e43e5
8 changed files with 258 additions and 71 deletions

View File

@@ -133,12 +133,15 @@ try{
if(drop)$('zona').dispatchEvent(new DragEvent('drop',{dataTransfer:dt,bubbles:true,cancelable:true}));
else{$('inp').files=dt.files;$('inp').dispatchEvent(new Event('change',{bubbles:true}));}
};
// A genuine mounted sheet spans the film width with printable resolution.
window.sendSheet=async()=>{
// A genuine mounted sheet spans the film width with printable resolution,
// on a transparent background; or with a solid one, or a residue dot.
window.sendSheet=async({fundo=false,ponto=false}={})=>{
const cm=larguraFilme(), px=Math.ceil(cm/2.54*150);
const c=document.createElement('canvas');c.width=px;c.height=Math.round(px*0.6);
const ctx=c.getContext('2d');ctx.fillStyle='white';ctx.fillRect(0,0,c.width,c.height);
const ctx=c.getContext('2d');
if(fundo){ctx.fillStyle='white';ctx.fillRect(0,0,c.width,c.height);}
ctx.fillStyle='#222';ctx.fillRect(40,40,px/4,px/4);
if(ponto)ctx.fillRect(Math.round(px*0.8),Math.round(c.height/2),4,4);
const blob=await new Promise(r=>c.toBlob(r,'image/png'));
const dt=new DataTransfer();dt.items.add(new File([blob],'folha-montada.png',{type:'image/png'}));
$('inp').files=dt.files;$('inp').dispatchEvent(new Event('change',{bubbles:true}));
@@ -273,6 +276,39 @@ try{
assert.equal(await evaluate(`document.querySelectorAll('.folhaPrevia').length`),1);
await evaluate(`(()=>{folhas.push({f:new File(['manual'],'manual.cdr'),med:null,rep:1,m:1,an:null});pintaFolha();})()`);
await waitFor(()=>evaluate(`itemAtual?.nota===0 && itemAtual?.unit===TABELA[modo]`),'mixed analyzed and manual sheets use table pricing');
// Residue and a solid background stop the order before payment (Dropstar,
// 2026-10-21). A residue is ink under 2 mm on both sides, measured in real
// millimetres: the same dot, wherever it falls on the 1 mm grid, gets the
// same verdict, from 0,5 to 4 mm.
assert.deepEqual(await evaluate(`(async()=>{
const medir=async(mm,dx,dy)=>{const c=document.createElement('canvas');c.width=5700;c.height=600;
const ctx=c.getContext('2d');ctx.fillStyle='#000';ctx.fillRect(100,100,3000,300);
const lado=Math.round(mm*10);ctx.fillRect(4000+dx,300+dy,lado,lado);
return analisarMapa(await mapaDaImagem(c,57)).residuos;};
const out={};
for(const mm of [0.5,1.5,1.9,2.1,4])out[mm]=[await medir(mm,0,0),await medir(mm,5,0),await medir(mm,0,5),await medir(mm,5,5)];
return out;})()`),
{'0.5':[1,1,1,1],'1.5':[1,1,1,1],'1.9':[1,1,1,1],'2.1':[0,0,0,0],'4':[0,0,0,0]});
// A large PNG is read as a stream; every pixel goes into the same ink map.
assert.deepEqual(await evaluate(`(async()=>{
const c=document.createElement('canvas');c.width=5700;c.height=600;
const ctx=c.getContext('2d');ctx.fillStyle='#000';ctx.fillRect(100,100,3000,300);ctx.fillRect(4005,305,12,12);
const blob=await new Promise(r=>c.toBlob(r,'image/png'));
const lido=await previaPngGrande(new File([blob],'folha.png'),600,null,57);
const a=analisarMapa(lido.mapa), b=analisarMapa(await mapaDaImagem(c,57));
return {stream:[a.residuos,a.artes,a.fundoChapado,a.pontos[0].mm],direct:[b.residuos,b.artes,b.fundoChapado,b.pontos[0].mm]};})()`),
{stream:[1,1,false,1.2],direct:[1,1,false,1.2]});
await click('#bVoltar');await click('[data-modo="file"]');
await evaluate('sendSheet({ponto:true})');
await waitFor(()=>evaluate(`folhas.length===1 && folhas[0].pct==null && folhas[0].an?.residuos===1`),'residue found');
await waitFor(()=>evaluate(`$('aoVivo').textContent.includes('ponto de recorte') && itemAtual===null`),'residue stops the order');
assert.equal(await evaluate(`$('lista').textContent.includes('Sobrou 1 ponto de recorte na sua folha')`),true);
await waitFor(()=>evaluate(`folhas[0].previewSrc.startsWith('data:image/webp')`),'residue circled on the preview');
await evaluate(`folhas=[];pintaFolha()`);
await evaluate('sendSheet({fundo:true})');
await waitFor(()=>evaluate(`folhas[0]?.an?.fundoChapado===true && itemAtual===null && $('aoVivo').textContent.includes('fundo transparente')`),'solid background stops the order');
assert.equal(await evaluate(`$('lista').textContent.includes('O fundo da sua folha não é transparente')`),true);
await evaluate(`folhas=[];pintaFolha()`);
// An image too small to span the film is refused, never silently repriced.
await click('#bVoltar');await click('[data-modo="file"]');
await evaluate('sendImage()');
@@ -296,6 +332,10 @@ try{
assert.deepEqual(rotated,{larg:50.8,alt:25.4,fonte:'página do PDF · UserUnit 2'});
const rendered=await evaluate(`rasterizarPdf(${pdfFile(pdfData({media:'[0 0 720 1440]',crop:'[0 0 360 720]',rotate:90,unit:2}))},50.8,25.4).then(r=>({ok:!!r.tela,error:r.erro||null}))`);
assert.deepEqual(rendered,{ok:true,error:null});
// A PDF sheet gets the same ink map, rendered in strips: a blank page is all transparent.
const mapped=await evaluate(`rasterizarPdf(${pdfFile(pdfData())},25.4,12.7,true).then(r=>{const a=analisarMapa(r.mapa);
return {fundo:a.fundoChapado,residuos:a.residuos,largura:r.mapa.wPx}})`);
assert.deepEqual(mapped,{fundo:false,residuos:0,largura:1270});
const multi=await evaluate(`medirFolha(${pdfFile(pdfData({pages:2}))})`);
assert.equal(multi.rejected,true);assert.match(multi.reason,/2 páginas/);
const beyondSpec=await evaluate(`medirFolha(${pdfFile(pdfData({media:'[0 0 20000 720]'}))})`);
@@ -368,6 +408,6 @@ try{
console.log('Supplied image:',JSON.stringify(layout));
}
assert.deepEqual(errors,[]);
console.log('PASS: JPG/PNG upload and drop, packed copies, 5 mm gaps, aspect ratio, live width/quantity/rotation/mirror, metres, ready-sheet pricing/repeats, UV, stale renders, strict inline CSP.');
console.log('PASS: JPG/PNG upload and drop, packed copies, 5 mm gaps, aspect ratio, live width/quantity/rotation/mirror, metres, ready-sheet pricing/repeats, residue and solid background stop the order, UV, stale renders, strict inline CSP.');
}catch(error){console.error(error);if(stderr)console.error(stderr.slice(-1200));process.exitCode=1;}
finally{ws?.close();chrome.kill();server.closeAllConnections();await new Promise(r=>server.close(r));}