From 29f44440cabca4ddf71eccf52ee74352e369f98e Mon Sep 17 00:00:00 2001 From: Eric Bell Date: Tue, 24 Nov 2026 12:24:35 -0500 Subject: [PATCH] Add ifStuck/stop to frames and captured date to sequences (Refs #23) Co-Authored-By: Claude Sonnet 5.5 --- src/model.js | 8 +++++++- src/ops.js | 10 +++++++++- src/print.js | 6 ++++-- src/version.js | 2 +- test/model.test.js | 8 +++++++- test/ops.test.js | 17 +++++++++++++++++ 6 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/model.js b/src/model.js index a903366..5b66444 100644 --- a/src/model.js +++ b/src/model.js @@ -29,7 +29,10 @@ import { isImageDataUrl, MAX_IMAGE_DATA_CHARS } from './images.js'; // Item: { id, text, status: 'open'|'done'|'tbd', detail?: string } // Sequence (visual sequence): { id, kind: 'sequence', title, updated: 'YYYY-MM-DD', // frames: [Frame] } -- a numbered series of pictures with optional text. -// Frame: { image: PNG/JPEG data URL or '', text, layout: 'right'|'under'|'none', secret?: boolean } +// Frame: { image: PNG/JPEG data URL or '', text, layout: 'right'|'under'|'none', secret?: boolean, +// ifStuck?: string, what to do if the screen looks different or the step fails +// stop?: boolean } "stop here and call someone" marker; ifStuck says who/why +// A sequence may also carry `captured: 'YYYY-MM-DD'`, set when a step is captured from the screen. // A sequence lives in the same ordered list as the records (records sections) or // items (steps / checklist sections), so it sits wherever the user puts it, but it // is not a record or an item (no number, no tick box). A 'text' section keeps its @@ -184,6 +187,7 @@ export function validate(doc) { if (q.kind !== 'sequence') errs.push(`${where}: kind must be "sequence"`); if (!isStr(q.title) || !q.title) errs.push(`${where}: missing title`); if (!DATE_RE.test(q.updated ?? '')) errs.push(`${where}: updated must be YYYY-MM-DD`); + if (q.captured !== undefined && !DATE_RE.test(q.captured)) errs.push(`${where}: captured must be YYYY-MM-DD`); if (!Array.isArray(q.frames)) return errs.push(`${where}: frames must be an array`); q.frames.forEach((f, k) => { const fw = `${where}.frames[${k}]`; @@ -193,6 +197,8 @@ export function validate(doc) { if (!isStr(f.text)) errs.push(`${fw}: text must be a string`); if (!FRAME_LAYOUTS.includes(f.layout)) errs.push(`${fw}: bad layout "${f.layout}"`); if (f.secret !== undefined && typeof f.secret !== 'boolean') errs.push(`${fw}: secret must be a boolean`); + if (f.ifStuck !== undefined && !isStr(f.ifStuck)) errs.push(`${fw}: ifStuck must be a string`); + if (f.stop !== undefined && typeof f.stop !== 'boolean') errs.push(`${fw}: stop must be a boolean`); }); } diff --git a/src/ops.js b/src/ops.js index 5f453fd..a5b8a66 100644 --- a/src/ops.js +++ b/src/ops.js @@ -184,7 +184,7 @@ export function allSequences(doc) { // and the secret flags stay). Returns how many values were erased. export function clearSecrets(doc) { let n = 0; - const frames = (q) => { for (const f of q.frames) if (f.secret && (f.image || String(f.text || '').trim())) { f.image = ''; f.text = ''; n++; } }; + const frames = (q) => { for (const f of q.frames) if (f.secret && (f.image || String(f.text || '').trim() || String(f.ifStuck || '').trim())) { f.image = ''; f.text = ''; if (f.ifStuck) f.ifStuck = ''; n++; } }; for (const s of doc.sections) { for (const r of s.records || []) { if (isSequence(r)) frames(r); @@ -217,6 +217,14 @@ export function addFrame(seq, image = '', layout = 'under') { return f; } +// A step captured from the screen: a new frame, and the sequence remembers when, +// so the reader can be told the site may have changed since. +export function addCapture(seq, image) { + const f = addFrame(seq, image); + seq.captured = today(); + return f; +} + // ---- what a section holds (for the delete confirmation) ---- export function sectionContents(section) { const c = { records: 0, items: 0, sequences: 0, images: 0, text: false }; diff --git a/src/print.js b/src/print.js index 78fde8b..9b805f9 100644 --- a/src/print.js +++ b/src/print.js @@ -46,19 +46,21 @@ export function frameLayout(frame) { // What to show for a frame. A secret frame (picture and text) is withheld // unless secrets are included; a frame with nothing in it is never "withheld". export function frameView(frame, includeSecrets) { - const hasContent = !!(frame.image || String(frame.text || '').trim()); + const hasContent = !!(frame.image || String(frame.text || '').trim() || String(frame.ifStuck || '').trim()); const withheld = !!frame.secret && !includeSecrets && hasContent; return { withheld, image: withheld ? '' : frame.image, text: withheld ? '' : frame.text, + ifStuck: withheld ? '' : String(frame.ifStuck || '').trim(), + stop: withheld ? false : !!frame.stop, layout: withheld ? 'none' : frameLayout(frame), }; } export function countSecrets(doc) { let n = 0; - const frames = (q) => { for (const f of q.frames) if (f.secret && (f.image || String(f.text || '').trim())) n++; }; + const frames = (q) => { for (const f of q.frames) if (f.secret && (f.image || String(f.text || '').trim() || String(f.ifStuck || '').trim())) n++; }; for (const s of doc.sections) { for (const r of s.records || []) { if (isSequence(r)) frames(r); diff --git a/src/version.js b/src/version.js index 4b2b537..17e9480 100644 --- a/src/version.js +++ b/src/version.js @@ -2,7 +2,7 @@ // YYMMDD is the date, X the iteration that day (A first, B second, ...). // Bump with `npm run bump` (see bump-version.js). build.js strips `export`. -export const APP_VERSION = '261123A'; +export const APP_VERSION = '261124A'; const VERSION_RE = /^(\d{6})([A-Z])$/; export const isVersion = (v) => typeof v === 'string' && VERSION_RE.test(v); diff --git a/test/model.test.js b/test/model.test.js index 053454d..93297e0 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -104,6 +104,9 @@ test('sequence validation: layout, image, text, secret, id, title', () => { bad((x) => { x.frames[0].image = 5; }, /image must be a string/); bad((x) => { x.frames[0].text = null; }, /text must be a string/); bad((x) => { x.frames[0].secret = 'yes'; }, /secret must be a boolean/); + bad((x) => { x.frames[0].ifStuck = 5; }, /ifStuck must be a string/); + bad((x) => { x.frames[0].stop = 'yes'; }, /stop must be a boolean/); + bad((x) => { x.captured = 'yesterday'; }, /captured must be YYYY-MM-DD/); bad((x) => { x.title = ''; }, /missing title/); bad((x) => { x.id = d.sections[0].records[0].id; }, /duplicate id/); bad((x) => { delete x.frames; }, /frames must be an array/); @@ -116,8 +119,11 @@ test('frameLayout hides empty text; frameView withholds secret frames only when assert.equal(frameLayout({ layout: 'right', text: 'x' }), 'right'); assert.equal(frameLayout({ layout: 'none', text: 'x' }), 'none'); const f = { image: PNG, text: 'pw is hunter2', layout: 'under', secret: true }; - assert.deepEqual(frameView(f, false), { withheld: true, image: '', text: '', layout: 'none' }); + assert.deepEqual(frameView(f, false), { withheld: true, image: '', text: '', ifStuck: '', stop: false, layout: 'none' }); assert.equal(frameView(f, true).text, 'pw is hunter2'); + const g = { image: PNG, text: '', layout: 'none', ifStuck: ' call 555-0100 ', stop: true }; + assert.deepEqual([frameView(g, false).ifStuck, frameView(g, false).stop], ['call 555-0100', true]); + assert.deepEqual([frameView({ ...g, secret: true }, false).ifStuck, frameView({ ...g, secret: true }, false).stop], ['', false]); assert.equal(frameView({ image: '', text: '', layout: 'under', secret: true }, false).withheld, false); }); diff --git a/test/ops.test.js b/test/ops.test.js index 848dabf..e853505 100644 --- a/test/ops.test.js +++ b/test/ops.test.js @@ -345,3 +345,20 @@ test('clearSecrets erases secret fields and frames, keeps the rest, returns the assert.deepEqual(validate(doc), []); assert.equal(clearSecrets(doc), 0); }); + +test('addCapture adds a frame and stamps the sequence captured date; clearSecrets clears ifStuck on secret steps', async () => { + const { addCapture, clearSecrets, addSequence } = await import('../src/ops.js'); + const doc = emptyDocument('x'); + const s = addSection(doc, 'records', 'Banking'); + const q = addSequence(doc, s); + assert.equal(q.captured, undefined); + const f = addCapture(q, ''); + assert.equal(q.frames.length, 1); + assert.equal(f.layout, 'under'); + assert.match(q.captured, /^\d{4}-\d{2}-\d{2}$/); + f.secret = true; f.ifStuck = 'call 555-0100'; f.stop = true; + assert.equal(clearSecrets(doc), 1); + assert.equal(f.ifStuck, ''); + assert.equal(f.stop, true); + assert.deepEqual(validate(doc), []); +});