fix(maestro): bound selector matching in the optional 0.22 plugin
Merged
TH
1h ago+247+247+012345678901234567890123456789-52-52-01234567890123456789
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:
matchesMaestroRegexran any valid pattern with nativeRegExp, 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
idandtextvalue compiles once before the snapshot scan. There is no process-wide cache. - Flags map
^(?:pattern)$withimsto RE2CASE_INSENSITIVE | MULTILINE | DOTALL. A test compares both engines. - One deliberate difference:
\sand\Smatch 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.
- Each
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.