03:00:0050% OFFClaim

Preflight first and last frame files before binding a pair

Check two original PNGs for exact dimensions, 16:9 ratio, complete decode and role-specific SHA-256 binding; reject portrait, swapped and missing inputs.

Prove that the files assigned to first and last are the intended readable images with matching geometry. This does not prove semantic continuity or a provider’s first/last-frame capability.

Previously recorded numerical observations below describe the original local fixture runs. For a reproduction, use the new receipt and its actual tool versions and hashes; an old observation is not a guaranteed result on every installation.

Preparation

  • Save each complete code block below under its displayed filename in one empty local folder. Run commands from that folder. The scripts create their synthetic inputs and manifests in the chosen output directory; inspect those files after running. Use an output directory that does not already exist. All relative paths below refer to this working folder.
  • Use Node.js and an installed FFmpeg. Set FFMPEG_BIN to its absolute path if it is not on PATH; the recorded fixture used FFmpeg 6.0.
  • Inspect binding.json and the original 320×180 first.png/last.png practice images in my-run/inputs. A separate 180×320 PNG deliberately violates the pair geometry.
  • Keep the role name, basename and expected SHA-256 together. Run into a new output directory so an earlier manifest cannot silently refer to replaced input files.

Run

node run-recipe.mjs --out ./my-run

01. Freeze each role-to-file assignment

The script creates a pair of small original RGB illustrations and writes a binding manifest. First and last have distinct bytes and edge markers. Hashes are captured from these exact files, not inferred from an upload order or a filename containing “first”.

02. Validate geometry and decode the image

For each bound file, read the PNG signature and IHDR width/height, then fully decode it through FFmpeg to one RGB frame. Both must be 320×180 and share the explicitly selected 16:9 canvas. Header dimensions alone would not establish that compressed pixels decode.

03. Replay the four unsafe assignments

Run the portrait-last, swapped filename, missing last and parent-path cases. Each is expected to fail for its own reason: dimension mismatch, hash binding, missing input or unsafe basename. failure-receipt.json retains the actual exception messages.

04. Retain the pair manifest with the files

Check seven passing assertions and the pre/post script hashes in execution-receipt.json. Keep both PNGs and binding.json together when adapting your own upload flow. Review camera, object and endpoint semantics separately; these file checks do not inspect them.

Acceptance

  • The correct first/last pair produces one completely decoded RGB frame per PNG.
  • Both roles report exactly 320×180 pixels and the cross-multiplication confirms 16:9.
  • First and last have different SHA-256 values, matching their bound original files.
  • The 180×320 replacement is rejected for dimension mismatch.
  • Swapping the last filename into the first role without changing its expected hash is rejected.
  • A missing file and a parent-path basename are rejected, with all seven checks recorded.

Troubleshooting

The tail image has the right subject but fails geometry.

Change only its actual pixel canvas to the pair’s selected dimensions, re-export, and capture a new hash. Renaming a portrait file cannot change its geometry.

Two files have been uploaded in the wrong order.

Correct the role-to-basename mapping, then regenerate both expected hashes from the selected files and recheck the manifest.

A header looks valid but decoding stops.

Replace only the damaged file with a complete local copy and rerun full decode. Do not accept IHDR dimensions as proof of readable pixels.

Keep with the result

This pair manifest is a file-readiness record. It does not demonstrate a generated transition, endpoint compatibility or visual preservation between the two states.

Complete source and input construction

Save every file below with its exact filename in the same folder. The source includes the input definitions and construction logic; code blocks are complete, including all companion modules.

common.mjs

import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { createHash } from 'node:crypto';
import { deflateSync } from 'node:zlib';
import { spawnSync } from 'node:child_process';
import http from 'node:http';
export { fs, path, http };
export const sha = b => createHash('sha256').update(b).digest('hex');
export const ensure = (v,m) => { if (!v) throw new Error(m); };
export const json = (p,v) => fs.writeFileSync(p,JSON.stringify(v,null,2)+'\n');
export function png(w,h,colour) {
  const raw=Buffer.alloc(h*(w*3+1));
  for(let y=0;y<h;y++) for(let x=0;x<w;x++) { const c=typeof colour==='function'?colour(x,y):colour; for(let k=0;k<3;k++) raw[y*(w*3+1)+1+x*3+k]=c[k]; }
  const crc=b=>{let c=0xffffffff;for(const n of b){c^=n;for(let j=0;j<8;j++)c=(c>>>1)^((c&1)?0xedb88320:0);}return(c^0xffffffff)>>>0;};
  const chunk=(t,b)=>{const n=Buffer.alloc(4),s=Buffer.from(t),c=Buffer.alloc(4);n.writeUInt32BE(b.length);c.writeUInt32BE(crc(Buffer.concat([s,b])));return Buffer.concat([n,s,b,c]);};
  const head=Buffer.alloc(13);head.writeUInt32BE(w);head.writeUInt32BE(h,4);head[8]=8;head[9]=2;
  return Buffer.concat([Buffer.from([137,80,78,71,13,10,26,10]),chunk('IHDR',head),chunk('IDAT',deflateSync(raw)),chunk('IEND',Buffer.alloc(0))]);
}
export function dimensions(b){ensure(b.subarray(0,8).equals(Buffer.from([137,80,78,71,13,10,26,10])),'PNG_SIGNATURE');return[b.readUInt32BE(16),b.readUInt32BE(20)];}
export const maxDelta=(a,b)=>{ensure(a.length===b.length,'BYTE_LENGTH');let d=0;for(let i=0;i<a.length;i++)d=Math.max(d,Math.abs(a[i]-b[i]));return d;};
export const safeName=s=>typeof s==='string'&&/^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/.test(s);
export async function request(url,method='GET',body){
  const u=new URL(url);ensure(u.hostname==='127.0.0.1'&&u.protocol==='http:','LOOPBACK_ONLY');
  return await new Promise((resolve,reject)=>{const q=http.request(u,{method,agent:false,headers:body?{'content-type':'application/json'}:{}},r=>{let size=0;const a=[];r.on('data',b=>{size+=b.length;if(size>2*1024*1024){r.destroy(new Error('RESPONSE_LIMIT'));return;}a.push(b);});r.on('error',reject);r.on('end',()=>resolve({status:r.statusCode,body:Buffer.concat(a)}));});q.setTimeout(3000,()=>q.destroy(new Error('HTTP_TIMEOUT')));q.on('error',reject);q.end(body===undefined?undefined:JSON.stringify(body));});
}
export async function closeServer(server){await new Promise((resolve,reject)=>{server.close(e=>e?reject(e):resolve());server.closeAllConnections();});}
export async function run(task,fn,media=false){
 const here=path.dirname(fileURLToPath(import.meta.url));const args=process.argv.slice(2);ensure(args.length===0||(args.length===2&&args[0]==='--out'),'USAGE: node run-recipe.mjs --out NEW_DIRECTORY');
 const out=path.resolve(args[1]||path.join(here,'my-run'));ensure(!fs.existsSync(out),'REFUSE_OVERWRITE');fs.mkdirSync(out,{recursive:true});
 const tmp=path.join(out,'.tmp');fs.mkdirSync(tmp);const tests=[],failures=[],commands=[];const scripts=Object.fromEntries(['run-recipe.mjs','common.mjs'].map(n=>[n,sha(fs.readFileSync(path.join(here,n)))]));
 const h={out,tmp,info:{},p:n=>path.join(out,n),check:(name,v,detail={})=>{ensure(v,`CHECK_FAILED:${name}`);tests.push({name,passed:true,...detail});},reject:(name,fn,pattern)=>{let e;try{fn();}catch(x){e=x;}ensure(e&&(!pattern||pattern.test(e.message)),`EXPECTED_REJECTION_MISSING:${name}`);const r={name,passed:true,expectedRejection:true,error:String(e.message).slice(0,900)};tests.push(r);failures.push(r);}};
 const bin=process.env.FFMPEG_BIN||'ffmpeg';
 h.ff=(args,allowFailure=false)=>{const all=['-hide_banner','-nostdin','-loglevel','error','-threads','1','-filter_threads','1',...args];const r=spawnSync(bin,all,{shell:false,timeout:15000,killSignal:'SIGKILL',maxBuffer:8*1024*1024});commands.push({args:all,status:r.status,signal:r.signal,stdoutBytes:r.stdout?.length||0,stderrTail:r.stderr?.toString().slice(-1800)||'',error:r.error?.message||null});if(!allowFailure)ensure(!r.error&&r.status===0,`FFMPEG:${r.error?.message||r.stderr?.toString().slice(-900)}`);return r;};
 h.decode=(file,w,hgt)=>{const r=h.ff(['-xerror','-err_detect','explode','-i',file,'-map','0:v:0','-an','-pix_fmt','rgb24','-f','rawvideo','pipe:1']);ensure(r.stdout.length>0&&r.stdout.length%(w*hgt*3)===0,'DECODE_GEOMETRY');return r.stdout;};
 let fatal=null;let ffmpeg=null;
 try{if(media){const r=h.ff(['-version']);ffmpeg={version:r.stdout.toString().split('\n')[0],binarySha256:path.isAbsolute(bin)?sha(fs.readFileSync(bin)):null};}await fn(h);ensure(tests.length>=6,'AT_LEAST_SIX_CHECKS');}
 catch(e){fatal=e.stack||String(e);process.exitCode=1;}
 finally{fs.rmSync(tmp,{recursive:true,force:true});const scriptsAfter=Object.fromEntries(Object.keys(scripts).map(n=>[n,sha(fs.readFileSync(path.join(here,n)))]));if(JSON.stringify(scriptsAfter)!==JSON.stringify(scripts)){fatal='SCRIPT_CHANGED_DURING_RUN';process.exitCode=1;}
 const receipt={task,recordedAt:new Date().toISOString(),nodeVersion:process.version,ffmpeg,scriptHashes:scripts,scriptBindingVerified:JSON.stringify(scriptsAfter)===JSON.stringify(scripts),fixtureOnly:true,providerModelTest:false,productionTaskRun:false,networkScope:'loopback-only or no network',passed:!fatal,checks:tests,observations:h.info,commands,fatal};json(h.p('execution-receipt.json'),receipt);json(h.p('failure-receipt.json'),{task,expectedFailureChecks:failures});fs.writeFileSync(h.p('checks.csv'),'check,result,expected_rejection\n'+tests.map(t=>`${t.name},${t.passed?'pass':'fail'},${Boolean(t.expectedRejection)}`).join('\n')+'\n');console.log(JSON.stringify({task,passed:!fatal,checks:tests.length,expectedRejections:failures.length,out}));if(fatal)console.error(fatal);}
}

run-recipe.mjs

import {fs,path,json,png,sha,ensure,dimensions,safeName,run} from './common.mjs';
await run('first-last-frame-file-preflight',async h=>{
 const inputs=h.p('inputs');fs.mkdirSync(inputs);fs.writeFileSync(path.join(inputs,'first.png'),png(320,180,(x,y)=>x<32?[220,60,50]:[20,100+y%80,160]));fs.writeFileSync(path.join(inputs,'last.png'),png(320,180,(x,y)=>x>287?[240,180,30]:[35,130,100+y%80]));fs.writeFileSync(path.join(inputs,'portrait.png'),png(180,320,[90,80,170]));
 const binding={first:{file:'first.png',sha256:sha(fs.readFileSync(path.join(inputs,'first.png')))},last:{file:'last.png',sha256:sha(fs.readFileSync(path.join(inputs,'last.png')))},width:320,height:180};json(h.p('binding.json'),binding);
 const preflight=b=>{for(const role of ['first','last']){const entry=b[role];ensure(safeName(entry.file),'UNSAFE_FILENAME');const p=path.join(inputs,entry.file);ensure(fs.existsSync(p),'MISSING_FRAME');const bytes=fs.readFileSync(p);ensure(sha(bytes)===entry.sha256,'HASH_BINDING');const [w,ht]=dimensions(bytes);ensure(w===b.width&&ht===b.height,'DIMENSION_MISMATCH');const rgb=h.decode(p,w,ht);ensure(rgb.length===w*ht*3,'ONE_FRAME_REQUIRED');}return true;};
 h.check('valid-frame-pair-decodes',preflight(binding));h.check('pair-is-16-by-9',binding.width*9===binding.height*16);h.check('first-and-last-are-distinct',binding.first.sha256!==binding.last.sha256);h.reject('portrait-last-rejected',()=>preflight({...binding,last:{file:'portrait.png',sha256:sha(fs.readFileSync(path.join(inputs,'portrait.png')))}}),/DIMENSION_MISMATCH/);h.reject('swapped-file-binding-rejected',()=>preflight({...binding,first:{...binding.first,file:'last.png'}}),/HASH_BINDING/);h.reject('missing-last-rejected',()=>preflight({...binding,last:{...binding.last,file:'missing.png'}}),/MISSING_FRAME/);h.reject('path-traversal-rejected',()=>preflight({...binding,first:{...binding.first,file:'../first.png'}}),/UNSAFE_FILENAME/);h.info={first:[320,180],last:[320,180],ratio:'16:9',scope:'file integrity and binding only; no semantic continuity or model capability test'};
},true);

Technical references

Preflight first and last frame files before binding a pair — Original task diagram; not a model output
Original task diagram; not a model output
Preflight first and last frame files before binding a pair