Tests: dedupe contract helper plumbing#48760
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e5110a8150
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @@ -1,5 +1,5 @@ | |||
| import { describe, expect, it } from "vitest"; | |||
| import { inboundCtxCapture as capture } from "../../../../src/channels/plugins/contracts/inbound-contract-dispatch-mock.js"; | |||
| import { inboundCtxCapture as capture } from "../../../../src/channels/plugins/contracts/inbound-testkit.js"; | |||
There was a problem hiding this comment.
Restore dispatch mock setup for Discord inbound test
Switching this import from inbound-contract-dispatch-mock to inbound-testkit drops the side-effect vi.mock(".../auto-reply/dispatch.js") that used to populate inboundCtxCapture.ctx. In this test file there is no replacement mock, so processDiscordMessage calls the real dispatch path and capture.ctx never gets set, making assertions like expect(capture.ctx).toBeTruthy() fail whenever this test runs.
Useful? React with 👍 / 👎.
Greptile SummaryThis PR is a test/contract-layer refactor that consolidates three thin inbound-capture shim files into The deduplication intent is correct and most of the changes are clean, but the inbound-testkit consolidation introduces two test regressions caused by a missing
The PR author explicitly notes no completed test run was obtained for this slice ("the focused Confidence Score: 2/5
|
| @@ -1,5 +1,5 @@ | |||
| import { describe, expect, it } from "vitest"; | |||
| import { inboundCtxCapture as capture } from "../../../../src/channels/plugins/contracts/inbound-contract-dispatch-mock.js"; | |||
| import { inboundCtxCapture as capture } from "../../../../src/channels/plugins/contracts/inbound-testkit.js"; | |||
There was a problem hiding this comment.
Missing
vi.mock() — capture.ctx will always be undefined
The old inbound-contract-dispatch-mock.ts module contained a module-level vi.mock("../../../auto-reply/dispatch.js", ...) call that was executed as a side effect of importing it. This mock intercepted dispatchInboundMessage and set inboundCtxCapture.ctx on each call.
The new inbound-testkit.ts consolidates all the helper utilities but deliberately omits this vi.mock() call. As a result, dispatch.js is no longer mocked in this test file — there is no vi.mock() here at all. When processDiscordMessage(messageCtx) runs, the real (unmocked) dispatchInboundMessage executes and nothing writes to capture.ctx. Both test assertions will then fail:
expect(capture.ctx).toBeTruthy(); // → capture.ctx is undefined → FAILS
expectInboundContextContract(capture.ctx!); // → called with undefined
The Signal extension test (event-handler.mention-gating.test.ts) correctly handles this by calling vi.mock() directly in the test file and using buildDispatchInboundCaptureMock. The same pattern needs to be applied here:
vi.mock("../../../../src/auto-reply/dispatch.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../../../../src/auto-reply/dispatch.js")>();
return buildDispatchInboundCaptureMock(actual, (ctx) => {
capture.ctx = ctx as MsgContext;
});
});Note the path depth — this test lives under extensions/discord/src/monitor/, four levels from the repo root, so the relative path to dispatch.js differs from the one in inbound-testkit.ts.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/discord/src/monitor/message-handler.inbound-context.test.ts
Line: 2
Comment:
**Missing `vi.mock()` — `capture.ctx` will always be `undefined`**
The old `inbound-contract-dispatch-mock.ts` module contained a module-level `vi.mock("../../../auto-reply/dispatch.js", ...)` call that was executed as a side effect of importing it. This mock intercepted `dispatchInboundMessage` and set `inboundCtxCapture.ctx` on each call.
The new `inbound-testkit.ts` consolidates all the helper utilities but deliberately omits this `vi.mock()` call. As a result, `dispatch.js` is no longer mocked in this test file — there is no `vi.mock()` here at all. When `processDiscordMessage(messageCtx)` runs, the real (unmocked) `dispatchInboundMessage` executes and nothing writes to `capture.ctx`. Both test assertions will then fail:
```
expect(capture.ctx).toBeTruthy(); // → capture.ctx is undefined → FAILS
expectInboundContextContract(capture.ctx!); // → called with undefined
```
The Signal extension test (`event-handler.mention-gating.test.ts`) correctly handles this by calling `vi.mock()` directly in the test file and using `buildDispatchInboundCaptureMock`. The same pattern needs to be applied here:
```typescript
vi.mock("../../../../src/auto-reply/dispatch.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../../../../src/auto-reply/dispatch.js")>();
return buildDispatchInboundCaptureMock(actual, (ctx) => {
capture.ctx = ctx as MsgContext;
});
});
```
Note the path depth — this test lives under `extensions/discord/src/monitor/`, four levels from the repo root, so the relative path to `dispatch.js` differs from the one in `inbound-testkit.ts`.
How can I resolve this? If you propose a fix, please make it concise.* Plugins: share contract test helpers * Channels: collapse inbound contract testkit
* Plugins: share contract test helpers * Channels: collapse inbound contract testkit
* Plugins: share contract test helpers * Channels: collapse inbound contract testkit (cherry picked from commit 64c69c3) # Conflicts: # extensions/discord/src/monitor/message-handler.inbound-context.test.ts # extensions/signal/src/monitor/event-handler.mention-gating.test.ts # src/channels/plugins/contracts/inbound.contract.test.ts # src/plugins/contracts/auth-choice.contract.test.ts # src/plugins/contracts/auth.contract.test.ts # src/plugins/contracts/discovery.contract.test.ts # src/plugins/contracts/loader.contract.test.ts # src/plugins/contracts/registry.ts # test/helpers/dispatch-inbound-capture.ts # test/helpers/inbound-contract-capture.ts # test/helpers/inbound-contract-dispatch-mock.ts
* Plugins: share contract test helpers * Channels: collapse inbound contract testkit (cherry picked from commit 64c69c3) # Conflicts: # extensions/discord/src/monitor/message-handler.inbound-context.test.ts # src/plugins/contracts/auth.contract.test.ts # src/plugins/contracts/discovery.contract.test.ts # src/plugins/contracts/registry.ts # test/helpers/dispatch-inbound-capture.ts # test/helpers/inbound-contract-capture.ts # test/helpers/inbound-contract-dispatch-mock.ts
Summary
Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
None.
Security Impact (required)
Repro + Verification
Environment
Steps
Expected
Actual
inbound-testkit.tsinstead of three thin files.Evidence
Attach at least one:
Human Verification (required)
What you personally verified (not just CI), and how:
origin/main; ranpnpm exec oxlinton the touched cleanup files.origin/mainonly contains the helper-extraction and inbound-testkit collapse.pnpm test -- ...lane again stalled at Vitest startup in this checkout, so I do not have a completed test run for this slice.Review Conversations
Compatibility / Migration
Failure Recovery (if this breaks)
src/plugins/contracts/testkit.ts,src/plugins/contracts/registry.ts, andsrc/channels/plugins/contracts/inbound-testkit.tsplus the replaced import sites.Risks and Mitigations