@ashishjain15491/tapcheck 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +75 -0
  2. package/LICENSE +21 -0
  3. package/README.md +243 -2
  4. package/dist/auth.d.ts +5 -0
  5. package/dist/auth.js +100 -0
  6. package/dist/browser.d.ts +143 -0
  7. package/dist/browser.js +237 -0
  8. package/dist/cli.d.ts +2 -0
  9. package/dist/cli.js +321 -0
  10. package/dist/config.d.ts +169 -0
  11. package/dist/config.js +369 -0
  12. package/dist/coverage.d.ts +17 -0
  13. package/dist/coverage.js +56 -0
  14. package/dist/flow.d.ts +193 -0
  15. package/dist/flow.js +512 -0
  16. package/dist/jev.d.ts +48 -0
  17. package/dist/jev.js +89 -0
  18. package/dist/parts.d.ts +65 -0
  19. package/dist/parts.js +157 -0
  20. package/dist/questions.d.ts +66 -0
  21. package/dist/questions.js +203 -0
  22. package/dist/report.d.ts +29 -0
  23. package/dist/report.js +59 -0
  24. package/dist/routes.d.ts +18 -0
  25. package/dist/routes.js +54 -0
  26. package/dist/stub.d.ts +51 -0
  27. package/dist/stub.js +244 -0
  28. package/dist/suites/a11y.d.ts +3 -0
  29. package/dist/suites/a11y.js +73 -0
  30. package/dist/suites/audit.d.ts +2 -0
  31. package/dist/suites/audit.js +440 -0
  32. package/dist/suites/code.d.ts +10 -0
  33. package/dist/suites/code.js +48 -0
  34. package/dist/suites/contract.d.ts +5 -0
  35. package/dist/suites/contract.js +79 -0
  36. package/dist/suites/crawl.d.ts +2 -0
  37. package/dist/suites/crawl.js +135 -0
  38. package/dist/suites/interact.d.ts +2 -0
  39. package/dist/suites/interact.js +319 -0
  40. package/dist/suites/security.d.ts +12 -0
  41. package/dist/suites/security.js +134 -0
  42. package/dist/suites/usability.d.ts +3 -0
  43. package/dist/suites/usability.js +205 -0
  44. package/dist/suites/ux.d.ts +6 -0
  45. package/dist/suites/ux.js +183 -0
  46. package/package.json +61 -5
  47. package/schema/tapcheck.schema.json +368 -0
@@ -0,0 +1,205 @@
1
+ /*
2
+ * Usability testing with a simulated first-time user, plus clickstream analysis. For each task in tapcheck.yml Jev picks
3
+ * the next control from what is on screen (by label and place), as a person who has never seen the app would; code clicks
4
+ * it and records the clickstream: target, coordinates, time on step, URL change and dead clicks (nothing changed). Code
5
+ * then scores the task: reached or not, clicks against the shortest path, hesitations, dead clicks and errors. A
6
+ * clickstream map draws the clicks over each step's screen. Runs on the first desktop-sized viewport.
7
+ *
8
+ * Safety: tapcheck only navigates. Submit buttons, links matching crawl.skip and anything labelled delete, send, publish,
9
+ * pay or sign out are never offered as a choice; text is typed only into fields outside a POST form; and Jev is asked
10
+ * about the one control about to be clicked, which is left alone unless that answer is a clear "this changes nothing".
11
+ */
12
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
13
+ import { context, open, SessionExpired, settle, slug } from '../browser.js';
14
+ import { ask, bad, BudgetReached, good, img, NO } from '../jev.js';
15
+ import { MAX_STEPS, SCROLL, TASK_Q } from '../questions.js';
16
+ const S = 'usability';
17
+ export const UNSAFE = /\b(delete|remove|destroy|log ?out|sign out|send|publish|unpublish|pay|upgrade|downgrade|cancel|archive|disconnect|revoke|unsubscribe|reset|discard|take down|impersonat)/i;
18
+ // ponytail: fixed bands, enough to tell two same-labelled controls apart; read the page's landmarks if this misnames them.
19
+ const place = (c) => (c.y < 72 ? 'at the top of the screen' : c.x < 260 ? 'on the left side' : 'in the main area');
20
+ /**
21
+ * Visible, safe controls in the first screen, keyed by label and place so two "Create" buttons stay two options.
22
+ * A text field is offered as "type the task's text into it" (and not at all when the task has nothing to type: focusing
23
+ * a field alone goes nowhere). `tried` holds controls already used on this screen with no effect, so they are not
24
+ * offered again.
25
+ */
26
+ async function options(r, page, vh, text, tried) {
27
+ const visible = [];
28
+ for (const h of await page.$$('a[href], button, [role=button], input:not([type=hidden]), select, textarea, summary'))
29
+ if (await h.isVisible())
30
+ visible.push(h);
31
+ const controls = await Promise.all(visible.map((h) => h.evaluate((el) => {
32
+ const r = el.getBoundingClientRect();
33
+ const label = (el.innerText || el.getAttribute('aria-label') || el.getAttribute('title') || el.placeholder || '').replace(/\s+/g, ' ').trim().slice(0, 60);
34
+ const form = el.form; // also set for a control tied to a form by its form= attribute
35
+ // A form's submit button (an untyped button of a form submits too) would save something, so it is never offered.
36
+ const submit = el.matches('button[type=submit], input[type=submit], input[type=image]') || (el.matches('button:not([type])') && !!form);
37
+ const field = el.matches('textarea, input:not([type]), input[type=text], input[type=search], input[type=email]');
38
+ return { tag: el.tagName.toLowerCase(), label, x: Math.round(r.left), y: Math.round(r.top), w: Math.round(r.width), h: Math.round(r.height), submit, hidden: !!el.closest('[aria-hidden=true]'), field, reads: !form || form.method === 'get',
39
+ path: el instanceof HTMLAnchorElement ? el.pathname : '' };
40
+ })));
41
+ const opts = {};
42
+ const at = {};
43
+ for (const [i, c] of controls.entries()) {
44
+ if (!c.label || c.hidden || c.submit || c.y < 0 || c.y > vh || UNSAFE.test(c.label) || (c.path && r.cfg.crawl.skip.test(c.path)))
45
+ continue;
46
+ // Enter in a field submits its form, so text is typed only outside a form or in one that reads (GET, as a search does).
47
+ if (c.field && (!text || !c.reads))
48
+ continue;
49
+ const k = slug(`${c.field ? 'type into ' : ''}${c.label} ${place(c)}`);
50
+ if (opts[k] || tried.has(`${page.url()}|${k}`))
51
+ continue;
52
+ opts[k] = c.field
53
+ ? `Type "${text}" into the field labelled "${c.label}", ${place(c)}, and press Enter.`
54
+ : `The ${c.tag === 'a' ? 'link' : c.tag === 'summary' ? 'expandable section' : c.tag} labelled "${c.label}", ${place(c)}.`;
55
+ at[k] = { i, c: { ...c, typing: c.field } };
56
+ }
57
+ return { opts, at, visible };
58
+ }
59
+ /** The clicks drawn over each step's screen: a numbered dot per click, red when nothing happened. */
60
+ async function clickMap(page, all, out) {
61
+ const clicks = all.filter((c) => c.place); // scrolls have no spot to mark
62
+ if (!clicks.length)
63
+ return;
64
+ const { width, height } = page.viewportSize();
65
+ const p = await page.context().newPage();
66
+ await p.setViewportSize({ width, height });
67
+ const panes = clicks.map((c) => `<div style="position:relative;width:${width}px;height:${height}px;background:url(data:image/png;base64,${readFileSync(c.shot).toString('base64')}) 0 0/100% 100%">`
68
+ + `<div style="position:absolute;left:${c.x - 14}px;top:${c.y - 14}px;width:28px;height:28px;border-radius:50%;background:${c.dead ? '#dc2626' : '#2563eb'};`
69
+ + `color:#fff;font:bold 14px system-ui;display:grid;place-items:center;box-shadow:0 0 0 6px ${c.dead ? '#dc262655' : '#2563eb55'}">${c.step}</div>`
70
+ + `<div style="position:absolute;left:8px;top:8px;background:#111c;color:#fff;font:13px system-ui;padding:4px 8px;border-radius:4px">${c.step}. ${c.label} · ${c.ms} ms${c.dead ? ' · dead click' : ''}</div></div>`).join('');
71
+ await p.setContent(`<body style="margin:0">${panes}</body>`);
72
+ await p.screenshot({ path: out, fullPage: true });
73
+ await p.close();
74
+ }
75
+ async function attempt(r, page, t, vh) {
76
+ await open(r, page, t.from);
77
+ const clicks = [];
78
+ const tried = new Set(); // url|option that changed nothing: not offered again on that screen
79
+ let reached = false, note = '', errorShown = false;
80
+ for (let step = 1; step <= MAX_STEPS + 1; step++) {
81
+ const shot = `${r.dir}/shots/task-${slug(t.name)}-${step}.png`;
82
+ await page.screenshot({ path: shot });
83
+ const { opts, at, visible } = await options(r, page, vh, t.text, tried);
84
+ // Scrolling is an option while there is more page below, at most twice per screen (a third look is a lost user).
85
+ const scrolled = clicks.filter((c) => !c.place && c.from === page.url()).length;
86
+ if (scrolled < 2 && await page.evaluate(() => scrollY + innerHeight < document.documentElement.scrollHeight - 40))
87
+ opts[SCROLL] = 'Scroll down to see more of the page.';
88
+ // The last look only asks whether the goal is reached: after the last allowed click, or with nothing safe to click.
89
+ const out = step === MAX_STEPS + 1, last = out || !Object.keys(opts).length;
90
+ const q = { arrived: TASK_Q.arrived(t), error: TASK_Q.error };
91
+ if (!last)
92
+ Object.assign(q, { can_progress: TASK_Q.can_progress, hesitation: TASK_Q.hesitation, pick: TASK_Q.pick(opts) });
93
+ const a = await ask(`task-${slug(t.name)}-${step}`, { goal: t.goal, already_clicked: clicks.map((c) => c.label), screenshot: img(shot), controls: Object.values(opts) }, q, [shot]);
94
+ errorShown ||= bad(a.error.noul) === 'FAIL';
95
+ if (step > 1 && good(a.arrived.noul) === 'pass') {
96
+ reached = true;
97
+ break;
98
+ }
99
+ if (last) {
100
+ note = `${out ? `not reached after ${MAX_STEPS} clicks` : 'no safe control to click'} (p=${a.arrived.noul.toFixed(2)})`;
101
+ break;
102
+ }
103
+ if (good(a.can_progress.noul) === 'FAIL') {
104
+ note = `stuck: nothing on screen leads toward the goal (step ${step})`;
105
+ break;
106
+ }
107
+ if (a.pick.choice === SCROLL) {
108
+ await page.mouse.wheel(0, vh * 0.8);
109
+ await settle(page);
110
+ clicks.push({ step, label: '(scrolled down)', place: '', x: 0, y: 0, from: page.url(), to: page.url(), ms: 0, dead: false, hesitation: a.hesitation.noul, shot, requests: [] });
111
+ continue;
112
+ }
113
+ const pick = at[a.pick.choice];
114
+ if (!pick || !visible[pick.i]) {
115
+ note = 'the chosen control was not found';
116
+ break;
117
+ }
118
+ // Guard: Jev judges the one control about to be clicked; above the "no" line it is not clicked and the task stops.
119
+ const g = await ask(`task-${slug(t.name)}-${step}-guard`, { screenshot: img(shot), control: opts[a.pick.choice] }, { irreversible: TASK_Q.irreversible }, [shot]);
120
+ if (g.irreversible.noul > NO) {
121
+ note = `stopped before "${pick.c.label}": it may change data (p=${g.irreversible.noul.toFixed(2)})`;
122
+ break;
123
+ }
124
+ const from = page.url();
125
+ const before = await page.evaluate(() => document.body.innerHTML.length);
126
+ const requests = [];
127
+ const onResponse = (res) => { if (['xhr', 'fetch', 'document'].includes(res.request().resourceType()))
128
+ requests.push({ method: res.request().method(), url: res.url(), status: res.status() }); };
129
+ page.on('response', onResponse);
130
+ const t0 = Date.now();
131
+ try {
132
+ if (pick.c.typing) {
133
+ await visible[pick.i].fill(t.text, { timeout: 5000 });
134
+ await visible[pick.i].press('Enter');
135
+ } // a search shows suggestions or submits
136
+ else
137
+ await visible[pick.i].click({ timeout: 5000 });
138
+ }
139
+ catch (e) {
140
+ page.off('response', onResponse);
141
+ note = `${pick.c.typing ? 'typing' : 'click'} failed: ${e.message.slice(0, 80)}`;
142
+ break;
143
+ }
144
+ await settle(page);
145
+ page.off('response', onResponse);
146
+ const after = await page.evaluate(() => document.body.innerHTML.length);
147
+ const to = page.url();
148
+ const c = pick.c;
149
+ const dead = to === from && Math.abs(after - before) < 20 && !requests.length;
150
+ if (dead || c.typing)
151
+ tried.add(`${from}|${a.pick.choice}`);
152
+ clicks.push({ step, label: c.typing ? `typed "${t.text}" into ${c.label}` : c.label, place: place(c), x: Math.round(c.x + c.w / 2), y: Math.round(c.y + c.h / 2), from, to,
153
+ // Focusing a field changes nothing on screen by design, so only buttons and links can be dead clicks.
154
+ ms: Date.now() - t0, dead: !c.typing && !['input', 'select', 'textarea'].includes(c.tag) && dead,
155
+ hesitation: a.hesitation.noul, shot, requests });
156
+ }
157
+ return { reached, note, clicks, errorShown };
158
+ }
159
+ export async function run(r) {
160
+ if (!r.side.tasks.length) {
161
+ r.record({ suite: S, where: 'tasks', check: 'tasks configured', status: 'info', detail: 'none: add tasks to tapcheck.yml to test them' });
162
+ return;
163
+ }
164
+ mkdirSync(`${r.dir}/shots`, { recursive: true });
165
+ const vp = r.cfg.viewports.find((v) => !v.mobile) ?? r.cfg.viewports[0];
166
+ const ctx = await context(r, vp);
167
+ const page = await ctx.newPage();
168
+ const stream = [];
169
+ try {
170
+ for (const t of r.side.tasks) {
171
+ const where = `${t.name}: ${t.goal}`;
172
+ try {
173
+ const a = await attempt(r, page, t, vp.height);
174
+ const map = `${r.dir}/shots/clickstream-${slug(t.name)}.png`;
175
+ await clickMap(page, a.clicks, map);
176
+ const ev = a.clicks.some((c) => c.place) ? [map] : [];
177
+ r.record({ suite: S, where, check: 'task completed', status: a.reached ? 'pass' : 'fail',
178
+ detail: [a.note, `${a.clicks.length} click(s): ${a.clicks.map((c) => c.label).join(' → ')}`].filter(Boolean).join(' · '), evidence: ev });
179
+ if (a.reached) {
180
+ const extra = a.clicks.length - t.optimal;
181
+ r.record({ suite: S, where, check: 'path efficiency', status: extra <= 0 ? 'pass' : extra === 1 ? 'warn' : 'fail', detail: `${a.clicks.length} clicks, shortest path ${t.optimal}`, evidence: ev });
182
+ }
183
+ const hes = a.clicks.filter((c) => c.hesitation > 0.5);
184
+ r.record({ suite: S, where, check: 'no hesitation', status: hes.length ? 'warn' : 'pass', detail: hes.map((c) => `step ${c.step} (p=${c.hesitation.toFixed(2)})`).join(', ') || undefined, evidence: ev });
185
+ const dead = a.clicks.filter((c) => c.dead);
186
+ r.record({ suite: S, where, check: 'no dead clicks', status: dead.length ? 'fail' : 'pass', detail: dead.map((c) => `"${c.label}"`).join(', ') || undefined, evidence: ev });
187
+ r.record({ suite: S, where, check: 'no error on the way', status: a.errorShown ? 'fail' : 'pass' });
188
+ // Request correlation: which click set off a failing request.
189
+ const failed = a.clicks.flatMap((c) => c.requests.filter((q) => q.status >= 400).map((q) => `"${c.label}" → ${q.status} ${q.method} ${new URL(q.url).pathname}`));
190
+ r.record({ suite: S, where, check: 'clicks set off no failing requests', status: failed.length ? 'fail' : 'pass',
191
+ detail: failed.slice(0, 5).join('; ') || `${a.clicks.reduce((n, c) => n + c.requests.length, 0)} request(s) across ${a.clicks.length} click(s)`, evidence: ev });
192
+ stream.push({ task: t.name, goal: t.goal, reached: a.reached, note: a.note, clicks: a.clicks });
193
+ }
194
+ catch (e) {
195
+ if (e instanceof BudgetReached || e instanceof SessionExpired)
196
+ throw e;
197
+ r.record({ suite: S, where, check: 'task ran', status: 'fail', detail: e.message.slice(0, 200) });
198
+ }
199
+ }
200
+ }
201
+ finally {
202
+ writeFileSync(`${r.dir}/clickstream.json`, JSON.stringify(stream, null, 2));
203
+ await ctx.close();
204
+ }
205
+ }
@@ -0,0 +1,6 @@
1
+ import { type Run } from '../browser.ts';
2
+ /** One finding per VISUAL question in `a` (the audit suite asks them too, of screens and of opened dialogs and menus). */
3
+ export declare function visual(r: Run, suite: string, where: string, a: Record<string, {
4
+ noul: number;
5
+ }>, shots: string[]): void;
6
+ export declare function run(r: Run): Promise<void>;
@@ -0,0 +1,183 @@
1
+ /*
2
+ * Deep UI/UX audit, per screen and viewport:
3
+ * - visual QA (loaded, errors, overlap, clipping, alignment) and measured facts (status, sideways scroll, broken images,
4
+ * off-screen and under-24px controls, a single h1, JS errors);
5
+ * - visual design: CTA clarity and label, negative space (Jev's judgment plus measured text coverage), density, hierarchy,
6
+ * legibility, spacing rhythm;
7
+ * - heuristic evaluation: the usability heuristics a screenshot can show;
8
+ * - guerrilla five-second test on the first screen: does a passer-by get the screen's job, and pick it among the others;
9
+ * - predicted attention (desktop): the first three places the eye goes and the main CTA as Jev boxes, drawn as a heatmap,
10
+ * with code checking that the CTA is among the first three looks. These are predictions, not eye-tracking data;
11
+ * - raw translation keys, measured: visible text that is exactly one of the keys the i18n.keys command prints, or an
12
+ * unfilled :placeholder.
13
+ * Jev judges, code decides: an unsure answer is a warning for a person to look at, never a pass.
14
+ */
15
+ import { execSync } from 'node:child_process';
16
+ import { readFileSync } from 'node:fs';
17
+ import { abs, context, facts, open, resolve, SessionExpired, slices, slug, watch } from '../browser.js';
18
+ import { ask, bad, BudgetReached, good, img, MIN_SCORE, status, to10 } from '../jev.js';
19
+ import { ATTENTION, ATTENTION_CHECK, ATTENTION_MODEL, DESIGN, guerrilla, HEURISTICS, purposeKey, VISUAL } from '../questions.js';
20
+ const S = 'ux';
21
+ // Negative space by measurement: text covering more than this share of the first screen reads as crowded.
22
+ const MAX_TEXT_COVERAGE = 0.32;
23
+ // A low score Jev was split on is a question for a person, not a defect: it is marked "needs review" (a warning).
24
+ const REVIEW_BELOW = 0.3;
25
+ function scored(r, where, check, a, ev) {
26
+ const v = to10(a.score);
27
+ const review = v < MIN_SCORE && a.confidence < REVIEW_BELOW;
28
+ r.record({ suite: S, where, check, status: v >= MIN_SCORE ? 'pass' : review ? 'warn' : 'fail',
29
+ detail: `${v}/10 (confidence ${a.confidence.toFixed(2)})${review ? ' · needs review: Jev was split' : ''}`, evidence: ev });
30
+ }
31
+ /**
32
+ * The app's translation keys, from the i18n.keys command (one per line). Only dotted identifiers count as keys.
33
+ * ponytail: catalogues keyed by the English sentence itself can't be told from real text, so they are ignored here.
34
+ */
35
+ function translationKeys(r) {
36
+ if (!r.cfg.i18n.keys)
37
+ return new Set();
38
+ const out = execSync(r.cfg.i18n.keys, { encoding: 'utf8', shell: '/bin/sh', maxBuffer: 64 * 1024 * 1024 });
39
+ return new Set(out.split('\n').map((k) => k.trim()).filter((k) => /^[\w-]+(\.[\w-]+)+$/.test(k)));
40
+ }
41
+ /** Two boxes are the same element when they share more than half of the smaller one. */
42
+ function same(a, b) {
43
+ const w = Math.max(0, Math.min(a.right, b.right) - Math.max(a.left, b.left)), h = Math.max(0, Math.min(a.bottom, b.bottom) - Math.max(a.top, b.top));
44
+ const area = (x) => (x.right - x.left) * (x.bottom - x.top);
45
+ return (w * h) / Math.max(1e-6, Math.min(area(a), area(b))) > 0.5;
46
+ }
47
+ /** The screenshot with the predicted looks as a heat overlay and numbered boxes, rendered by the browser itself. */
48
+ async function heatmap(page, shot, looks, out) {
49
+ const { width, height } = page.viewportSize();
50
+ const src = `data:image/png;base64,${readFileSync(shot).toString('base64')}`;
51
+ const blobs = looks.map((l) => {
52
+ const cx = ((l.box.left + l.box.right) / 2) * 100, cy = ((l.box.top + l.box.bottom) / 2) * 100;
53
+ const r = Math.max(8, ((l.box.right - l.box.left + l.box.bottom - l.box.top) / 2) * 100);
54
+ return `radial-gradient(circle at ${cx}% ${cy}%, rgba(255,0,0,${0.55 * l.weight}) 0, rgba(255,140,0,${0.3 * l.weight}) ${r * 0.6}%, transparent ${r}%)`;
55
+ }).join(',');
56
+ const frames = looks.map((l, i) => `<div style="position:absolute;left:${l.box.left * 100}%;top:${l.box.top * 100}%;width:${(l.box.right - l.box.left) * 100}%;`
57
+ + `height:${(l.box.bottom - l.box.top) * 100}%;border:2px solid ${l.colour};border-radius:4px"><b style="position:absolute;top:-22px;left:-2px;`
58
+ + `background:${l.colour};color:#fff;font:12px system-ui;padding:2px 6px;border-radius:4px;white-space:nowrap">${i + 1}. ${l.label}</b></div>`).join('');
59
+ const p = await page.context().newPage();
60
+ await p.setViewportSize({ width, height });
61
+ await p.setContent(`<body style="margin:0"><div style="position:relative;width:${width}px;height:${height}px;background:url(${src}) 0 0/100% 100%">`
62
+ + `<div style="position:absolute;inset:0;background:${blobs};mix-blend-mode:multiply"></div>${frames}</div></body>`);
63
+ await p.screenshot({ path: out });
64
+ await p.close();
65
+ }
66
+ /** One finding per VISUAL question in `a` (the audit suite asks them too, of screens and of opened dialogs and menus). */
67
+ export function visual(r, suite, where, a, shots) {
68
+ for (const [k, defect] of [['loaded', false], ['error_shown', true], ['overlap', true], ['clipped', true], ['raw_key', true], ['misaligned', true]]) {
69
+ if (!a[k])
70
+ continue;
71
+ const v = defect ? bad(a[k].noul) : good(a[k].noul);
72
+ r.record({ suite, where, check: `visual: ${k.replace('_', ' ')}`, status: status(v), detail: `p=${a[k].noul.toFixed(2)}`, evidence: shots });
73
+ }
74
+ }
75
+ export async function run(r) {
76
+ const screens = r.side.screens.length ? r.side.screens : [{ name: 'Home', path: '/' }];
77
+ const known = translationKeys(r);
78
+ for (const vp of r.cfg.viewports) {
79
+ const ctx = await context(r, vp);
80
+ const page = await ctx.newPage();
81
+ const errors = watch(page);
82
+ try {
83
+ for (const s of screens) {
84
+ const where = `${s.name} · ${vp.name}`;
85
+ try {
86
+ const path = await resolve(r, page, s);
87
+ if (!path) {
88
+ r.record({ suite: S, where, check: 'screen reachable', status: 'warn', detail: 'no link to it found' });
89
+ continue;
90
+ }
91
+ errors.length = 0;
92
+ const res = await open(r, page, path);
93
+ const f = await facts(page);
94
+ const key = `ux-${slug(s.name)}-${vp.name}`;
95
+ const shots = await slices(r, page, key, f.height, vp.height);
96
+ // Measured, not asked.
97
+ const http = res?.status() ?? 0;
98
+ r.record({ suite: S, where, check: 'HTTP status', status: http && http < 400 ? 'pass' : 'fail', detail: `${http} ${abs(r, path)}` });
99
+ r.record({ suite: S, where, check: 'no sideways scroll', status: f.overflowX ? 'fail' : 'pass' });
100
+ r.record({ suite: S, where, check: 'images load', status: f.brokenImages.length ? 'fail' : 'pass', detail: f.brokenImages.slice(0, 5).join(', ') || undefined });
101
+ r.record({ suite: S, where, check: 'controls on screen', status: f.offscreen ? 'fail' : 'pass', detail: f.offscreen ? `${f.offscreen} off-screen` : undefined });
102
+ r.record({ suite: S, where, check: 'target size ≥ 24px', status: f.smallTargets.length ? 'warn' : 'pass', detail: f.smallTargets.slice(0, 6).join('; ') || undefined });
103
+ r.record({ suite: S, where, check: 'one h1', status: f.h1 === 1 ? 'pass' : 'warn', detail: `${f.h1} h1 element(s)` });
104
+ r.record({ suite: S, where, check: 'no JS errors', status: errors.length ? 'fail' : 'pass', detail: errors.slice(0, 3).join(' | ') || undefined });
105
+ r.record({ suite: S, where, check: 'negative space (measured)', status: f.textCoverage > MAX_TEXT_COVERAGE ? 'warn' : 'pass',
106
+ detail: `text covers ${(f.textCoverage * 100).toFixed(1)}% of the first screen (limit ${MAX_TEXT_COVERAGE * 100}%)`, evidence: [shots[0]] });
107
+ const texts = await page.evaluate(() => {
108
+ const out = [];
109
+ const w = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
110
+ for (let n = w.nextNode(); n; n = w.nextNode()) {
111
+ const t = n.textContent?.trim();
112
+ const el = n.parentElement;
113
+ if (t && el && el.offsetParent !== null && !el.closest('script,style,code,pre,[aria-hidden=true]'))
114
+ out.push(t);
115
+ }
116
+ for (const el of document.querySelectorAll('[placeholder],[aria-label],[title]'))
117
+ for (const a of ['placeholder', 'aria-label', 'title']) {
118
+ const v = el.getAttribute(a);
119
+ if (v)
120
+ out.push(v.trim());
121
+ }
122
+ return out;
123
+ });
124
+ const raw = [...new Set(texts.filter((t) => known.has(t) || /(^|\s):[a-z_]{2,}\b/.test(t)))];
125
+ r.record({ suite: S, where, check: 'no raw translation keys (measured)', status: raw.length ? 'fail' : 'pass', detail: raw.slice(0, 6).join(', ') || undefined, evidence: raw.length ? [shots[0]] : undefined });
126
+ // One request for every judgment over the same screenshots.
127
+ const a = await ask(key, { screen: s.name, viewport: `${vp.name}, ${vp.width} × ${vp.height} px`, screenshots: shots.map(img),
128
+ note: shots.length > 1 ? 'The screenshots are consecutive slices of one screen, top to bottom.' : undefined }, { ...VISUAL, ...DESIGN, ...HEURISTICS(r.cfg.audience) }, shots);
129
+ visual(r, S, where, a, shots);
130
+ for (const k of ['cta', 'cta_label', 'negative_space', 'hierarchy', 'legibility', 'spacing'])
131
+ scored(r, where, `design: ${k.replace('_', ' ')}`, a[k], shots);
132
+ const probs = Object.entries(a.density.probabilities ?? {}).map(([k, p]) => `${k} ${p.toFixed(2)}`).join(', ');
133
+ r.record({ suite: S, where, check: 'design: density', status: a.density.choice === 'balanced' ? 'pass' : 'warn', detail: `${a.density.choice} (${probs})`, evidence: [shots[0]] });
134
+ for (const k of ['h1_status', 'h2_language', 'h4_consistency', 'h6_recognition', 'h8_minimalist'])
135
+ scored(r, where, `heuristic: ${k}`, a[k], shots);
136
+ r.record({ suite: S, where, check: 'heuristic: h10_help', status: status(good(a.h10_help.noul)), detail: `p=${a.h10_help.noul.toFixed(2)}`, evidence: shots });
137
+ // Guerrilla five-second test, on the first screen only. It needs the screen's purpose; picking the job
138
+ // among the others needs at least one other screen with a purpose.
139
+ if (s.purpose) {
140
+ const others = [...new Set(screens.filter((x) => x.name !== s.name && x.purpose && x.purpose !== s.purpose).map((x) => x.purpose))].slice(0, 6);
141
+ const { purpose_pick, ...rest } = guerrilla(s.purpose, others);
142
+ const g = await ask(`${key}-guerrilla`, { screenshot: img(shots[0]) }, others.length ? { ...rest, purpose_pick } : rest, [shots[0]]);
143
+ r.record({ suite: S, where, check: 'guerrilla: purpose clear in 5s', status: status(good(g.purpose_clear.noul)), detail: `p=${g.purpose_clear.noul.toFixed(2)}`, evidence: [shots[0]] });
144
+ if (others.length) {
145
+ const picked = g.purpose_pick.choice === purposeKey(s.purpose);
146
+ r.record({ suite: S, where, check: 'guerrilla: right job picked', status: picked ? 'pass' : 'fail', detail: picked ? undefined : `read as "${g.purpose_pick.choice}"`, evidence: [shots[0]] });
147
+ }
148
+ scored(r, where, 'guerrilla: trust', g.trust, [shots[0]]);
149
+ }
150
+ else {
151
+ r.record({ suite: S, where, check: 'guerrilla five-second test', status: 'info', detail: 'skipped: give the screen a purpose in tapcheck.yml to run it' });
152
+ }
153
+ // Predicted attention, desktop only.
154
+ if (!vp.mobile) {
155
+ const c = await ask(`${key}-cta-check`, { screenshot: img(shots[0]) }, ATTENTION_CHECK, [shots[0]]);
156
+ const at = await ask(`${key}-attention`, img(shots[0]), ATTENTION, [shots[0]], ATTENTION_MODEL);
157
+ const hasCta = good(c.has_cta.noul);
158
+ const looks = [
159
+ { label: 'first look', box: at.look_1.box, weight: 1, colour: '#dc2626' },
160
+ { label: 'second look', box: at.look_2.box, weight: 0.75, colour: '#ea580c' },
161
+ { label: 'third look', box: at.look_3.box, weight: 0.5, colour: '#ca8a04' },
162
+ ...(hasCta === 'pass' ? [{ label: 'main CTA', box: at.main_cta.box, weight: 0.4, colour: '#2563eb' }] : []),
163
+ ];
164
+ const map = `${r.dir}/shots/${key}-heatmap.png`;
165
+ await heatmap(page, shots[0], looks, map);
166
+ const seen = hasCta === 'pass' && looks.slice(0, 3).some((l) => same(l.box, at.main_cta.box));
167
+ r.record({ suite: S, where, check: 'attention: main CTA among first three looks', status: hasCta !== 'pass' ? 'warn' : seen ? 'pass' : 'fail',
168
+ detail: hasCta !== 'pass' ? `no clear main CTA on the first screen (p=${c.has_cta.noul.toFixed(2)})` : seen ? undefined : 'the eye is predicted to land elsewhere first',
169
+ evidence: [map] });
170
+ }
171
+ }
172
+ catch (e) {
173
+ if (e instanceof BudgetReached || e instanceof SessionExpired)
174
+ throw e;
175
+ r.record({ suite: S, where, check: 'audit ran', status: 'fail', detail: e.message.slice(0, 200) });
176
+ }
177
+ }
178
+ }
179
+ finally {
180
+ await ctx.close();
181
+ }
182
+ }
183
+ }
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
- "name": "@ashishjain15491/tapcheck",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@ashishjain15491/tapcheck",
3
+ "version": "0.1.0",
4
+ "description": "End-to-end and UI audit harness for any web app, whatever its stack: crawl, API contract, security, accessibility, and Jev judgments of what people see.",
5
+ "license": "MIT",
6
+ "author": "ashishjain15491 (https://github.com/ashishjain15491)",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/ashishjain15491/tapcheck.git"
10
+ },
11
+ "homepage": "https://github.com/ashishjain15491/tapcheck",
12
+ "type": "module",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/flow.d.ts",
16
+ "default": "./dist/flow.js"
17
+ }
18
+ },
19
+ "types": "dist/flow.d.ts",
20
+ "bin": {
21
+ "tapcheck": "dist/cli.js"
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "schema",
26
+ "README.md",
27
+ "LICENSE",
28
+ "CHANGELOG.md"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "engines": {
34
+ "node": ">=22.18.0"
35
+ },
36
+ "scripts": {
37
+ "build": "rm -rf dist && tsc -p tsconfig.build.json && chmod +x dist/cli.js",
38
+ "typecheck": "tsc -p tsconfig.json",
39
+ "test": "node --test test/*.test.ts",
40
+ "prepack": "npm run build",
41
+ "check-public": "scripts/check-public.sh"
42
+ },
43
+ "dependencies": {
44
+ "@typesafe-ai/sdk": "0.7.0",
45
+ "axe-core": "4.14.1",
46
+ "playwright": "1.65.1",
47
+ "yaml": "2.9.1"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "22.20.5",
51
+ "typescript": "7.0.2"
52
+ },
53
+ "keywords": [
54
+ "e2e",
55
+ "testing",
56
+ "accessibility",
57
+ "ui-audit",
58
+ "playwright",
59
+ "security",
60
+ "crawl"
61
+ ]
62
+ }