Skip to content

[chat] Add chat/test entrypoint for consumer test utilities#352

Draft
matchai wants to merge 9 commits intomainfrom
matchai/chat-testing-exports
Draft

[chat] Add chat/test entrypoint for consumer test utilities#352
matchai wants to merge 9 commits intomainfrom
matchai/chat-testing-exports

Conversation

@matchai
Copy link
Copy Markdown
Member

@matchai matchai commented Apr 9, 2026

Exposes the existing internal test utilities via a chat/test entrypoint so consumers can create type-safe Thread and Message instances without fromPartial or manual mock construction. When the SDK's interfaces change, these factories are updated in the same release — consumers just bump the dependency.

createTestThread constructs a real ThreadImpl backed by a mock adapter with spyable methods. Accepts adapter as a string (name) or object (name + overrides like botUserId). All ThreadImplConfigWithAdapter fields are accepted as optional overrides.

createTestMessage constructs a real Message instance. Only text is required — id, author, raw, and any MessageData fields are optional with sensible defaults.

import { createTestThread, createTestMessage } from "chat/test";

const thread = createTestThread({
  adapter: "slack",
  id: "T123:C456",
  channelId: "C456",
});

const message = createTestMessage({
  text: "deploy my app",
  author: { userId: "U789" },
  raw: { team_id: "T123" },
});

// Adapter-specific overrides
const slackThread = createTestThread({
  adapter: { name: "slack", botUserId: "B123" },
});

// All ThreadImplConfig fields accepted
const dmThread = createTestThread({
  adapter: "discord",
  isDM: true,
  channelVisibility: "private",
});

vitest is an optional peer dependency — consumers need it installed for the vi.fn() spies.

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chat Ready Ready Preview, Comment, Open in v0 Apr 9, 2026 3:22am
chat-sdk-nextjs-chat Ready Ready Preview, Comment, Open in v0 Apr 9, 2026 3:22am

- Fix channelId bug: counter now always increments per call
- Un-export ThreadImplConfigWithAdapter, define standalone CreateTestThreadOptions
- Split adapter into adapter?: string + adapterOverrides?: Partial<Adapter>
- Return { thread, mockAdapter, mockState } instead of Object.assign
- Shrink public surface: only export createTestThread, createTestMessage, and types
…ions from it

Eliminates field duplication between ThreadImplConfigWithAdapter,
ThreadImplConfigLazy, and CreateTestThreadOptions by extracting
shared fields into a stable public BaseThreadOptions type.
Build overrides object conditionally so metadata and author keys
are only present when explicitly provided by the caller.
- Un-export BaseThreadOptions (stays as internal dedup only)
- Define CreateTestThreadOptions explicitly, no derived types
- Return Thread interface instead of ThreadImpl in TestThread
- No internal types leak through the generated .d.ts
Not needed for chat/test. Keep the PR strictly scoped to the
new entrypoint without touching existing internal types.
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