diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f15e94dc..1ad14ede 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -146,7 +146,7 @@ jobs: env: # Pinned to a commit on stackone-ai-python's main, not the branch, so a Python change never # silently changes what this job grades. Bump it deliberately. - PYTHON_SDK_REF: d76c26663c9141bf106a19d385252da9a8c7e75d + PYTHON_SDK_REF: 05398a3f1e119297beb7e514f92c17601a75583e steps: - name: Check conformance token is configured env: @@ -166,7 +166,7 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: repository: StackOneHQ/sdk-conformance - ref: 4ead1c25bb443ef1fd1986d5f053b2d1475d0e90 + ref: 6aba490ee49b298643e3a0bb9fbbaecf36c0edd7 token: ${{ secrets.CONFORMANCE_REPO_TOKEN }} path: sdk-conformance persist-credentials: false diff --git a/src/tool.ts b/src/tool.ts index 868c2916..322f5096 100644 --- a/src/tool.ts +++ b/src/tool.ts @@ -682,6 +682,7 @@ export class Tools implements Iterable { constructor(tools: BaseTool[]) { this.tools = [...tools]; + warnOnDuplicateNames(this.tools); } /** @@ -705,7 +706,6 @@ export class Tools implements Iterable { * Claude Agent SDK refuses the second outright. */ #uniqueTools(): BaseTool[] { - warnOnDuplicateNames(this.tools); const seen = new Set(); return this.tools.filter((tool) => { if (seen.has(tool.name)) { @@ -951,11 +951,10 @@ export class Tools implements Iterable { /** * Two accounts on one provider serve identically named tools. Every lookup and adapter keeps the - * first one listed — the lowest account id — and drops the rest, so warn that the others are - * unreachable by name: once when the tools are fetched, and again from each adapter that drops - * them. + * first one listed and drops the rest, so warn once, when the collection is built, that the others + * are unreachable by name. */ -export function warnOnDuplicateNames(tools: readonly BaseTool[]): void { +function warnOnDuplicateNames(tools: readonly BaseTool[]): void { const counts = new Map(); for (const tool of tools) { counts.set(tool.name, (counts.get(tool.name) ?? 0) + 1); diff --git a/src/toolsets.test.ts b/src/toolsets.test.ts index 61bc1d96..9d271d1a 100644 --- a/src/toolsets.test.ts +++ b/src/toolsets.test.ts @@ -14,7 +14,7 @@ import { server } from '../mocks/node'; import { FAILED_ACCOUNT_RETRY_MS } from './consts'; import { listMcpTools } from './mcp-client'; import type { McpToolDefinition as ListedTool } from './mcp-client'; -import { StackOneMcpTool, StackOneTool } from './tool'; +import { StackOneMcpTool, StackOneTool, Tools } from './tool'; import type { BaseTool } from './tool'; import { StackOneToolSet } from './toolsets'; import { StackOneAPIError } from './utils/error-stackone-api'; @@ -1099,9 +1099,21 @@ describe('duplicate tool names', () => { expect(Object.keys(aiSdk)).toEqual(expected); expect(aiSdk.hibob_list_employees?.description).toBe('on a'); await expect(tools.toClaudeAgentSdk()).resolves.toBeDefined(); - // Once from fetchTools(), then once from each adapter call that dropped a duplicate. - expect(warnSpy).toHaveBeenCalledTimes(8); - expect(new Set(warnSpy.mock.calls.map(([message]: unknown[]) => message)).size).toBe(1); + // Once from fetchTools(); the adapters drop the duplicate without repeating it. + expect(warnSpy).toHaveBeenCalledTimes(1); + }); + + it('warns when collections fetched separately are merged into one', async () => { + fakeListing(() => [def('hibob_list_employees')]); + const toolset = newToolSet(); + const a = await toolset.fetchTools({ accountIds: ['a'] }); + const b = await toolset.fetchTools({ accountIds: ['b'] }); + expect(warnSpy).not.toHaveBeenCalled(); + + const merged = new Tools([...a, ...b]); + merged.toOpenAI(); + + expect(warnSpy).toHaveBeenCalledTimes(1); }); it('stays quiet when names are unique', async () => { diff --git a/src/toolsets.ts b/src/toolsets.ts index 2e226cc3..a40cbcbd 100644 --- a/src/toolsets.ts +++ b/src/toolsets.ts @@ -23,7 +23,7 @@ import { } from './mcp-client'; import type { EndUserSource, McpToolDefinition } from './mcp-client'; import { cloneJson, toolParametersFromInputSchema } from './schema'; -import { StackOneMcpTool, Tools, warnOnDuplicateNames } from './tool'; +import { StackOneMcpTool, Tools } from './tool'; import type { StackOneTool } from './tool'; import type { ActionResult, @@ -1177,7 +1177,6 @@ export class StackOneToolSet { isAskedFor(tool.name, mode === 'search_execute' ? { actions: options.actions } : options), ); - warnOnDuplicateNames(tools); return new Tools(tools); } catch (error) { // StackOneAPIError carries the HTTP status. Re-wrapping it would throw that away, so a diff --git a/tests/vectors/messages.json b/tests/vectors/messages.json index b5a1d477..7a33528b 100644 --- a/tests/vectors/messages.json +++ b/tests/vectors/messages.json @@ -190,7 +190,7 @@ "python": true, "node": true }, - "notes": "Language-neutral wording: neither SDK's method or parameter names. Emitted once when a fetched collection holds a clashing name, and again by every adapter that keeps the first tool per name and drops the rest: OpenAI, LangChain, Pydantic AI, AI SDK and Claude Agent SDK. Listing order is ascending account id, so the first is the lowest account id's." + "notes": "Language-neutral wording: neither SDK's method or parameter names. Emitted once, when a tool collection holding a clashing name is built: by listing, or by the caller combining collections. The adapters that keep the first tool per name and drop the rest (OpenAI, LangChain, Pydantic AI, AI SDK and Claude Agent SDK) do not repeat it. Listing order is ascending account id, so the first is the lowest account id's." }, { "id": "mcp-timeout",