fix(8): read interactive action_id from context, not top-level#36
Merged
Conversation
PR #33's Lexi review (CHANGES_REQUESTED, posted 6m after the merge) flagged that InteractiveAction::actionId() and value() were reading fields that don't exist in real Mattermost webhook payloads. The bug was real but the format diagnosis in the review was off — Mattermost sends JSON (not Slack-style form-urlencoded with a `payload` field), but it does NOT put `action` or `value` at the top level. Both come back inside the integrator-supplied `context` object. The DTO's tests passed because MattermostFixtures::fakeButtonClick() fabricated both layouts (top-level shortcuts AND the real `context` key). In production the top-level keys are absent, so actionId() returned '' and the router never matched any registered handler. - src/Interactive/InteractiveAction.php: actionId() and value() now read from `context.action` and `context.value` respectively, with doc-blocks explaining the convention (integrator stuffs the action name into the button definition's `integration.context.action`). - src/Testing/MattermostFixtures.php: drop the spurious top-level `action` and `value` shortcuts; nest both inside `context` to match what real Mattermost sends. - tests/Unit/Testing/MattermostFixturesTest.php: updated the fakeButtonClick assertion to verify the new shape and explicitly assert no top-level `action`/`value` keys. Controller is unchanged — `$request->all()` works fine for MM's real JSON body. 341 passed (14 integration skipped); pint, phpstan level 8, rector all clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix-forward for the bug Lexi flagged on PR #33 — her CHANGES_REQUESTED review landed 6 minutes after the merge, so the broken DTO is currently in
main.InteractiveAction::actionId()andvalue()were reading top-levelaction/valuekeys that do not exist in real Mattermost interactive webhook payloads. Mattermost passes the integrator'scontextobject back unchanged — by convention this package keys the action name ascontext.action. The original tests passed becauseMattermostFixtures::fakeButtonClick()fabricated both shapes (the realcontextkey plus spurious top-level shortcuts). In production the top-level shortcuts are absent, soactionId()returned''and the router never matched any registered handler.Note on Lexi's review
She had the right diagnosis (DTO reads from the wrong place) but described the format as Slack's (
application/x-www-form-urlencodedwith apayloadfield holding JSON). Mattermost's actual format is JSON — see the Mattermost docs. The controller's$request->all()is correct as-is; only the DTO and fixture needed changes.Changes
src/Interactive/InteractiveAction.php—actionId()reads from$payload['context']['action'];value()reads from$payload['context']['value']. Doc-blocks explain the integrator-supplied-context convention.src/Testing/MattermostFixtures.php—fakeButtonClick()no longer emits the spurious top-levelaction/valuekeys. Both nest insidecontextto mirror real Mattermost payloads.tests/Unit/Testing/MattermostFixturesTest.php— assertion updated for the new shape and explicitly checks no top-levelaction/valuekeys leak.Test plan
vendor/bin/pest --compact— 341 passed (14 integration skipped)vendor/bin/pint --test— cleanvendor/bin/phpstan analyse— clean at level 8vendor/bin/rector process --dry-run— cleanThe 34 existing
tests/Unit/Interactive/*tests still pass without modification — the fixture continues to exposecontext.action(where they read it) but no longer emits the spurious top-level fields.