test: cover the grammy wiring by dispatching real Updates through createBot - #313
Merged
Conversation
Every existing bot test drives a composer with a hand-rolled context stub, so none of them touch grammy: not Update -> Context construction, not the plugin chain (session/hydrate/i18n/autoChatAction), not command routing. A grammy or @grammyjs/types bump could break the real wiring with all 625 tests green — #312 had to be checked past that hole by hand, and smoke:api cannot help because STAGING=true skips Telegram entirely. Boots the real createBot() against mongodb-memory-server, supplies botInfo so handleUpdate skips getMe, and answers every outgoing call with an api transformer, so the fake token never reaches Telegram. The start assertion pins the locale text and the disabled link preview rather than just 'a reply happened': unhandledFeature answers /start too when startFeature is unwired, and a bare length check passed that mutation. Verified it now fails with startFeature removed and passes when restored. BOT_INFO is checked as UserFromGetMe at the call site, so a top-level @grammyjs/types that drifts from grammy's bundled copy fails typecheck here — the same field (supports_join_request_queries) the trap turns on.
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.
Closes the coverage gap flagged during the #312 dependency batch.
The hole
Every existing bot test drives a composer with a hand-rolled context stub. None of them touch grammy itself — not
Update→Contextconstruction, not the plugin chain (session/hydrate/i18n/autoChatAction), not command routing. So agrammyor@grammyjs/typesbump can break the real wiring with all 625 tests green.smoke:apican't help either: it runsSTAGING=true, which skips Telegram entirely. That's why grammy 1.43 → 1.46 in #312 had to be cleared by hand.The cover
Boots the real
createBot()and pushes realUpdateobjects through it:mongodb-memory-serverbehind it, becauseattachUsergenuinely hits mongo (it isn't injectable fromcreateBot)botInfosupplied sohandleUpdateskipsgetMehydrate()gets a Message-shaped result to wrapThree cases:
/startrouted end to end,attachUserupserting a first-contact user into mongo, and an unknown command still reaching a handler.The assertion is mutation-tested
The obvious version of the
/startcheck — "asendMessagewent out with non-empty text" — passes even withstartFeatureunwired, becauseunhandledFeatureanswers/starttoo. I found that by actually deleting theprotectedBot.use(startFeature)line and watching the test stay green.It now pins the locale text and the disabled link preview, both unique to
buildStartCommandHandler. Re-ran the same mutation:not ok 1, and green again on revert.Bonus: the types trap became a compile error
BOT_INFOis checked asUserFromGetMeat the call site, so a top-level@grammyjs/typesdrifting from grammy's bundled copy now fails typecheck in this file — turning onsupports_join_request_queries, the same field the trap has always keyed on. Writing that literal out is deliberate, not incidental.Cost
628 tests (up from 625); suite wall time unchanged at ~7s.