Skip to content

testing: migrate bot-dm-guard.test.ts → stub HttpClient (comms-e5vm.7) - #14

Merged
GraemeF merged 1 commit into
mainfrom
comms-e5vm.7
Jun 13, 2026
Merged

GraemeF merged 1 commit into
mainfrom
comms-e5vm.7

Conversation

@GraemeF

@GraemeF GraemeF commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Tier-2 migration (epic comms-e5vm). Moves packages/zulip/bot-dm-guard.test.ts off the real-socket Bun.serve realm (startTestRealm + FetchHttpClient) onto the owned-fake stub HttpClient via effectTest, following the pattern proved in comms-e5vm.2 (#12).

What changed

The bot-dm-guard wrapper's job is a decision: intercept POST /messages with type=private and reject when every non-self recipient is a bot, otherwise forward. The old tests wired the inner ZulipHttp against an in-process Bun.serve realm purely to give the wrapper a forward target. They now build that inner ZulipHttp over makeStubHttpClient().client instead — no socket, deterministic.

  • buildHttp(stub) provides stub.client for HttpClient.HttpClient.
  • Reject cases need no canned response — the guard short-circuits before inner.post.
  • Allow / pass-through cases register stub.respond(...); assertions count stub.captured.
  • No TestClock: this file has no timing/retry, so effectTest takes no layer.

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-/messages pass-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.ts comms-e5vm.3, http.test.ts comms-e5vm.8), the Tier-3 real-socket teardown test (comms-4lz5), and the stateful-fake deletion (comms-e5vm.6). startTestRealm / registerRealmHooks remain — still consumed by the not-yet-migrated files.

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.
@GraemeF
GraemeF merged commit c21b32e into main Jun 13, 2026
2 checks passed
@GraemeF
GraemeF deleted the comms-e5vm.7 branch June 13, 2026 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant