testing: migrate bot-dm-guard.test.ts → stub HttpClient (comms-e5vm.7) - #14
Merged
Merged
Conversation
Swap the bot-dm-guard wrapper tests off the real-socket Bun.serve realm (startTestRealm + FetchHttpClient) onto the owned-fake stub HttpClient via effectTest, matching the Tier-2 pattern proved in comms-e5vm.2. The wrapper's job is a decision — intercept POST /messages type=private and reject when every non-self recipient is a bot — so every case here is guard-wrapper logic, which is Tier-2 owned-fake territory, not a live-contract duplicate: real Zulip can't be driven to bot↔bot rejection, and the allow-cases assert the guard's decision to forward, not that the forward succeeds. All 12 migrate; none deleted. No TestClock — no timing/retry here.
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.
Tier-2 migration (epic comms-e5vm). Moves
packages/zulip/bot-dm-guard.test.tsoff the real-socketBun.serverealm (startTestRealm+FetchHttpClient) onto the owned-fake stub HttpClient viaeffectTest, following the pattern proved in comms-e5vm.2 (#12).What changed
The bot-dm-guard wrapper's job is a decision: intercept
POST /messageswithtype=privateand reject when every non-self recipient is a bot, otherwise forward. The old tests wired the innerZulipHttpagainst an in-processBun.serverealm purely to give the wrapper a forward target. They now build that innerZulipHttpovermakeStubHttpClient().clientinstead — no socket, deterministic.buildHttp(stub)providesstub.clientforHttpClient.HttpClient.inner.post.stub.respond(...); assertions countstub.captured.TestClock: this file has no timing/retry, soeffectTesttakes nolayer.On deletion
The epic says happy-path cases that merely duplicate the live contract get deleted, not migrated. None here qualify — all 12 are guard-wrapper logic (bot↔bot rejection, the allow-branch decisions, parse-failure rejects, GET/DELETE/non-
/messagespass-through transparency). The live contract can't even express bot↔bot rejection, and the allow-cases assert the guard's decision to forward, not that the forward succeeds. So all 12 migrate; none are deleted (deleting any would reduce guard coverage).Out of scope
Other Tier-2 files (
adapter.test.tscomms-e5vm.3,http.test.tscomms-e5vm.8), the Tier-3 real-socket teardown test (comms-4lz5), and the stateful-fake deletion (comms-e5vm.6).startTestRealm/registerRealmHooksremain — still consumed by the not-yet-migrated files.