Conversation
|
|
Thanks for the contribution! Before we can merge this, we need @alter to sign the Salesforce Inc. Contributor License Agreement. |
|
recheck |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3090 +/- ##
=======================================
Coverage 94.38% 94.38%
=======================================
Files 43 43
Lines 7426 7431 +5
Branches 704 704
=======================================
+ Hits 7009 7014 +5
Misses 408 408
Partials 9 9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
91acd67 to
2e5657b
Compare
AmyScript
left a comment
There was a problem hiding this comment.
Thanks for the fix! The test is a proper regression test, two invocations with fresh args, assserting next is calledOnce on each which failed before the change and passes after. LGTM!
Closes #1058
matchesPattern in src/middleware/builtin.ts calls pattern.test(candidate) directly on the
RegExp a caller passed to app.command(). RegExp#test() advances lastIndex on a pattern that
carries the g or y flag, and that state lives on the RegExp object itself, not in the call.
Since the same pattern object is reused for every incoming command (the middleware closure
captures it once), a command registered with a g or y flagged pattern matches on the first
invocation, fails to match on the second, matches again on the third, and so on, alternating
forever. The affected listener silently never runs on the failing invocations, so ack() never
gets called and Slack shows the interaction as timed out.
Fix resets pattern.lastIndex to 0 right before calling test(), so every invocation starts from
the same state regardless of what a previous invocation left behind. This only matters for
patterns with the g or y flag; resetting lastIndex on a pattern without either flag is a no-op
since test() ignores it. The two other places in builtin.ts that match a pattern
(matchConstraints and matchMessage) use String#match() instead of RegExp#test(), which does
not carry this same statefulness, so they were not affected and were not touched.
Tested:
invokes the resulting middleware twice with the same matching command, and asserts next()
gets called both times. Confirmed it fails against unmodified code (second invocation
never calls next()) and passes after the fix.
before this change plus the 1 new test.