Skip to content

Commit eddff6d

Browse files
BenTaylorDevclaude
andcommitted
test(react-core): move threadId-propagation test out of the hooks dir
The previous regression (CopilotKit#5041, shared root cause with CopilotKit#4739) slipped through because the original coverage (use-agent-thread-isolation.test.tsx) lived next to the per-thread-cloning feature and was deleted alongside it when cloning was reverted. The invariant outlived the feature but the tests didn't. Relocate to packages/react-core/src/__tests__/ and rename as a contract test so future implementation swaps (cloning, effect, prop drilling, context) keep it in scope. Tightened the header docstring to spell out the invariant and the reason for the placement. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d1506ec commit eddff6d

1 file changed

Lines changed: 23 additions & 14 deletions

File tree

packages/react-core/src/v2/hooks/__tests__/use-agent-threadid-sync.test.tsx renamed to packages/react-core/src/__tests__/threadid-propagation.contract.test.tsx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,38 @@ import React from "react";
22
import { render, act } from "@testing-library/react";
33
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
44
import type { AbstractAgent } from "@ag-ui/client";
5-
import { useCopilotKit } from "../../context";
6-
import { useAgent } from "../use-agent";
7-
import { CopilotChatConfigurationProvider } from "../../providers/CopilotChatConfigurationProvider";
5+
import { useCopilotKit } from "../v2/context";
6+
import { useAgent } from "../v2/hooks/use-agent";
7+
import { CopilotChatConfigurationProvider } from "../v2/providers/CopilotChatConfigurationProvider";
88
import { CopilotKitCoreRuntimeConnectionStatus } from "@copilotkit/core";
99

10-
vi.mock("../../context", () => ({
10+
vi.mock("../v2/context", () => ({
1111
useCopilotKit: vi.fn(),
1212
}));
1313

1414
const mockUseCopilotKit = useCopilotKit as ReturnType<typeof vi.fn>;
1515

1616
/**
17-
* Regression coverage for issue #5041 (and the same root cause behind #4739):
18-
* <CopilotKit threadId={x}> flows into CopilotChatConfigurationProvider, but
19-
* the underlying ProxiedCopilotRuntimeAgent was never having `agent.threadId`
20-
* set from that value. The AbstractAgent constructor auto-mints a UUID, so
21-
* outbound /agent/run, /agent/connect, /agent/stop requests carried a UUID
22-
* that diverged from what app code read via useThreads/useCopilotChatConfig.
17+
* Contract-level regression coverage for the threadId-propagation invariant.
2318
*
24-
* The fix wires useAgent to sync `agent.threadId` from the chat configuration
25-
* when `hasExplicitThreadId` is true. This file pins that behavior so the
26-
* propagation can't silently regress again (as it did when per-thread cloning
27-
* was removed in May 2026).
19+
* Lives at the package root (src/__tests__) rather than next to any one
20+
* implementation site on purpose: the previous regression (issue #5041, root
21+
* cause shared with #4739) slipped through because the original coverage
22+
* (use-agent-thread-isolation.test.tsx, 333 lines) lived next to the
23+
* per-thread-cloning feature and was deleted alongside it in May 2026 when
24+
* cloning was reverted. The threadId-propagation invariant survived the
25+
* feature change but its tests didn't.
26+
*
27+
* The invariant under test: a caller-supplied threadId (via <CopilotKit>,
28+
* <ThreadsProvider>, or <CopilotChatConfigurationProvider>) MUST end up on
29+
* the underlying agent's `threadId` field, because ProxiedCopilotRuntimeAgent
30+
* uses that field to address /agent/run, /agent/connect, /agent/stop. Without
31+
* it the agent ships its own auto-minted UUID and the backend sees a different
32+
* thread than the app code reads via useThreads/useCopilotChatConfiguration.
33+
*
34+
* This file should outlive any specific implementation strategy (cloning,
35+
* effect-based sync, prop drilling, context bridge). If you change the
36+
* mechanism, keep this contract.
2837
*/
2938
describe("useAgent → agent.threadId sync from chat configuration", () => {
3039
let mockCopilotkit: {

0 commit comments

Comments
 (0)