fix(maestro): bound selector matching in the optional 0.22 plugin

Merged
TH
2h ago
+247-52

Summary

A Maestro id or text selector regex cannot stall the daemon event loop through catastrophic backtracking. The flow author controls the pattern. The app under test controls the text.

Before / after

  • Before: matchesMaestroRegex ran any valid pattern with native RegExp, so (a+)+$ against app text could block the event loop.
  • After: patterns run on re2js (MIT, no dependencies, bundled into the Maestro package), a linear-time RE2 port.
    • Each id and text value compiles once before the snapshot scan. There is no process-wide cache.
    • Flags map ^(?:pattern)$ with ims to RE2 CASE_INSENSITIVE | MULTILINE | DOTALL. A test compares both engines.
    • One deliberate difference: \s and \S match ASCII whitespace only, as in Maestro (Java regex). 0.22 JavaScript also matched Unicode whitespace such as U+00A0 and U+202F. The Boundaries section of run-maestro-flows.md documents it, and a test pins it.
    • Patterns without regex syntax match one whole line, case-insensitively, with no length cap. Invalid JavaScript regexes compare as literals.
    • A pattern over 256 characters, or one using backreferences or lookaround, fails with maestro_selector_regex_unsafe. The error details carry the exceeded limit.
    • A failed step still reports, without suggestions, when its selector is refused.

Size

About 125 added and 27 removed production lines versus 0.22, in the Maestro selector files plus package and bundling config.

Validation

pnpm exec vitest run packages/maestro/src/internal/__tests__/selector-regex.test.ts: 23 passed at 2f27af802b. With native RegExp, the backtracking and refusal tests fail. CI is pending.