test: cover the whole-word chat trigger conversions (refs #49439) - #25
Merged
Conversation
Commit 86c924e converted twelve bare-substring triggers in TwitchBot._handle_triggers to the _word_in whole-word helper and shipped with no test — nothing under tests/ imported twitch at all. Add tests/test_triggers.py, one parametrized case per converted trigger, each asserting three things: the old bare-substring check does match the false-positive message (negative control, so the case cannot pass vacuously), the fixed code sends nothing for that message, and the fixed code still responds to a legitimate whole-word message. Run against 86c924e^ all twelve cases fail; against HEAD all pass.
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.
What this is
tests/test_triggers.py— one parametrized regression case per trigger convertedin 86c924e, exercising the real
TwitchBot._handle_triggerspath with thesocket-facing methods stubbed.
Why it has a home
86c924e ("convert remaining bare-substring chat triggers to whole-word matching",
refs #49439) touched
twitch.pyonly: 12 insertions, 12 deletions, no tests.tests/has two commits in its entire history, both initial setup, and nothingunder
tests/importedtwitchat all — so twelve behavioural conversionsshipped with zero regression coverage while CI happily ran
pytest tests/ -v.Each case asserts three things:
false-positive message, so the case cannot pass vacuously and the bug being
fixed is demonstrably real.
Changed from the scratch harness
This started as a standalone verification script run while #49439 was being
fixed. Converting it to a pytest test:
sys.path.insert("/home/…/AvicBotChat")— pytest's rootdiralready resolves the import, the same way
tests/test_irc.pyimportsavicbotwikimedia.twitch.time.sleep = lambda …and thesend_message/_sing_major_generalstubs with a function-scopedmonkeypatchfixture. As written they leaked into any test that ran later inthe session. The delays are zeroed via
MESSAGE_DELAY/LONG_MESSAGE_DELAYrather than by stubbing
time.sleep, so the stdlib is never touched.CASESis now@pytest.mark.parametrizewith the trigger word as the test id,so a failure names the trigger.
"<MAJOR-GENERAL>"in-band sentinel became its ownsings_major_generalparametrize field and its own assertion branch.
Test result
Full suite, current HEAD (22 pre-existing tests still pass, 12 new):
Proof it discriminates
twitch.pychecked out at86c924e^(the revision immediately before the fix),test file unchanged — all twelve cases fail:
twitch.pyrestored, suite green again (34 passed). No source file is modifiedby this PR — only
tests/test_triggers.pyis added.Lint
Local ruff is 0.15.20; CI pins 0.15.22. CI's own Lint job passes on this branch,
so the pinned version agrees.
CI on this branch
Both jobs green (
LintandTests), and the Tests job confirms the suite on thePython version CI actually uses:
Not verified
send_message, so nothing about the actual IRC socket path iscovered — this is a trigger-matching test, not an integration test.