Skip to content

feat(flow): regex matching via matches in assertions and selectors#503

Open
j-piasecki wants to merge 1 commit into
mainfrom
pr503
Open

feat(flow): regex matching via matches in assertions and selectors#503
j-piasecki wants to merge 1 commit into
mainfrom
pr503

Conversation

@j-piasecki

Copy link
Copy Markdown
Member

What

  • Add matches as a case-sensitive JavaScript regex comparator for await and assert text conditions.
  • Support { text: { matches: ... } } in every flow selector slot, combined with id and role.
  • Preserve regex matchers through parsing, YAML serialization, recording summaries, and run reports.

Correctness

  • Prevent empty-matchable patterns from matching unlabeled nodes or empty assertion text.
  • Reject unknown raw await-ui-element selector keys instead of silently dropping constraints.
  • Reject selector combinations YAML cannot round-trip without changing their semantics.
  • Document native label aggregation accurately and keep action ranking consistent.

Maintenance

  • Share selector-field and regex-syntax validation across both matcher parse paths.
  • Compile selector regexes once per tree walk and full-match regexes once per ranking pass.
  • Make comparator serialization exhaustive, extract the duplicated flow test harness, and scope slow-test timeouts narrowly.

Verification

  • Full tool-server suite: 2,588 tests across 263 files.
  • Source and test typechecks, ESLint, Prettier, and skill-copy validation pass.

## What

- Add `matches` as a case-sensitive JavaScript regex comparator for `await` and `assert` text conditions.
- Support `{ text: { matches: ... } }` in every flow selector slot, combined with `id` and `role`.
- Preserve regex matchers through parsing, YAML serialization, recording summaries, and run reports.

## Correctness

- Prevent empty-matchable patterns from matching unlabeled nodes or empty assertion text.
- Reject unknown raw `await-ui-element` selector keys instead of silently dropping constraints.
- Reject selector combinations YAML cannot round-trip without changing their semantics.
- Document native label aggregation accurately and keep action ranking consistent.

## Maintenance

- Share selector-field and regex-syntax validation across both matcher parse paths.
- Compile selector regexes once per tree walk and full-match regexes once per ranking pass.
- Make comparator serialization exhaustive, extract the duplicated flow test harness, and scope slow-test timeouts narrowly.

## Verification

- Full tool-server suite: 2,588 tests across 263 files.
- Source and test typechecks, ESLint, Prettier, and skill-copy validation pass.

@latekvo latekvo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great idea, gg :shipit:

Comment on lines +39 to +41
`text` also takes a **regex matcher map** — `{ text: { matches: '^Order #\d+$' } }`, in any selector slot — for dynamic text no literal can pin. It tests each node's native **own** label/value, excluding only adapter-hoisted `subtreeText`. On iOS, an accessible container's native label may already aggregate descendant text, so a wrapper and its leaf can both match. Matching is unanchored and **case-sensitive** like the `text` condition's `matches`, and an invalid pattern fails at parse. Quote the pattern in single quotes (they keep backslashes). So `assert: { visible: { text: { matches: '^Taps: \d+$' } } }` asserts a counter is on screen with no locator at all, and `tap: { text: { matches: '^Order #\d+$' } }` taps a dynamic row — though a stable `id` is still the more robust action target.

Selectors resolve against the **full native hierarchy** (iOS: the UIView tree; Android: the complete accessibility hierarchy including not-important views) — strictly more than `describe` or the raw `await-ui-element` tool see (both use the trimmed tree), with complete `testID`/`resource-id` coverage. So an `id` selector works even when `describe` collapses or omits the element — don't fall back to coordinate taps just because a testID isn't visible in `describe` output. And when several elements match — including wrappers whose native text aggregates descendant content — the action directives (`tap`, `type`, `scroll-to`) pick the **most specific** match: an exact text/identifier match beats a substring hit (for a regex matcher, a pattern consuming the element's whole text counts as exact), then the smallest frame wins.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear, my comment from #497 DOES NOT apply to this text block, as flow files should always prefer by-label taps over coord taps. Just wanted to clear this out :)

Comment on lines +39 to +41
`text` also takes a **regex matcher map** — `{ text: { matches: '^Order #\d+$' } }`, in any selector slot — for dynamic text no literal can pin. It tests each node's native **own** label/value, excluding only adapter-hoisted `subtreeText`. On iOS, an accessible container's native label may already aggregate descendant text, so a wrapper and its leaf can both match. Matching is unanchored and **case-sensitive** like the `text` condition's `matches`, and an invalid pattern fails at parse. Quote the pattern in single quotes (they keep backslashes). So `assert: { visible: { text: { matches: '^Taps: \d+$' } } }` asserts a counter is on screen with no locator at all, and `tap: { text: { matches: '^Order #\d+$' } }` taps a dynamic row — though a stable `id` is still the more robust action target.

Selectors resolve against the **full native hierarchy** (iOS: the UIView tree; Android: the complete accessibility hierarchy including not-important views) — strictly more than `describe` or the raw `await-ui-element` tool see (both use the trimmed tree), with complete `testID`/`resource-id` coverage. So an `id` selector works even when `describe` collapses or omits the element — don't fall back to coordinate taps just because a testID isn't visible in `describe` output. And when several elements match — including wrappers whose native text aggregates descendant content — the action directives (`tap`, `type`, `scroll-to`) pick the **most specific** match: an exact text/identifier match beats a substring hit (for a regex matcher, a pattern consuming the element's whole text counts as exact), then the smallest frame wins.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This text looks bloated to me but this isn't a core skill so it's not a huge deal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants