Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2import { SkillLimitError } from '@tanstack/ai'
3import {
4 codeExecutionTool,
5 convertCodeExecutionToolToAdapterFormat,
6 readCodeExecutionSkills,
7} from '../src/tools/code-execution-tool'
8
9const config = {
10 type: 'code_execution_20250825',
11 name: 'code_execution',
12} as const
13
14describe('codeExecutionTool', () => {
15 it('converts to the bare SDK tool config (skills are NOT in the wire tool)', () => {
16 const tool = codeExecutionTool(config, {
17 skills: [{ type: 'anthropic', skill_id: 'pptx', version: 'latest' }],
18 })
19 expect(convertCodeExecutionToolToAdapterFormat(tool)).toEqual(config)
20 })
21
22 it('exposes attached skills via readCodeExecutionSkills', () => {
23 const tool = codeExecutionTool(config, {
24 skills: [{ type: 'anthropic', skill_id: 'pptx', version: 'latest' }],
25 })
26 expect(readCodeExecutionSkills(tool)).toEqual([
27 { type: 'anthropic', skill_id: 'pptx', version: 'latest' },
28 ])
29 })
30
31 it('returns undefined skills when none attached', () => {
32 expect(readCodeExecutionSkills(codeExecutionTool(config))).toBeUndefined()
33 })
34
35 it('rejects more than 8 skills', () => {
36 const skills = Array.from({ length: 9 }, (_, i) => ({
37 type: 'anthropic' as const,
38 skill_id: `s${i}`,
39 }))
40 expect(() => codeExecutionTool(config, { skills })).toThrow(/at most 8/i)
41 try {
42 codeExecutionTool(config, { skills })
43 } catch (err) {
44 expect(err).toBeInstanceOf(SkillLimitError)
45 const e = err as SkillLimitError
46 expect(e.provider).toBe('anthropic')
47 expect(e.path).toBe('native')
48 expect(e.allowed).toBe(8)
49 expect(e.actual).toBe(9)
50 expect(e.offending).toHaveLength(9)
51 }
52 })
53
54 it('rejects an empty skill_id', () => {
55 expect(() =>
56 codeExecutionTool(config, {
57 skills: [{ type: 'anthropic', skill_id: '' }],
58 }),
59 ).toThrow(/between 1 and 64|skill_id/i)
60 })
61
62 it('rejects a skill_id longer than 64 characters', () => {
63 expect(() =>
64 codeExecutionTool(config, {
65 skills: [{ type: 'anthropic', skill_id: 'a'.repeat(65) }],
66 }),
67 ).toThrow(/between 1 and 64|skill_id/i)
68 })
69
70 it('accepts a 64-character skill_id (boundary)', () => {
71 expect(() =>
72 codeExecutionTool(config, {
73 skills: [{ type: 'anthropic', skill_id: 'a'.repeat(64) }],
74 }),
75 ).not.toThrow()
76 })
77})