@rickcedwhat/playwright-smart-vision 0.4.0-next.a59a073 → 0.4.0-next.ae9971f

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 (117) hide show
  1. package/README.md +17 -0
  2. package/dist/action-scope.test.d.ts +2 -0
  3. package/dist/action-scope.test.d.ts.map +1 -0
  4. package/dist/action-scope.test.js +57 -0
  5. package/dist/action-scope.test.js.map +1 -0
  6. package/dist/author/apply.d.ts +61 -9
  7. package/dist/author/apply.d.ts.map +1 -1
  8. package/dist/author/apply.js +453 -136
  9. package/dist/author/apply.js.map +1 -1
  10. package/dist/author/author.test.js +36 -0
  11. package/dist/author/author.test.js.map +1 -1
  12. package/dist/author/catalog.d.ts +4 -3
  13. package/dist/author/catalog.d.ts.map +1 -1
  14. package/dist/author/catalog.js +20 -11
  15. package/dist/author/catalog.js.map +1 -1
  16. package/dist/author/geometry.d.ts +5 -0
  17. package/dist/author/geometry.d.ts.map +1 -1
  18. package/dist/author/geometry.js +17 -0
  19. package/dist/author/geometry.js.map +1 -1
  20. package/dist/author/geometry.test.js +18 -1
  21. package/dist/author/geometry.test.js.map +1 -1
  22. package/dist/author/index.d.ts +3 -3
  23. package/dist/author/index.d.ts.map +1 -1
  24. package/dist/author/index.js +2 -2
  25. package/dist/author/index.js.map +1 -1
  26. package/dist/author/options.d.ts +3 -1
  27. package/dist/author/options.d.ts.map +1 -1
  28. package/dist/author/options.js +9 -0
  29. package/dist/author/options.js.map +1 -1
  30. package/dist/author/roundtrip.test.d.ts +2 -0
  31. package/dist/author/roundtrip.test.d.ts.map +1 -0
  32. package/dist/author/roundtrip.test.js +240 -0
  33. package/dist/author/roundtrip.test.js.map +1 -0
  34. package/dist/author/show.d.ts +2 -2
  35. package/dist/author/show.js +2 -2
  36. package/dist/author/storage.js +1 -1
  37. package/dist/author/storage.js.map +1 -1
  38. package/dist/configure.d.ts +2 -2
  39. package/dist/configure.d.ts.map +1 -1
  40. package/dist/configure.js +6 -2
  41. package/dist/configure.js.map +1 -1
  42. package/dist/devtools.d.ts.map +1 -1
  43. package/dist/devtools.js +197 -2
  44. package/dist/devtools.js.map +1 -1
  45. package/dist/dropdown-strategies.test.d.ts +2 -0
  46. package/dist/dropdown-strategies.test.d.ts.map +1 -0
  47. package/dist/dropdown-strategies.test.js +21 -0
  48. package/dist/dropdown-strategies.test.js.map +1 -0
  49. package/dist/element.d.ts +20 -2
  50. package/dist/element.d.ts.map +1 -1
  51. package/dist/element.js +102 -27
  52. package/dist/element.js.map +1 -1
  53. package/dist/extractor-queue.d.ts +2 -0
  54. package/dist/extractor-queue.d.ts.map +1 -0
  55. package/dist/extractor-queue.js +17 -0
  56. package/dist/extractor-queue.js.map +1 -0
  57. package/dist/field-extractor.d.ts.map +1 -1
  58. package/dist/field-extractor.js +181 -136
  59. package/dist/field-extractor.js.map +1 -1
  60. package/dist/index.d.ts +5 -4
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +1 -1
  63. package/dist/index.js.map +1 -1
  64. package/dist/presets.d.ts +9 -3
  65. package/dist/presets.d.ts.map +1 -1
  66. package/dist/presets.js +9 -3
  67. package/dist/presets.js.map +1 -1
  68. package/dist/screen-config.d.ts +1 -0
  69. package/dist/screen-config.d.ts.map +1 -1
  70. package/dist/screen-config.js +6 -0
  71. package/dist/screen-config.js.map +1 -1
  72. package/dist/screen-config.test.d.ts +2 -0
  73. package/dist/screen-config.test.d.ts.map +1 -0
  74. package/dist/screen-config.test.js +22 -0
  75. package/dist/screen-config.test.js.map +1 -0
  76. package/dist/screen-frame.test.d.ts +2 -0
  77. package/dist/screen-frame.test.d.ts.map +1 -0
  78. package/dist/screen-frame.test.js +182 -0
  79. package/dist/screen-frame.test.js.map +1 -0
  80. package/dist/screen-handler.d.ts.map +1 -1
  81. package/dist/screen-handler.js +2 -0
  82. package/dist/screen-handler.js.map +1 -1
  83. package/dist/screen-result.d.ts +14 -1
  84. package/dist/screen-result.d.ts.map +1 -1
  85. package/dist/screen-result.js +137 -48
  86. package/dist/screen-result.js.map +1 -1
  87. package/dist/screen.d.ts +23 -15
  88. package/dist/screen.d.ts.map +1 -1
  89. package/dist/screen.js +45 -25
  90. package/dist/screen.js.map +1 -1
  91. package/dist/strategies.d.ts +73 -2
  92. package/dist/strategies.d.ts.map +1 -1
  93. package/dist/strategies.js +132 -4
  94. package/dist/strategies.js.map +1 -1
  95. package/dist/strategies.test.js +4 -4
  96. package/dist/strategies.test.js.map +1 -1
  97. package/dist/text-element.d.ts +9 -3
  98. package/dist/text-element.d.ts.map +1 -1
  99. package/dist/text-element.js +10 -5
  100. package/dist/text-element.js.map +1 -1
  101. package/dist/text-element.test.js +6 -0
  102. package/dist/text-element.test.js.map +1 -1
  103. package/dist/types.d.ts +17 -2
  104. package/dist/types.d.ts.map +1 -1
  105. package/dist/types.js +11 -0
  106. package/dist/types.js.map +1 -1
  107. package/dist/utils/ocr.d.ts +29 -11
  108. package/dist/utils/ocr.d.ts.map +1 -1
  109. package/dist/utils/ocr.js +77 -21
  110. package/dist/utils/ocr.js.map +1 -1
  111. package/dist/utils/ocr.test.js +43 -1
  112. package/dist/utils/ocr.test.js.map +1 -1
  113. package/package.json +9 -10
  114. package/skills/psv-authoring/SKILL.md +40 -0
  115. package/skills/psv-authoring/references/first-pass.md +36 -0
  116. package/skills/psv-debugging/SKILL.md +39 -0
  117. package/skills/psv-test-writing/SKILL.md +63 -0
@@ -0,0 +1,36 @@
1
+ # Canonical first-pass details
2
+
3
+ `first-pass.json` assigns semantic names/types to actual IDs in `boxes.json`. Minimal shape (IDs shown only as an example; use IDs from your capture):
4
+
5
+ ```json
6
+ {
7
+ "ready": "formTitle",
8
+ "elements": [
9
+ { "name": "formTitle", "type": "label", "boxIds": [1] },
10
+ { "name": "firstName", "type": "field", "boxIds": [2], "labelIds": [3] },
11
+ { "name": "phone", "type": "field", "boxIds": [4, 5, 6], "parts": [
12
+ { "name": "area", "boxId": 4 },
13
+ { "name": "prefix", "boxId": 5 },
14
+ { "name": "line", "boxId": 6 }
15
+ ] }
16
+ ]
17
+ }
18
+ ```
19
+
20
+ Types: field, button, checkbox, radio, dropdown, tab, label, icon, message, other. Element names are camelCase and screen directories kebab-case. `ready` accepts a name, names, or `{ "any": ["name"] }`.
21
+
22
+ `labelIds` reference detected captions. They stabilize matching while the value changes; use the actual caption location, including above/right labels. `boxIds` join the intended controls. Buttons whose text is inside the box usually need no separate caption. An undersized fragment of an icon is not the whole target.
23
+
24
+ Same-kind cells (phone/date/name components) can be one target with named parts. A dropdown beside a different field can instead be a section: define a section with both box IDs, then member elements that share its section name. Apply absorbs them into the section parent with short named parts; use `element(parent).part(member)`, not a separate top-level element for the absorbed member.
25
+
26
+ Selected/default text uses `ocrSource: "live"` and `ocrRect` relative to the template anchor. Measure the rectangle on the capture and exclude labels, borders, arrows and menu options. A unique title/label can anchor a detached region. Legacy `changes` reads changed ink; it may read nothing when text equals the reference.
27
+
28
+ Explicit part geometry uses authoring `rect` relative to the parent crop; a part's `ocrRect` is ignored. Section members use their own `ocrRect`, which Apply translates into absorbed part geometry. Saved runtime parts have x/y/width/height rather than authoring `rect`.
29
+
30
+ `variants` maps appearance names to `{ "filename": "state.png" }` inside templates/. Capture real disabled/enabled/loading or other legitimate appearances. Keep the sources and reference images; do not add a variant to bless an unconfirmed product defect. Section-parent variants belong on the section; nested part variants are unsupported.
31
+
32
+ Omitted refinements preserve supported existing runtime edits on an unchanged layout; explicit values take precedence. In `first-pass.json`, `null` supports clearing `ready` and `variants`, or requesting generated geometry for `ocrRect` and a part's `rect`.
33
+
34
+ Do not set `read`, `charset`, `swaps`, `overflow` or `ocrSource` to `null` in `first-pass.json`; validation rejects those values. On an already applied screen, clear these options with `patchElementOptions()` or `patchPartOptions()`, passing `null` for each option to remove (for example, `{ read: null, charset: null }`). These APIs delete the properties from both the canonical first-pass and runtime definitions. Generated authoring metadata records geometry baselines; do not hand-edit it or use a sidecar to restore discarded options after Apply.
35
+
36
+ Use validateScreenAuthoring() before Apply, then Apply twice and inspect preservation. Relative layout changes with retained refinements can require explicit reviewed confirmation; translation alone is supported. A confirmation does not validate product intent or the correctness of matching state images.
@@ -0,0 +1,39 @@
1
+ ---
2
+ name: psv-debugging
3
+ description: Diagnoses and maintains Playwright Smart Vision template, OCR, action and state failures with visual evidence while preserving test intent. Use when PSV cannot locate/read a control, a test passes the wrong state, or a UI change affects saved assets.
4
+ metadata:
5
+ library: "@rickcedwhat/playwright-smart-vision"
6
+ library_version: "0.4.0-next.ae9971f"
7
+ type: core
8
+ source_paths: "src/field-extractor.ts, src/screen-result.ts, src/element.ts, src/author/options.ts"
9
+ ---
10
+
11
+ # Diagnose before changing acceptance
12
+
13
+ Separate four questions: did the target locate, is the value region readable, did the input action work, and does the final state satisfy the user's intent? A location confidence problem is different from empty OCR or a failed replacement action.
14
+
15
+ Inspect the failure screenshot/trace, requested template, best candidate and configured read region. If the candidate resembles a different saved target, inspect the library before creating a duplicate. A low-confidence/missing anchor makes live values unavailable; unavailable is not an empty value and must not pass an empty assertion.
16
+
17
+ - Wrong template/appearance: compare the actual crop and current screen. For a known accepted permanent redesign, update the canonical asset. For multiple legitimate appearances of the same semantic control, consider variants. Missing/wrong behavior remains failing until its expectedness is confirmed.
18
+ - Wrong/missing OCR: inspect the value crop and effective `read`, `ocrSource`, charset, swaps and overflow. Use live OCR for current default/selected text and a bounded region excluding labels and menu options. Inspect named parts individually. Crop geometry is relative to the matched anchor; numeric geometry belongs in reviewed authoring, not fixed runtime screen clicks.
19
+ - Wrong input: native insertText and canvas key events differ. Select-all may be ignored by a canvas. Choose a compatible explicit action recipe and assert the resulting value; do not claim replacement support from empty-field entry.
20
+ - Wrong selection/state: verify the selected value or checkbox/button state, not page-wide text presence. A menu option visible elsewhere must not satisfy the control assertion.
21
+
22
+ Supported option patches update canonical and runtime definitions together:
23
+
24
+ ```ts
25
+ import { configure } from '@rickcedwhat/playwright-smart-vision/configure';
26
+ import { patchElementOptions, patchPartOptions, applyScreen, validateScreenAuthoring } from '@rickcedwhat/playwright-smart-vision/author';
27
+
28
+ await configure({ storage: { root: './submission/screens' } });
29
+ // The selectedContact target must already have a reviewed bounded ocrRect.
30
+ patchElementOptions('customer-form', 'selectedContact', { ocrSource: 'live' });
31
+ patchPartOptions('customer-form', 'birthdate', 'month', { charset: { only: ['0-9'] } });
32
+ const validation = validateScreenAuthoring('customer-form');
33
+ if (!validation.valid) throw new Error(validation.errors.join('\n'));
34
+ applyScreen('customer-form');
35
+ ```
36
+
37
+ Use glyph allowances only for observed OCR confusions, after checking the crop. Do not normalize a different business value into the expected result. Preserve existing read/part/variant refinements during Apply. Rerun the specific assertion and a deliberately wrong-input control in an isolated copy.
38
+
39
+ For maintenance, retain the old baseline and show the asset/config/test diff. State what changed, why it is expected, how it was validated and what is unresolved. Ask the user with the affected evidence when intent is unknown. Do not weaken assertions or reinterpret missing controls as valid variants merely to get a green run.
@@ -0,0 +1,63 @@
1
+ ---
2
+ name: psv-test-writing
3
+ description: Writes and updates Playwright Smart Vision tests for canvas or remote-desktop interfaces, including fixture setup, action recipes, named parts and value/state assertions. Use when writing tests against authored PSV screens.
4
+ metadata:
5
+ library: "@rickcedwhat/playwright-smart-vision"
6
+ library_version: "0.4.0-next.ae9971f"
7
+ type: core
8
+ source_paths: "src/screen.ts, src/element.ts, src/strategies.ts"
9
+ ---
10
+
11
+ # Write visual tests
12
+
13
+ Use the installed package's public exports. The ordinary Playwright fixture provides per-test action configuration; a separate `init()` hook is unnecessary for fixture tests.
14
+
15
+ ```ts
16
+ import { createFixture, Strategies } from '@rickcedwhat/playwright-smart-vision';
17
+
18
+ const test = createFixture();
19
+ test.use({
20
+ storageRoot: './submission/screens',
21
+ actionStrategies: { fill: Strategies.Fill.clearAndType() },
22
+ });
23
+
24
+ test('edits a customer', async ({ page, screen }) => {
25
+ await page.goto('/');
26
+ const form = screen('customer-form');
27
+ await form.waitFor();
28
+ await form.element('firstName').fill('Ada');
29
+ await form.element('firstName').toHaveValue('Ada');
30
+ await form.element('birthdate').part('month').fill('04', {
31
+ strategy: Strategies.Fill.backspaceAndType({ maxLength: 2 }),
32
+ });
33
+ await form.element('birthdate').part('month').toHaveValue('04');
34
+ });
35
+ ```
36
+
37
+ Choose the input recipe from the target's observed behavior:
38
+ - Default `selectAllType()` selects all, clears, then uses `insertText`. Native/paste-capable inputs often support it; event-only canvases may ignore it.
39
+ - `clearAndType()` uses keyboard events but still requires select-all support. Filling an empty field does not prove replacement works.
40
+ - `backspaceAndType({ maxLength })` focuses, sends End and a known bounded number of Backspaces, then types. Use only with compatible focus/End/Backspace behavior and a known clearing bound.
41
+ - Existing presets expose their action portion as `presets.webview.strategies.actions`, etc. Reusing that portion does not configure OCR.
42
+
43
+ Assert the result after input. There is no automatic fallback cascade. Actions configured through `actionStrategies` are fixture-scoped; partial screen overrides use `screen(name, { actions: {...} })`, and fill/click calls accept `{ strategy }`. Omitted or undefined entries inherit. For non-fixture integrations, `init({ page, strategies: { actions } })` associates actions with that page. OCR/storage/capture defaults and `release()` remain shared runtime concerns.
44
+
45
+ Use named parts for multi-cell fields, asserting every required segment. Locate changing table data through current text or a verified value region, rather than per-customer cell images or fixed screen coordinates. `getByText()` is page-wide OCR; a visible option or label does not establish a selected field value.
46
+
47
+ Selected/default values need an authored `ocrSource: "live"` and bounded `ocrRect` excluding labels/menu options. Call `toHaveValue()` on that named element or part. The legacy changed-ink default can read nothing when current text equals the reference. Live OCR returns text; it does not snap to the nearest allowed option.
48
+
49
+ For stateful controls, assert the observed transition: disabled → enabled → loading → disabled is different from proving persistence. Prefer `check()`/`uncheck()` plus state assertions where the authored checkbox is readable. Use authored variants for legitimate appearances, not to accept an unconfirmed defect.
50
+
51
+ Keep required observations, optional checks and exclusions explicit. A green run or a coverage manifest is not proof of coverage. Challenge important assertions in separate diagnostic copies with an incorrect input/state while retaining the expected assertion; confirm failure at that assertion. Preserve original outputs. Ask the user about unknown product intent; an unanswered question is not approval.
52
+
53
+ For a mouse-driven dropdown with a known menu region, use
54
+ `selectOption(value, { strategy: Strategies.SelectOption.visualMenu(region) })`.
55
+ The rectangle is relative to the top left of the required live OCR value region. Include the menu rows and exclude
56
+ the control itself and unrelated labels. The recipe opens the control, clicks
57
+ only a unique text match inside the region on the first capture, and verifies the actual selected
58
+ value. Explicit recipes require a bounded live OCR value region and do not
59
+ use clipboard reads for verification.
60
+ Use `Strategies.SelectOption.keyboard()` for controls that support typing and
61
+ Enter, or supply a custom recipe. Set `actionStrategies.selectOption` to reuse
62
+ a recipe per fixture, or use a screen or call override. Omitting a recipe
63
+ retains the legacy unverified keyboard behavior.