ZZZ Digital Lab

Back to n8n workflow hardening

make_images.py

"""Render 1000x750 portfolio cards from real local evidence. No stock assets."""
import json,argparse
from pathlib import Path
from PIL import Image,ImageDraw,ImageFont
ROOT=Path(__file__).resolve().parent
BG='#eff3f8'; NAVY='#14283f'; MUTED='#536a80'; GREEN='#087c64'; RED='#b83f48'; AMBER='#976400'; LINE='#d8e1ec'
def font(size,bold=False,mono=False):
 names=['consola.ttf','DejaVuSansMono.ttf'] if mono else (['segoeuib.ttf','DejaVuSans-Bold.ttf'] if bold else ['segoeui.ttf','DejaVuSans.ttf'])
 for name in names:
  try: return ImageFont.truetype(name,size)
  except OSError: pass
 return ImageFont.load_default(size=size)
def text(d,xy,value,size=20,fill=NAVY,bold=False,mono=False,max_width=None):
 f=font(size,bold,mono)
 if max_width is not None:
  while d.textbbox((0,0),value,font=f)[2]>max_width and size>13: size-=1; f=font(size,bold,mono)
  if d.textbbox((0,0),value,font=f)[2]>max_width: raise ValueError('Text exceeds card: '+value)
 d.text(xy,value,font=f,fill=fill)
def card(title,subtitle):
 im=Image.new('RGB',(1000,750),BG); d=ImageDraw.Draw(im)
 d.rectangle((0,0,1000,13),fill=GREEN); text(d,(44,35),'SYNTHETIC PORTFOLIO DEMO',15,GREEN,True)
 text(d,(44,69),title,36,bold=True,max_width=912); text(d,(44,121),subtitle,19,MUTED,max_width=912)
 return im,d
def panel(d,box,fill='white'): d.rounded_rectangle(box,16,fill=fill)
def footer(d,left,right):
 d.line((44,692,956,692),fill=LINE,width=2); text(d,(44,708),left,15,MUTED,max_width=660); text(d,(752,708),right,15,GREEN,True,max_width=204)
def save(im,root,name):
 (root/'images').mkdir(exist_ok=True); im.save(root/'images'/name)
def load(root,name): return json.loads((root/name).read_text(encoding='utf-8'))
def n8n():
 root=ROOT; lint=load(root,'evidence/lint.json'); tests=load(root,'evidence/tests.json'); replay=load(root,'evidence/replay.json')
 im,d=card('n8n workflow hardening','Static export checks and a local JavaScript contract replay')
 before=lint['before']; after=lint['after']; panel(d,(44,174,956,279),NAVY)
 text(d,(64,190),str(len(before))+' baseline findings',27,'#ffce7e',True); text(d,(510,190),str(len(after))+' hardened findings',27,'#9bdcca',True)
 text(d,(64,236),'Findings are static policy checks, not an n8n execution certificate.',18,'white')
 for x,title,color,lines in [(44,'BEFORE',RED,['Missing retry / timeout bounds','Repeated events processed again','No error workflow or dead-letter path','Back-edge creates an unbounded cycle','Synthetic secret marker in a header']),
 (508,'AFTER',GREEN,['3 attempts + fixed 1-second backoff','Stable receiver idempotency key','Error workflow + dead-letter sink','Acyclic graph + bounded event list','Credential references; no inline value'])]:
  panel(d,(x,304,x+448,584)); text(d,(x+20,320),title,20,color,True)
  for i,line in enumerate(lines): text(d,(x+20,366+i*38),line,18,max_width=410)
 text(d,(44,613),f"{tests['passed']}/{tests['passed']+tests['failed']} tests pass",26,GREEN,True); text(d,(383,620),'Exports inactive. Destinations are .invalid placeholders.',18,max_width=574)
 footer(d,'Evidence: evidence/lint.json and evidence/tests.json','n8n runtime not run'); save(im,root,'01-before-after.png')
 im,d=card('Failure and recovery contract checks','Actual offline replay of the JavaScript embedded in the hardened export')
 panel(d,(44,174,956,487))
 facts=[('Success',str(replay['success']['accepted'])+' accepted'),('Duplicate replay',str(replay['duplicate']['accepted'])+' accepted again'),('Transient errors',str(replay['transient']['attempts'])+' attempts; bounded backoff'),('Permanent failure',str(replay['permanent']['deadLetters'])+' dead-letter record'),('Recovery replay',str(replay['recovery']['accepted'])+' accepted after recovery'),('Oversized batch','Rejected before processing')]
 for i,(label,result) in enumerate(facts):
  y=193+i*46; text(d,(64,y),label,21,bold=True); text(d,(364,y),result,21,GREEN,max_width=565)
 panel(d,(44,511,956,665),NAVY); text(d,(64,530),'Receiver contract',22,'#9bdcca',True)
 text(d,(64,574),'Atomic idempotent insert is required at the receiving API.',21,'white',max_width=860)
 text(d,(64,612),'Local fake receiver checks the contract; live services are unverified.',19,'white',max_width=860)
 footer(d,'Tests and written handoff; AI coding tools','No runtime guarantee'); save(im,root,'02-verification.png'); return root


if __name__=='__main__':
    n8n()
    print('Rendered two evidence-based PNGs, 1000x750, in images/')