Files
wehub-resource-sync 0d3cb498a3
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Waiting to run
Test and Publish Multi-arch Docker Image / test (push) Waiting to run
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Blocked by required conditions
Validate Renovate Config / Validate Renovate Configuration (push) Waiting to run
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:24:08 +08:00

133 lines
3.4 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
getToolNameFromAttributes,
TOOL_ARGUMENT_ATTRIBUTE_KEYS,
TOOL_NAME_ATTRIBUTE_KEYS,
} from '../../src/tracing/toolAttributes';
describe('getToolNameFromAttributes', () => {
it('returns undefined when attributes are missing', () => {
expect(getToolNameFromAttributes(undefined)).toBeUndefined();
});
it('returns undefined when no recognized keys are present', () => {
expect(getToolNameFromAttributes({ foo: 'bar' })).toBeUndefined();
});
it('returns Vercel AI SDK tool span names', () => {
expect(
getToolNameFromAttributes({
'ai.toolCall.name': 'lookup_customer',
}),
).toBe('lookup_customer');
});
it('prefers generic tool.name over vendor-specific keys', () => {
expect(
getToolNameFromAttributes({
'tool.name': 'search_orders',
'ai.toolCall.name': 'lookup_customer',
}),
).toBe('search_orders');
});
it('recognizes function.name', () => {
expect(
getToolNameFromAttributes({
'function.name': 'compose_reply',
}),
).toBe('compose_reply');
});
it('trims whitespace from values', () => {
expect(
getToolNameFromAttributes({
'tool.name': ' trimmed_tool ',
}),
).toBe('trimmed_tool');
});
it('skips empty string values in favor of later recognized keys', () => {
expect(
getToolNameFromAttributes({
'tool.name': ' ',
'ai.toolCall.name': 'fallback_tool',
}),
).toBe('fallback_tool');
});
it('skips non-string values', () => {
expect(
getToolNameFromAttributes({
'tool.name': 42,
'ai.toolCall.name': 'fallback_tool',
}),
).toBe('fallback_tool');
});
it('does not match arbitrary attributes whose keys are not in the allowlist', () => {
expect(
getToolNameFromAttributes({
'workflow.tool': 'should_not_match',
'tool.description': 'not a tool name',
}),
).toBeUndefined();
});
});
describe('tool attribute key tables', () => {
it('exposes the expected set of tool-name keys', () => {
expect([...TOOL_NAME_ATTRIBUTE_KEYS].sort()).toEqual([
'agent.tool',
'agent.toolName',
'agent.tool_name',
'ai.toolCall.name',
'codex.mcp.tool',
'function.name',
'function_name',
'gen_ai.tool.name',
'tool',
'tool.name',
'tool_name',
]);
});
it('exposes the expected set of tool-argument keys', () => {
expect([...TOOL_ARGUMENT_ATTRIBUTE_KEYS].sort()).toEqual([
'agent.tool.args',
'agent.tool.arguments',
'agent.tool.input',
'ai.toolCall.args',
'ai.toolCall.arguments',
'ai.toolCall.input',
'args',
'arguments',
'codex.mcp.args',
'codex.mcp.arguments',
'codex.mcp.input',
'function.args',
'function.arguments',
'function.input',
'function_args',
'function_arguments',
'gen_ai.tool.args',
'gen_ai.tool.arguments',
'gen_ai.tool.call.args',
'gen_ai.tool.call.arguments',
'gen_ai.tool.input',
'input',
'tool.args',
'tool.arguments',
'tool.input',
'tool_args',
'tool_arguments',
'tool_input',
]);
});
it('has no duplicate keys in either table', () => {
expect(new Set(TOOL_NAME_ATTRIBUTE_KEYS).size).toBe(TOOL_NAME_ATTRIBUTE_KEYS.length);
expect(new Set(TOOL_ARGUMENT_ATTRIBUTE_KEYS).size).toBe(TOOL_ARGUMENT_ATTRIBUTE_KEYS.length);
});
});