-
Notifications
You must be signed in to change notification settings - Fork 190
test: Pin sync/task tool-call contracts before dispatch dedup #1073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jirispilka
wants to merge
2
commits into
master
Choose a base branch
from
claude/deduplicate-sync-task-paths-duv3zq
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+412
−128
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import { InMemoryTaskStore } from '@modelcontextprotocol/sdk/experimental/tasks/stores/in-memory.js'; | ||
|
|
||
| import type { ALLOWED_TASK_TOOL_EXECUTION_MODES } from '../../../src/const.js'; | ||
| import type { ActorsMcpServer } from '../../../src/mcp/server.js'; | ||
| import type { ActorsMcpServerOptions, InternalToolArgs, ToolEntry, ToolInputSchema } from '../../../src/types.js'; | ||
| import { TOOL_TYPE } from '../../../src/types.js'; | ||
| import { compileSchema } from '../../../src/utils/ajv.js'; | ||
|
|
||
| /** | ||
| * Signature of an SDK request handler reached via the private `_requestHandlers` map. The | ||
| * `mcp.server.*` tests drive these handlers directly (no transport, no `server.request()`). | ||
| */ | ||
| export type HandlerFn = ( | ||
| req: Record<string, unknown>, | ||
| extra: Record<string, unknown>, | ||
| ) => Promise<Record<string, unknown>>; | ||
|
|
||
| /** | ||
| * Returns the real request handler the SDK registered for `method` (e.g. 'tools/call', | ||
| * 'tasks/result'), reached through the server's private `_requestHandlers` map so a test can invoke | ||
| * it directly. Throws if the handler is not registered. This reach into an SDK-internal seam is | ||
| * centralized here so an SDK upgrade only needs one fix. | ||
| */ | ||
| export function getRequestHandler(server: unknown, method: string): HandlerFn { | ||
| // eslint-disable-next-line no-underscore-dangle | ||
| const handler = (server as { server: { _requestHandlers: Map<string, HandlerFn> } }).server._requestHandlers.get( | ||
| method, | ||
| ); | ||
| if (!handler) throw new Error(`Handler "${method}" not registered`); | ||
| return handler; | ||
| } | ||
|
|
||
| /** | ||
| * Constructs a real `ActorsMcpServer` backed by an `InMemoryTaskStore`, runs `run` against it, and | ||
| * always closes it. Defaults match the existing `mcp.server.*` tests (telemetry off, placeholder | ||
| * token); pass `options` to override (e.g. telemetry on with no token for the shape tests). | ||
| */ | ||
| export async function withServer<T>( | ||
| run: (server: ActorsMcpServer) => Promise<T>, | ||
| options?: Partial<ActorsMcpServerOptions>, | ||
| ): Promise<T> { | ||
| const { ActorsMcpServer } = await import('../../../src/mcp/server.js'); | ||
| const server = new ActorsMcpServer({ | ||
| taskStore: new InMemoryTaskStore(), | ||
| setupSigintHandler: false, | ||
| telemetry: { enabled: false }, | ||
| token: 'fake-token', | ||
| ...options, | ||
| }); | ||
| try { | ||
| return await run(server); | ||
| } finally { | ||
| await server.close(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * A synthetic internal tool whose `call` throws `error` (default: a plain `Error('boom')`), so | ||
| * dispatch falls through to the outer catch. An empty input schema validates against `{}`. Set | ||
| * `taskSupport` to make the tool eligible for the task path (it otherwise fails the pre-dispatch gate). | ||
| */ | ||
| export function makeThrowingTool( | ||
| options: { name?: string; error?: unknown; taskSupport?: (typeof ALLOWED_TASK_TOOL_EXECUTION_MODES)[number] } = {}, | ||
| ): ToolEntry { | ||
| const { name = 'test-throwing-tool', error = new Error('boom'), taskSupport } = options; | ||
| return { | ||
| type: TOOL_TYPE.INTERNAL, | ||
| name, | ||
| description: 'throws', | ||
| inputSchema: { type: 'object', properties: {} } as ToolInputSchema, | ||
| ajvValidate: compileSchema({ type: 'object', properties: {} }), | ||
| ...(taskSupport ? { execution: { taskSupport } } : {}), | ||
| call: async (_toolArgs: InternalToolArgs) => { | ||
| throw error; | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * A synthetic internal tool that records what the server passed into `call` (whether it ran, and the | ||
| * `progressTracker` it received). Generalizes to any "did the server pass X to the tool?" assertion. | ||
| */ | ||
| export function makeRecorderTool(name: string): { | ||
| tool: ToolEntry; | ||
| received: { called: boolean; progressTracker: InternalToolArgs['progressTracker'] | undefined }; | ||
| } { | ||
| const received: { called: boolean; progressTracker: InternalToolArgs['progressTracker'] | undefined } = { | ||
| called: false, | ||
| progressTracker: undefined, | ||
| }; | ||
| const tool: ToolEntry = { | ||
| type: TOOL_TYPE.INTERNAL, | ||
| name, | ||
| description: 'recorder tool for progress wiring tests', | ||
| inputSchema: { type: 'object', properties: {}, additionalProperties: true }, | ||
| ajvValidate: Object.assign(() => true, { errors: null }) as unknown as ToolEntry['ajvValidate'], | ||
| paymentRequired: false, | ||
| annotations: {}, | ||
| call: async (toolArgs: InternalToolArgs) => { | ||
| received.called = true; | ||
| received.progressTracker = toolArgs.progressTracker; | ||
| return { content: [{ type: 'text', text: 'ok' }] }; | ||
| }, | ||
| } as ToolEntry; | ||
| return { tool, received }; | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit (Claude): the dynamic
await import(...)isn't needed — none of the four consumer suites usevi.mockon this module, and the file already type-importsActorsMcpServer. Looks like cruft carried over from the oldprogress_wiringharness; a static value import is simpler.