Repository navigation
test(react-core): make slot and drill-down tests fail when the behavior breaks - #8202
Merged
Merged
Conversation
…lots break Most of these tests passed with slot overrides switched off: they checked querySelector results with toBeDefined (null passes), hid assertions behind if (el), or asserted nothing. They now assert on the rendered element, and duplicates of CopilotChatInput.test.tsx are removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sts fail when slots break Every message view slot test passed with slot overrides switched off, because assertions sat behind if (el) or checked toBeDefined on null. They now assert on the rendered messages. The nested button matrix lives in the assistant and user message files only, and duplicates of CopilotChatAssistantMessage.test.tsx are removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s fail when slots break Assertions hid behind if (el) or checked toBeDefined on null, so they passed with slot overrides switched off. The user message tests now cover every slot in each form against the rendered element, and the loading state test checks which pill is busy instead of counting buttons. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… fail when slots break Most of these passed with slot overrides switched off. The width tests only checked that the style named the CSS variable, which the default width also sets, and one close-button test asserted its own handler. They now check the rendered element, the variable's value, and that the bound close action closes the modal. The chat view slot matrix the popup and sidebar repeated is reduced to one forwarding test each. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…iew slot breaks Most passed with slot overrides switched off, and several only checked that the container had a first child, which holds even when CopilotChat renders nothing. They now assert on the chat view, and smoke tests covered by the other CopilotChat files are removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…en wiring breaks Most assertions sat behind if (el), so they passed when the element was missing. The add menu click never fired (the button is disabled without menu items) and the submit test looked for a form that does not exist. The tests now find each element by test id and assert unconditionally; drill-downs already covered per component are removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
querySelector and queryBy return null, not undefined, so expect(el).toBeDefined() passed whether or not the element rendered. The class slot checks in CopilotChatAssistantMessage.test.tsx passed with slot overrides switched off. They now assert not.toBeNull, and the tool rendering waitFor waits for the element instead of resolving at once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ot fail The wildcard result check sat behind if (el) and never ran: the test made a new tool call id for the result, so it never matched the call. The forwarded-tools test accepted an empty tools array. Two renderSlot tests fell back to asserting the default component, and the memo test counted two separate renders. Each now fails when the behavior it names breaks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ebar slot tests The toggleButton slot takes a forwardRef button, so a plain function component did not type-check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review: 1
Please check the settings in the CodeRabbit UI or the
|
Contributor
|
Size Change: 0 B Total Size: 2.39 MB ℹ️ View Unchanged
|
@copilotkit/a2ui-renderer
@copilotkit/agentcore-runner
@copilotkit/angular
@copilotkit/channels
@copilotkit/channels-core
@copilotkit/channels-discord
@copilotkit/channels-intelligence
@copilotkit/channels-slack
@copilotkit/channels-teams
@copilotkit/channels-ui
@copilotkit/channels-whatsapp
@copilotkit/core
@copilotkit/intelligence-langgraph
@copilotkit/intelligence-mastra
@copilotkit/learning
@copilotkit/markdown
@copilotkit/mcp-apps-renderer
@copilotkit/react-core
@copilotkit/react-native
@copilotkit/runtime
@copilotkit/sdk-js
@copilotkit/shared
@copilotkit/sqlite-runner
@copilotkit/voice
@copilotkit/vue
@copilotkit/web-components
@copilotkit/web-inspector
commit: |
Merged
4 tasks
AlemTuzlak
added a commit
that referenced
this pull request
Nov 4, 2026
…o that check nothing (#8204) Three runtime tests passed only because any `Response` passed. None of them reached the code it names. This PR makes them reach it and assert the status. It also deletes two tests that check nothing. No production code changes. Part of PE-1086. v1 and the GraphQL runtime are already gone from `2.0.0` (#8084, #8103), so nothing in runtime was skipped for pending removal. ## What does this PR do? ### Rewritten | Test | What was wrong | Evidence | |---|---|---| | `fetch-handler.test.ts` › "returns 500 JSON error for unhandled errors" | The body had no `messages`, so the request got a **400** from validation. The agent never ran. The test only checked `toBeInstanceOf(Response)`. | The probe showed a 400 `Invalid request body`. Mutation **M-A** (the "Failed to run agent" response in `handle-run.ts` returns 200 instead of 500): the old test passes, the new one fails. | | `fetch-handler-validation.test.ts` › "CORS headers present on 500 error responses" | Same body problem: it got a 400, not a 500. | Mutation **M-A**: the old test passes, the new one fails. | | `code-review-fixes.test.ts` › "single-route agent/run works after onBeforeHandler replaces request" | The test's own hook built `new Request(..., { body: stream })` without `duplex`, and that throws in Node. The handler returned a **500** `internal_error` and `agent/run` never ran. | `onError` showed `TypeError: RequestInit: duplex option is required`. Mutation **M-B** (single-route dispatch sends `{}` instead of `methodCall.body` for `agent/run`): the old test passes, the new one fails. | Each rewritten test now sends a valid run body and asserts the status it names: 500 with `{"error":"Failed to run agent","message":"boom"}`, 500 with CORS headers, or 200 with `text/event-stream`. ### Deleted | Test | Why | |---|---| | `mcp-clients.test.ts` › "type compatibility: @ai-sdk/mcp MCPClient satisfies MCPClientProvider" | It cast `tools()` with `as unknown as` and ended with `expect(true).toBe(true)`, so it checked nothing at runtime or compile time. Without the cast, `tsc` rejects the claim (see below). | | `mcp-apps-middleware-integration.test.ts` › "can be created with mcpServers config pointing at MCPMock URL" | It asserted that `new MCPAppsMiddleware(...)` is an instance of `MCPAppsMiddleware`. That is always true. The other tests in the file use the middleware. | ### Finding for a follow-up (not fixed here) An `@ai-sdk/mcp` `MCPClient` is **not** assignable to `MCPClientProvider`. Its `tools()` returns MCP tools whose `inputSchema` is `FlexibleSchema<unknown>`, and that does not fit the `ai` `ToolSet`. A user who passes a real `MCPClient` to `mcpClients` gets a type error. The deleted test hid this with a cast. This PR changes tests only, so the type stays as it is. ## Related PRs and Issues - PE-1086 (Linear) - react-core part: #8202 ## Checklist - [ ] I have read the [Contribution Guide](https://github.com/copilotkit/copilotkit/blob/master/CONTRIBUTING.md) - [ ] If the PR changes or adds functionality, I have updated the relevant documentation (not applicable: tests only) - [ ] If the PR contains a breaking change, the title has `!` (not applicable) - [ ] "Allow edits by maintainers" is checked ## Testing **Commands run** - `nx run @copilotkit/runtime:test`: 184 files and 3013 tests pass, 4 skipped. - `nx run @copilotkit/runtime:check-types --exclude-task-dependencies`: passes. - `oxfmt` and the oxlint gate on every changed file: pass. - Mutations M-A and M-B, applied and reverted locally. Nothing from them is committed. **Manual test** 1. In `packages/runtime/src/runtime/handlers/handle-run.ts`, change `status: 500` in the "Failed to run agent" response to `status: 200`. 2. Run `pnpm vitest run src/runtime/__tests__/fetch-handler.test.ts` in `packages/runtime`. 3. On `2.0.0`, all tests pass. On this branch, "returns 500 JSON error for unhandled errors" fails. 4. Revert the change. **How this PR makes testing easy** The changes are tests only. The mutation steps above reproduce the evidence. ## Risk / rollback Low. Only test files change. To undo, revert the PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.
Most react-core slot tests passed with slot overrides switched off. This PR rewrites them so that they fail when a slot breaks. It also deletes tests that guard nothing. No production code changes.
Part of PE-1086. v1 and the GraphQL runtime are already gone from
2.0.0(#8084, #8103), so nothing in react-core was skipped for pending removal.What does this PR do?
The rot came from four patterns:
expect(container.querySelector(...)).toBeDefined().querySelectorandqueryBy*returnnull, andnullis defined, so the check always passes.if (el) { expect(...) }. When the element is missing, the test asserts nothing.How I measured it
I applied each mutation locally, ran the tests, and reverted it. Nothing from the mutations is committed.
renderSlotElementinlib/slots.tsxalways renders the default component, so every slot override is ignored.resolveSlotComponentinCopilotChatMessageView.tsxalways returns the default. The message view resolves the assistant and user message slots with this function, not withrenderSlot.Before this PR, 341 of 427 tests in the slot files and
lib/__tests__passed under M-slots-off.Per file
"Survive" = the test still passes under M-slots-off + M-resolve. After this PR, every survivor tests something that is not a slot override: positioning, children render props, labels, root
className, or width.CopilotChatInput.slots.e2etoolsMenu). Duplicates ofCopilotChatInput.test.tsxremoved.CopilotChatView.slots.e2eCopilotChatMessageView.slots.e2eCopilotChat.raw-event-feedback.test.tsx.CopilotChatAssistantMessage.slots.e2emarkdownRenderernever forwardsdata-testid, so that test now checks an objectclassName. ThetoolCallsViewstring-slot test is deleted:CopilotChatToolCallsViewignoresclassName, so nothing is observable.CopilotChatUserMessage.slots.e2eit.each.CopilotChatSuggestionView.slots.e2eCopilotModalHeader.slots.e2eonClickcloses the modal.CopilotPopupView.slots.e2eCopilotSidebarView.slots.e2eCopilotChat.slots.e2econtainer.firstChildsmoke tests (they pass whenCopilotChatrenders nothing), a test that asserted its own mock was not called, and a test with no assertion.CopilotChatView.onClick.e2e<form>that does not exist, so it never asserted. The add-menu click never fired because the button is disabled without menu items.CopilotChatAssistantMessage.testtoBeDefinedon DOM queriesnot.toBeNull()classNameprop.CopilotChatInput.test,CopilotChatToolRendering.e2etoBeDefinedon DOM queriesnot.toBeNull()/getByTestIdwaitFor(() => expect(queryByTestId(..)).toBeDefined())resolved at once. It now waits for the element.use-frontend-tool.e2etestId("tc1")was called twice, so the result never matched the call. The forwarded-tools test accepted an empty array. MutationaddTool→ no-op: the old test passes, the new one fails.lib/__tests__/renderSlot.testTyped props replace most
as anycasts in the rewritten tests.Related PRs and Issues
Checklist
!(not applicable)Testing
Commands run
nx run @copilotkit/react-core:test: 197 files and 2369 tests pass, 35 skipped (unchangedskipIfgates).nx run @copilotkit/react-core:check-types --exclude-task-dependencies: passes.oxfmtand the oxlint gate on every changed file: pass.Manual test
packages/react-core/src/lib/slots.tsx, addreturn React.createElement(DefaultComponent, props);as the first line ofrenderSlotElement.pnpm vitest run src/components/chat/__tests__/CopilotChatInput.slots.e2e.test.tsxinpackages/react-core.2.0.0, 42 of 48 tests pass. On this branch, 26 of 36 fail.How this PR makes testing easy
The changes are tests only. The mutation steps above reproduce the numbers in the table.
Risk / rollback
Low. Only test files change. If a rewritten test turns out to be flaky, revert this PR or that one commit. Each commit covers one group of files.
🤖 Generated with Claude Code