The crew marks a duct section cleaned, but the photo index contains only its before photo. The same job records a rooftop fan as inaccessible. Both records need follow-up. One needs an after photo and the other needs an access plan.

Bind each photo to its system and component

Use the pair (systemId, componentId) as the scope key. Two kitchens can both have a HOOD-01. Each photo ID resolves to one system, component, and capture phase. A reference to P-06, the after photo for KITCHEN-B/HOOD-01, fails when attached to KITCHEN-A/HOOD-01. An unknown photo ID or a duplicate index entry also fails before the audit issues a queue.

System / component Reported status Attached photos Follow-up
KITCHEN-A/HOOD-01 cleaned P-01 before, P-02 after
KITCHEN-A/DUCT-02 cleaned P-03 before MISSING_AFTER_PHOTO
KITCHEN-A/ROOF-FAN-01 inaccessible P-04 before INACCESSIBLE
KITCHEN-B/HOOD-01 cleaned P-05 before, P-06 after

Freeze the follow-up queue for each audit

The fixture asks for both phases when a component is marked cleaned. For an inaccessible component, the access status itself creates a follow-up. The audit sorts the queue for stable review and freezes the array and each row. When the correct after photo P-07 arrives for the duct, a new audit returns only the rooftop fan. The original two entries remain available in the previous snapshot.

Run the benchmark

Save the block as hoodcert-benchmark.ts and run node --experimental-strip-types hoodcert-benchmark.ts with Node.js 24. The script needs no packages. Node.js TypeScript documentation

import assert from "node:assert/strict"; type ComponentKey = { systemId: string; componentId: string }; type ScopeRow = ComponentKey & { status: "cleaned" | "inaccessible"; photoIds: readonly string[]; }; type Photo = ComponentKey & { id: string; phase: "before" | "after" }; type FollowUp = ComponentKey & { reason: "INACCESSIBLE" | "MISSING_BEFORE_PHOTO" | "MISSING_AFTER_PHOTO"; }; function auditScope(scope: readonly ScopeRow[], photos: readonly Photo[]) { const photoIndex = new Map<string, Photo>(); for (const photo of photos) { assert(photo.id.trim(), "Photo ID is required"); assert(!photoIndex.has(photo.id), `Duplicate photo ID: ${photo.id}`); photoIndex.set(photo.id, photo); } const seenComponents = new Set<string>(); const followUps: Readonly<FollowUp>[] = []; for (const { systemId, componentId, status, photoIds } of scope) { assert(systemId.trim() && componentId.trim(), "System and component IDs are required"); const key = JSON.stringify([systemId, componentId]); const label = `${systemId}/${componentId}`; assert(!seenComponents.has(key), `Duplicate scope component: ${label}`); seenComponents.add(key); const attached = new Set<string>(); const phases = new Set<Photo["phase"]>(); for (const id of photoIds) { assert(!attached.has(id), `Duplicate photo reference: ${id}`); const photo = photoIndex.get(id); assert(photo, `Unknown photo ID: ${id}`); assert(photo.systemId === systemId && photo.componentId === componentId, `Photo ${id} belongs to ${photo.systemId}/${photo.componentId}, expected ${label}`); attached.add(id); phases.add(photo.phase); } const addFollowUp = (reason: FollowUp["reason"]) => { followUps.push(Object.freeze({ systemId, componentId, reason })); }; if (status === "inaccessible") { addFollowUp("INACCESSIBLE"); } else { if (!phases.has("before")) addFollowUp("MISSING_BEFORE_PHOTO"); if (!phases.has("after")) addFollowUp("MISSING_AFTER_PHOTO"); } } return Object.freeze(followUps.sort((left, right) => { const a = JSON.stringify([left.systemId, left.componentId, left.reason]); const b = JSON.stringify([right.systemId, right.componentId, right.reason]); if (a === b) return 0; return a < b ? -1 : 1; })); } const scope: readonly ScopeRow[] = [ { systemId: "KITCHEN-A", componentId: "ROOF-FAN-01", status: "inaccessible", photoIds: ["P-04"] }, { systemId: "KITCHEN-A", componentId: "HOOD-01", status: "cleaned", photoIds: ["P-01", "P-02"] }, { systemId: "KITCHEN-A", componentId: "DUCT-02", status: "cleaned", photoIds: ["P-03"] }, { systemId: "KITCHEN-B", componentId: "HOOD-01", status: "cleaned", photoIds: ["P-05", "P-06"] }, ]; const photos: readonly Photo[] = [ { id: "P-01", systemId: "KITCHEN-A", componentId: "HOOD-01", phase: "before" }, { id: "P-02", systemId: "KITCHEN-A", componentId: "HOOD-01", phase: "after" }, { id: "P-03", systemId: "KITCHEN-A", componentId: "DUCT-02", phase: "before" }, { id: "P-04", systemId: "KITCHEN-A", componentId: "ROOF-FAN-01", phase: "before" }, { id: "P-05", systemId: "KITCHEN-B", componentId: "HOOD-01", phase: "before" }, { id: "P-06", systemId: "KITCHEN-B", componentId: "HOOD-01", phase: "after" }, ]; const queue = auditScope(scope, photos); const expected = [ { systemId: "KITCHEN-A", componentId: "DUCT-02", reason: "MISSING_AFTER_PHOTO" }, { systemId: "KITCHEN-A", componentId: "ROOF-FAN-01", reason: "INACCESSIBLE" }, ]; assert.deepEqual(queue, expected); assert.deepEqual(auditScope(scope.toReversed(), photos.toReversed()), expected); assert(Object.isFrozen(queue) && queue.every((entry) => Object.isFrozen(entry))); assert.equal(Reflect.set(queue[0], "reason", "INACCESSIBLE"), false); assert.throws(() => auditScope([{ ...scope[1], photoIds: ["P-01", "P-06"] }], photos), /belongs to KITCHEN-B\/HOOD-01, expected KITCHEN-A\/HOOD-01/); assert.throws(() => auditScope([{ ...scope[1], photoIds: ["P-03"] }], photos), /belongs to KITCHEN-A\/DUCT-02, expected KITCHEN-A\/HOOD-01/); assert.throws(() => auditScope([{ ...scope[1], photoIds: ["P-99"] }], photos), /Unknown photo ID/); assert.throws(() => auditScope(scope, [...photos, photos[0]]), /Duplicate photo ID/); assert.deepEqual(auditScope([{ ...scope[1], photoIds: ["P-02"] }], photos), [ { systemId: "KITCHEN-A", componentId: "HOOD-01", reason: "MISSING_BEFORE_PHOTO" }, ]); const newPhoto: Photo = { id: "P-07", systemId: "KITCHEN-A", componentId: "DUCT-02", phase: "after" }; const updatedScope = scope.map((row) => row.systemId === newPhoto.systemId && row.componentId === newPhoto.componentId ? { ...row, photoIds: [...row.photoIds, newPhoto.id] } : row); const nextQueue = auditScope(updatedScope, [...photos, newPhoto]); assert.deepEqual(nextQueue, [expected[1]]); assert.deepEqual(queue, expected); console.log(`Audited components: ${scope.length} | indexed photos: ${photos.length}`); for (const { systemId, componentId, reason } of queue) { console.log(`${systemId}/${componentId}: ${reason}`); } console.log(`After attaching ${newPhoto.id}: ${nextQueue.length} follow-up | original queue: ${queue.length}`); 

Verified Node output

Audited components: 4 | indexed photos: 6 KITCHEN-A/DUCT-02: MISSING_AFTER_PHOTO KITCHEN-A/ROOF-FAN-01: INACCESSIBLE After attaching P-07: 1 follow-up | original queue: 2 

Keep the scope and photo index with each audit snapshot. That gives the reviewer the exact references behind a missing-evidence flag and preserves the access exception when the rest of the job is documented.

HoodCert kitchen exhaust reporting · B2B Ops and FinOps Benchmarks