screw-bugs 0.1.8 → 0.1.10

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 (107) hide show
  1. package/README.md +49 -34
  2. package/dist/browser-playwright/capture.js +1 -1
  3. package/dist/browser-playwright/launch.js +27 -10
  4. package/dist/browser-playwright/page.d.ts +48 -26
  5. package/dist/browser-playwright/page.js +86 -89
  6. package/dist/browser-playwright/recorder.d.ts +154 -0
  7. package/dist/browser-playwright/recorder.js +382 -0
  8. package/dist/build-info.json +3 -3
  9. package/dist/cli/app.js +6 -2
  10. package/dist/cli/commands.js +4 -3
  11. package/dist/cli/doctor.d.ts +17 -2
  12. package/dist/cli/doctor.js +62 -4
  13. package/dist/cli/mcp.js +2 -2
  14. package/dist/cli/report-server.d.ts +19 -10
  15. package/dist/cli/report-server.js +43 -18
  16. package/dist/cli/share.js +2 -2
  17. package/dist/cli/sign-in.d.ts +9 -3
  18. package/dist/cli/sign-in.js +12 -9
  19. package/dist/cli/tailnet.d.ts +57 -0
  20. package/dist/cli/tailnet.js +82 -0
  21. package/dist/core/index.d.ts +1 -14
  22. package/dist/core/index.js +3 -14
  23. package/dist/report/index.d.ts +1 -10
  24. package/dist/report/index.js +3 -10
  25. package/dist/schema/index.d.ts +1 -9
  26. package/dist/schema/index.js +3 -9
  27. package/package.json +14 -14
  28. package/dist/core/accounts.d.ts +0 -40
  29. package/dist/core/accounts.js +0 -95
  30. package/dist/core/css.d.ts +0 -95
  31. package/dist/core/css.js +0 -436
  32. package/dist/core/engine.d.ts +0 -75
  33. package/dist/core/engine.js +0 -554
  34. package/dist/core/errors.d.ts +0 -85
  35. package/dist/core/errors.js +0 -36
  36. package/dist/core/evidence.d.ts +0 -14
  37. package/dist/core/evidence.js +0 -131
  38. package/dist/core/labels.d.ts +0 -47
  39. package/dist/core/labels.js +0 -199
  40. package/dist/core/liveness.d.ts +0 -45
  41. package/dist/core/liveness.js +0 -66
  42. package/dist/core/marks.d.ts +0 -63
  43. package/dist/core/marks.js +0 -410
  44. package/dist/core/services.d.ts +0 -574
  45. package/dist/core/services.js +0 -25
  46. package/dist/core/share.d.ts +0 -68
  47. package/dist/core/share.js +0 -318
  48. package/dist/core/steps.d.ts +0 -106
  49. package/dist/core/steps.js +0 -722
  50. package/dist/core/uploads.d.ts +0 -49
  51. package/dist/core/uploads.js +0 -133
  52. package/dist/core/video.d.ts +0 -47
  53. package/dist/core/video.js +0 -233
  54. package/dist/core/viewport.d.ts +0 -28
  55. package/dist/core/viewport.js +0 -50
  56. package/dist/report/assets.d.ts +0 -34
  57. package/dist/report/assets.js +0 -105
  58. package/dist/report/bug.d.ts +0 -11
  59. package/dist/report/bug.js +0 -20
  60. package/dist/report/html.d.ts +0 -47
  61. package/dist/report/html.js +0 -923
  62. package/dist/report/icons.d.ts +0 -51
  63. package/dist/report/icons.js +0 -93
  64. package/dist/report/live.d.ts +0 -7
  65. package/dist/report/live.js +0 -135
  66. package/dist/report/logos.d.ts +0 -4
  67. package/dist/report/logos.js +0 -19
  68. package/dist/report/markup.d.ts +0 -50
  69. package/dist/report/markup.js +0 -156
  70. package/dist/report/menu-bar.d.ts +0 -60
  71. package/dist/report/menu-bar.js +0 -157
  72. package/dist/report/player.d.ts +0 -102
  73. package/dist/report/player.js +0 -315
  74. package/dist/report/pr-summary.d.ts +0 -11
  75. package/dist/report/pr-summary.js +0 -119
  76. package/dist/report/sha256.d.ts +0 -9
  77. package/dist/report/sha256.js +0 -97
  78. package/dist/report/share-page.d.ts +0 -48
  79. package/dist/report/share-page.js +0 -291
  80. package/dist/report/shots.d.ts +0 -59
  81. package/dist/report/shots.js +0 -280
  82. package/dist/report/sign-in.d.ts +0 -41
  83. package/dist/report/sign-in.js +0 -568
  84. package/dist/report/styles.d.ts +0 -3
  85. package/dist/report/styles.js +0 -274
  86. package/dist/report/view.d.ts +0 -296
  87. package/dist/report/view.js +0 -702
  88. package/dist/report/walkthrough.d.ts +0 -93
  89. package/dist/report/walkthrough.js +0 -716
  90. package/dist/schema/accounts.d.ts +0 -137
  91. package/dist/schema/accounts.js +0 -121
  92. package/dist/schema/config.d.ts +0 -7
  93. package/dist/schema/config.js +0 -6
  94. package/dist/schema/doctor.d.ts +0 -46
  95. package/dist/schema/doctor.js +0 -30
  96. package/dist/schema/evidence.d.ts +0 -1115
  97. package/dist/schema/evidence.js +0 -565
  98. package/dist/schema/findings.d.ts +0 -161
  99. package/dist/schema/findings.js +0 -82
  100. package/dist/schema/job.d.ts +0 -1905
  101. package/dist/schema/job.js +0 -577
  102. package/dist/schema/ledger.d.ts +0 -1124
  103. package/dist/schema/ledger.js +0 -285
  104. package/dist/schema/share.d.ts +0 -55
  105. package/dist/schema/share.js +0 -64
  106. package/dist/schema/status.d.ts +0 -7
  107. package/dist/schema/status.js +0 -11
@@ -1,410 +0,0 @@
1
- import { ATTR_VALUE_MAX, ATTRS_MAX, candidateKey, elementOf, framesOf, matchText, } from '../schema/index.js';
2
- import { parseSelector, SUPPORTED_CSS, selectorKey, selectorMatches, usesAncestors, } from './css.js';
3
- import { clipBox } from './labels.js';
4
- import { describeFrames, describeTarget } from './steps.js';
5
- const norm = matchText;
6
- /**
7
- * An element as `css.ts` matches it, with the element it is in from `parent`, and what of it was
8
- * not saved whole. Its ID and test ID are saved whole; its `class` attribute is its saved classes.
9
- */
10
- const cssElement = (el, parent, parentCut = false) => ({
11
- tag: el.tag,
12
- id: el.id,
13
- classes: el.classes,
14
- classesCut: el.moreClasses,
15
- attributesCut: el.moreAttrs,
16
- foreign: el.foreign,
17
- attribute: (name) => {
18
- if (name === 'id')
19
- return el.id === undefined ? undefined : { value: el.id };
20
- if (name === 'data-testid')
21
- return el.testId === undefined ? undefined : { value: el.testId };
22
- if (name === 'class')
23
- return el.classes === undefined
24
- ? el.moreClasses === true
25
- ? { value: '', cut: true }
26
- : undefined
27
- : { value: el.classes.join(' '), cut: el.moreClasses };
28
- const value = el.attrs?.[name];
29
- if (value !== undefined)
30
- return { value, cut: el.cutAttrs?.includes(name) };
31
- return el.omittedAttrs?.includes(name) === true ? 'unsaved' : undefined;
32
- },
33
- parent,
34
- parentCut,
35
- });
36
- /** A saved node (`ShotPage.nodes`), with the ones it is in. */
37
- const nodeElement = (nodes, index) => {
38
- const node = nodes[index];
39
- return node === undefined
40
- ? undefined
41
- : cssElement(node, () => node.parent === undefined ? undefined : nodeElement(nodes, node.parent));
42
- };
43
- /** A candidate as a selector sees it, with the saved elements it is in. */
44
- const candidateElement = (c, page) => cssElement(c, () => c.up === undefined || page.nodes === undefined ? undefined : nodeElement(page.nodes, c.up), c.upCut === true);
45
- /** An `<iframe>` saved with a screenshot as a selector sees it, with what it is in. */
46
- const frameElement = (frame) => {
47
- const ancestors = frame.ancestors ?? [];
48
- const at = (depth) => {
49
- const node = ancestors[depth];
50
- return node === undefined
51
- ? undefined
52
- : cssElement(node, () => at(depth + 1), depth === ancestors.length - 1 && frame.moreAncestors === true);
53
- };
54
- return cssElement(frame, () => at(0), ancestors.length === 0 && frame.moreAncestors === true);
55
- };
56
- /** A target's CSS selector parsed, or why it cannot be checked against `page`, in words. */
57
- const selectorOf = (target, page, frames) => {
58
- if (target.css === undefined)
59
- return {};
60
- const parsed = parseSelector(target.css);
61
- const whose = frames ? "the frame's CSS selector" : 'the CSS selector';
62
- if (parsed._tag === 'unsupported')
63
- return {
64
- problem: `${parsed.reason.replace(/^the CSS selector/, whose)}; highlights take ${SUPPORTED_CSS}, or a role, text, label or alt`,
65
- };
66
- const saved = frames
67
- ? (page.frames ?? []).some((f) => f.ancestors !== undefined)
68
- : page.nodes !== undefined;
69
- if (usesAncestors(parsed.selector) && !saved)
70
- return {
71
- problem: `${whose} names what the element is in, which this screenshot's page state does not hold (it was saved by an older version); name the element itself`,
72
- };
73
- return { selector: parsed.selector };
74
- };
75
- /** Whether `c` matches, and whether exactly (the whole name or text, not just part of it). */
76
- const matchOf = (target, c, css, element) => {
77
- const by = (have, want) => {
78
- const [h, w] = [norm(have), norm(want)];
79
- return h === w ? 'exact' : h.includes(w) ? 'partial' : undefined;
80
- };
81
- if (target.role !== undefined) {
82
- if (norm(c.role) !== norm(target.role))
83
- return undefined;
84
- return target.name === undefined ? 'exact' : by(c.name, target.name);
85
- }
86
- if (target.text !== undefined)
87
- return 'text' in c ? by(c.text, target.text) : undefined;
88
- if (target.label !== undefined)
89
- return 'label' in c ? by(c.label, target.label) : undefined;
90
- if (target.alt !== undefined)
91
- return 'alt' in c ? by(c.alt, target.alt) : undefined;
92
- if (css === undefined)
93
- return undefined;
94
- const matches = selectorMatches(css, element());
95
- return matches === true ? 'exact' : matches === undefined ? 'unsure' : undefined;
96
- };
97
- /** Why a selector is not matched when whether it matches depends on what was not saved whole. */
98
- const notSavedWhole = (whose) => `${whose} depends on an attribute value, attribute, class or enclosing element that was not saved whole with the screenshot (values are cut to ${ATTR_VALUE_MAX} characters, at most ${ATTRS_MAX} attributes and 8 classes are kept), so it cannot be told what it matches; name it by role, text, label or alt, or by what was saved whole`;
99
- /**
100
- * The key (see `candidateKey`) that any element matching `target` exactly has, when there is one
101
- * that `Truncated.unsaved` counts: for a CSS selector, only one of a single `#id` or test ID.
102
- */
103
- const exactKey = (target, css) => {
104
- if (target.role !== undefined)
105
- return target.name === undefined
106
- ? candidateKey.role(target.role)
107
- : candidateKey.roleName(target.role, target.name);
108
- if (target.text !== undefined)
109
- return candidateKey.text(target.text);
110
- if (target.label !== undefined)
111
- return candidateKey.label(target.label);
112
- if (target.alt !== undefined)
113
- return candidateKey.alt(target.alt);
114
- const key = css === undefined ? undefined : selectorKey(css);
115
- if (key === undefined)
116
- return undefined;
117
- return 'id' in key ? candidateKey.id(key.id) : candidateKey.testId(key.testId);
118
- };
119
- /**
120
- * Why the one saved element that matches might not be the only element that does, on a page
121
- * where not every element was saved; undefined when it provably is. Only an exact match can be
122
- * proven: an unsaved element that matches exactly too has the same key, and is counted. One that
123
- * matches only partly loses to the exact match, unless it is inside it (the innermost match
124
- * wins). Inside, its text is part of the match's text, so it matches exactly too; a name need not
125
- * be, so a saved element with an unsaved one of its role inside (`nested`) is not proven.
126
- */
127
- const doubt = (target, css, match, truncated, saved) => {
128
- if (!truncated.complete)
129
- return 'this page was too big for all its elements to be looked at, so it cannot be told apart for sure';
130
- const cut = `only ${saved} of this page's ${truncated.found} elements were saved with the screenshot`;
131
- const key = exactKey(target, css);
132
- if (match.how !== 'exact' || key === undefined)
133
- return `${cut}, so only an exact name, text, label, alt text, #id or test ID can be told apart; name it exactly`;
134
- const others = truncated.unsaved[key] ?? 0;
135
- if (others > 0)
136
- return `${cut}, and ${others} more ${others === 1 ? 'element that was not saved matches' : 'elements that were not saved match'} too; name it more precisely`;
137
- if (target.role !== undefined && truncated.nested.includes(match.index))
138
- return `${cut}, and an element inside it that was not saved could match too; name it more precisely`;
139
- return undefined;
140
- };
141
- const sameBox = (a, b) => a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
142
- /** The part of `box` on an image of `width` × `height`, or undefined when none of it is. */
143
- export const clampBox = (box, width, height) => {
144
- const x0 = Math.max(0, box.x);
145
- const y0 = Math.max(0, box.y);
146
- const x1 = Math.min(width, box.x + box.width);
147
- const y1 = Math.min(height, box.y + box.height);
148
- const round = (n) => Math.round(n * 100) / 100;
149
- return x1 - x0 > 0 && y1 - y0 > 0
150
- ? { x: round(x0), y: round(y0), width: round(x1 - x0), height: round(y1 - y0) }
151
- : undefined;
152
- };
153
- /**
154
- * The part of an element's `content` (its text and images) inside its `box`, which is already on
155
- * the image; undefined when it has none there, or none was saved.
156
- */
157
- export const contentWithin = (content, box) => {
158
- if (content === undefined)
159
- return undefined;
160
- const part = clipBox(content, box);
161
- const round = (n) => Math.round(n * 100) / 100;
162
- return part.width > 0 && part.height > 0
163
- ? { x: round(part.x), y: round(part.y), width: round(part.width), height: round(part.height) }
164
- : undefined;
165
- };
166
- /** Why a mark is refused on an element that was in the page but not seen on the screenshot. */
167
- export const NOT_VISIBLE = 'the element was not visible when the screenshot was taken';
168
- /**
169
- * Matches left out as not on the screenshot, in words: `1 more match outside this screenshot was
170
- * ignored`. `where` is what they were outside of.
171
- */
172
- const ignoredText = (outside, unseen, where) => {
173
- const parts = [
174
- ...(outside > 0
175
- ? [`${outside} more ${outside === 1 ? 'match' : 'matches'} outside ${where}`]
176
- : []),
177
- ...(unseen > 0
178
- ? [
179
- outside > 0
180
- ? `${unseen} that ${unseen === 1 ? 'was' : 'were'} not visible`
181
- : `${unseen} more ${unseen === 1 ? 'match that was' : 'matches that were'} not visible`,
182
- ]
183
- : []),
184
- ];
185
- return parts.length === 0
186
- ? undefined
187
- : `${parts.join(' and ')} ${outside + unseen === 1 ? 'was' : 'were'} ignored`;
188
- };
189
- /**
190
- * Finds `target` among the elements saved with a screenshot. When several match, an element
191
- * inside another match wins over that one (text is in every ancestor too), then an exact name or
192
- * text over a partial one. Then, when some of those left are on the screenshot (on its image, in
193
- * `part` when given, and visible when it was taken), the others are left out and said so: a copy
194
- * far below a viewport screenshot or below where its frame shows, or one that is transparent, is
195
- * not what the agent saw. More than one left, unless they share one box, is ambiguous; an element
196
- * the page had but did not show gets no mark. The box is cut to `part`.
197
- */
198
- export const resolveTarget = (target, page, part) => {
199
- const { selector: css, problem } = selectorOf(target, page, false);
200
- if (problem !== undefined)
201
- return { _tag: 'missing', reason: problem };
202
- const all = page.candidates.flatMap((c, index) => {
203
- const how = matchOf(target, c, css, () => candidateElement(c, page));
204
- return how === undefined ? [] : [{ c, index, how }];
205
- });
206
- if (all.some((m) => m.how === 'unsure'))
207
- return { _tag: 'missing', reason: notSavedWhole('the CSS selector') };
208
- const matched = all.flatMap((m) => (m.how === 'unsure' ? [] : [{ ...m, how: m.how }]));
209
- if (matched.length === 0)
210
- return {
211
- _tag: 'missing',
212
- reason: page.truncated === undefined
213
- ? 'element not found on this screenshot'
214
- : `element not found among the ${page.candidates.length} elements saved with this screenshot; the page had more`,
215
- };
216
- const indices = new Set(matched.map((m) => m.index));
217
- /** Matches that hold another match are dropped: the innermost one is the element. */
218
- const holders = new Set();
219
- for (const m of matched)
220
- for (let p = m.c.parent; p !== undefined; p = page.candidates[p]?.parent) {
221
- if (holders.has(p))
222
- break;
223
- if (indices.has(p))
224
- holders.add(p);
225
- }
226
- let left = matched.filter((m) => !holders.has(m.index));
227
- if (left.length > 1 && left.some((m) => m.how === 'exact'))
228
- left = left.filter((m) => m.how === 'exact');
229
- const where = part?.where ?? 'this screenshot';
230
- /** The part of an element's box on the image, and where its document shows. */
231
- const placed = (c) => clampBox(part === undefined ? c.box : clipBox(c.box, part.box), page.width, page.height);
232
- const onImage = (c) => placed(c) !== undefined;
233
- const shown = left.filter((m) => m.c.visible !== false && onImage(m.c));
234
- let ignored;
235
- if (shown.length > 0 && shown.length < left.length) {
236
- const outside = left.filter((m) => !onImage(m.c)).length;
237
- ignored = ignoredText(outside, left.length - shown.length - outside, where);
238
- left = shown;
239
- }
240
- const [first] = left;
241
- if (first === undefined || left.some((m) => !sameBox(m.c.box, first.c.box)))
242
- return {
243
- _tag: 'ambiguous',
244
- reason: `${left.length} elements match on this screenshot; name it more precisely`,
245
- };
246
- const unsure = page.truncated === undefined
247
- ? undefined
248
- : doubt(target, css, first, page.truncated, page.candidates.length);
249
- if (unsure !== undefined)
250
- return { _tag: 'ambiguous', reason: unsure };
251
- const box = placed(first.c);
252
- if (box === undefined)
253
- return { _tag: 'missing', reason: `the element is outside ${where}` };
254
- if (first.c.visible === false)
255
- return { _tag: 'missing', reason: NOT_VISIBLE };
256
- const content = contentWithin(first.c.content, box);
257
- return {
258
- _tag: 'found',
259
- box,
260
- ...(content !== undefined ? { content } : {}),
261
- ...(ignored !== undefined ? { ignored } : {}),
262
- };
263
- };
264
- /**
265
- * The page state of one document of a screenshot: the page's own elements (`frame` undefined), or
266
- * those of one of its frames, with `parent` counted among them and that document's `truncated`.
267
- * The page's own elements come first in a sidecar, so their indices stay as they are.
268
- */
269
- const documentOf = (page, frame) => {
270
- const local = new Map();
271
- const kept = [];
272
- page.candidates.forEach((c, i) => {
273
- if (c.frame !== frame)
274
- return;
275
- local.set(i, kept.length);
276
- kept.push(c);
277
- });
278
- const candidates = kept.map((candidate) => {
279
- const { parent, frame: _frame, ...c } = candidate;
280
- const at = parent === undefined ? undefined : local.get(parent);
281
- return at === undefined ? c : { ...c, parent: at };
282
- });
283
- const truncated = frame === undefined ? page.truncated : page.frames?.[frame]?.truncated;
284
- const { truncated: _t, frames: _f, framesFound: _n, framesUnread: _u, ...rest } = page;
285
- return { ...rest, candidates, ...(truncated !== undefined ? { truncated } : {}) };
286
- };
287
- /**
288
- * Finds the `<iframe>` `target` names among the frames saved with a screenshot that are in frame
289
- * `parent` (the page itself when undefined), the way `resolveTarget` finds an element.
290
- */
291
- const resolveFrame = (target, page, parent) => {
292
- const { selector: css, problem } = selectorOf(target, page, true);
293
- if (problem !== undefined)
294
- return { _tag: 'missing', reason: problem };
295
- const frames = page.frames ?? [];
296
- const some = page.framesFound !== undefined && page.framesFound > frames.length;
297
- /** Frames beside these that could not be described: any of them could match too. */
298
- const unread = (parent === undefined ? page.framesUnread : frames[parent]?.framesUnread) ?? 0;
299
- const all = frames.flatMap((f, index) => {
300
- const how = f.parent === parent ? matchOf(target, f, css, () => frameElement(f)) : undefined;
301
- return how === undefined ? [] : [{ f, index, how }];
302
- });
303
- if (all.some((m) => m.how === 'unsure'))
304
- return { _tag: 'missing', reason: notSavedWhole("the frame's CSS selector") };
305
- const matched = all.flatMap((m) => (m.how === 'unsure' ? [] : [{ ...m, how: m.how }]));
306
- if (matched.length === 0)
307
- return {
308
- _tag: 'missing',
309
- reason: some
310
- ? `frame not found among the ${frames.length} frames saved with this screenshot; the page had more`
311
- : unread > 0
312
- ? `frame not found among the frames saved with this screenshot; ${unread} could not be read`
313
- : 'frame not found on this screenshot',
314
- };
315
- const left = matched.some((m) => m.how === 'exact')
316
- ? matched.filter((m) => m.how === 'exact')
317
- : matched;
318
- const [first] = left;
319
- if (first === undefined || left.length > 1)
320
- return {
321
- _tag: 'ambiguous',
322
- reason: `${left.length} frames match on this screenshot; name the frame more precisely`,
323
- };
324
- if (some)
325
- return {
326
- _tag: 'ambiguous',
327
- reason: `only ${frames.length} of this screenshot's ${page.framesFound} frames were saved, so the frame cannot be told apart for sure`,
328
- };
329
- if (unread > 0)
330
- return {
331
- _tag: 'ambiguous',
332
- reason: `${unread} other frame${unread === 1 ? '' : 's'} beside it could not be read, so the frame cannot be told apart for sure`,
333
- };
334
- if (first.f.unread !== undefined)
335
- return { _tag: 'missing', reason: `nothing in that frame was saved: ${first.f.unread}` };
336
- return { _tag: 'frame', index: first.index };
337
- };
338
- /**
339
- * Finds a highlight's element on a screenshot: in the frames its `frame` names, outermost first,
340
- * then among that document's elements (`resolveTarget`). An element in a frame gets only the part
341
- * of its box where the frame shows, and a match outside that part counts as outside the
342
- * screenshot, as a copy below a viewport screenshot does. The frame's own `truncated` decides
343
- * whether a match is unique there. One without `frame` is looked for in the page itself only,
344
- * as a step would; when it is missing there but in a frame, the reason says so.
345
- */
346
- export const resolveHighlight = (target, page) => {
347
- let frame;
348
- for (const named of framesOf(target.frame)) {
349
- const found = resolveFrame(named, page, frame);
350
- if (found._tag !== 'frame')
351
- return found;
352
- frame = found.index;
353
- }
354
- const element = elementOf(target);
355
- const shown = frame === undefined ? undefined : page.frames?.[frame]?.box;
356
- const resolution = resolveTarget(element, documentOf(page, frame), shown === undefined
357
- ? undefined
358
- : {
359
- box: shown,
360
- where: `the part of its frame${describeFrames(framesOf(target.frame)).replace(/^ in iframe/, '')} that shows on this screenshot`,
361
- });
362
- if (frame === undefined) {
363
- if (resolution._tag !== 'missing' || page.frames === undefined)
364
- return resolution;
365
- const { selector: css } = selectorOf(element, page, false);
366
- const inFrame = page.candidates.some((c) => c.frame !== undefined &&
367
- matchOf(element, c, css, () => candidateElement(c, page)) !== undefined);
368
- return inFrame
369
- ? {
370
- ...resolution,
371
- reason: `${resolution.reason}; it is inside a frame, so name the frame too, such as "frame": {"css": "iframe"}`,
372
- }
373
- : resolution;
374
- }
375
- return resolution;
376
- };
377
- /**
378
- * Places every highlight of `findings` on its screenshot. `shots` has every screenshot of the run
379
- * by ID, with its saved page state when it has one, and why its boxes cannot be placed on the
380
- * image when they cannot (`unplaced`, see `pageUnplaced`). Highlights on unknown screenshots are
381
- * left out: `checkFindings` rejects them before findings are saved.
382
- */
383
- export const placeMarks = (findings, shots) => {
384
- const placed = {};
385
- for (const entry of findings.cases)
386
- for (const highlight of entry.highlights ?? []) {
387
- const found = shots.get(highlight.shot);
388
- if (found === undefined)
389
- continue;
390
- const base = {
391
- mark: highlight.mark,
392
- target: describeTarget(highlight.target),
393
- ...(highlight.note !== undefined ? { note: highlight.note } : {}),
394
- };
395
- const resolution = found.page === undefined
396
- ? { _tag: 'missing', reason: 'this screenshot has no saved page state to look in' }
397
- : found.unplaced !== undefined
398
- ? { _tag: 'missing', reason: found.unplaced }
399
- : resolveHighlight(highlight.target, found.page);
400
- (placed[highlight.shot] ??= []).push(resolution._tag === 'found'
401
- ? {
402
- ...base,
403
- box: resolution.box,
404
- ...(resolution.content !== undefined ? { content: resolution.content } : {}),
405
- ...(resolution.ignored !== undefined ? { ignored: resolution.ignored } : {}),
406
- }
407
- : { ...base, problem: resolution.reason });
408
- }
409
- return placed;
410
- };