/** * Unit tests for CodeExecutor schema and tool definition. * * Validates the execute_code tool exposes a minimal raw-execution schema — * `{ lang, code, args }`. Higher-level workflows (versioning, code_id, * old_str/new_str edits) are consumer concerns (e.g. ranger's * codeEditWrapper) and must NOT appear in this schema. */ import { CodeExecutionToolSchema, CodeExecutionToolDescription, CodeExecutionToolName, CodeExecutionToolDefinition, } from '../CodeExecutor'; describe('CodeExecutionToolSchema', () => { it('exposes a minimal raw-execution surface (lang, code, args) — no required fields', () => { expect(CodeExecutionToolSchema.required).toEqual([]); }); it('has "code" as an optional string property', () => { expect(CodeExecutionToolSchema.properties.code).toBeDefined(); expect(CodeExecutionToolSchema.properties.code.type).toBe('string'); expect(CodeExecutionToolSchema.required).not.toContain('code'); }); it('has "lang" with enum of supported languages', () => { expect(CodeExecutionToolSchema.properties.lang.type).toBe('string'); expect(CodeExecutionToolSchema.properties.lang.enum).toContain('py'); expect(CodeExecutionToolSchema.properties.lang.enum).toContain('js'); expect(CodeExecutionToolSchema.properties.lang.enum).toContain('ts'); }); it('has "args" as optional array', () => { expect(CodeExecutionToolSchema.properties.args).toBeDefined(); expect(CodeExecutionToolSchema.properties.args.type).toBe('array'); }); it('does NOT expose consumer-workflow fields (code_id, old_str, new_str, replace_all)', () => { // These live in ranger's codeEditWrapper Zod schema, not here. const props = CodeExecutionToolSchema.properties as Record; expect(props.code_id).toBeUndefined(); expect(props.old_str).toBeUndefined(); expect(props.new_str).toBeUndefined(); expect(props.replace_all).toBeUndefined(); }); }); describe('CodeExecutionToolDescription', () => { it('does NOT teach code_id / old_str / new_str workflows (consumer concerns)', () => { expect(CodeExecutionToolDescription).not.toMatch(/code_id/); expect(CodeExecutionToolDescription).not.toMatch(/old_str/); expect(CodeExecutionToolDescription).not.toMatch(/new_str/); }); it('describes the raw execution environment', () => { expect(CodeExecutionToolDescription).toMatch(/stateless/); expect(CodeExecutionToolDescription).toMatch(/No network access/); }); }); describe('CodeExecutionToolDefinition', () => { it('exports the canonical tool name', () => { expect(CodeExecutionToolName).toBe('execute_code'); }); it('schema is the minimal raw-execution surface', () => { const props = CodeExecutionToolDefinition.schema.properties as Record< string, unknown >; expect(props.lang).toBeDefined(); expect(props.code).toBeDefined(); expect(props.args).toBeDefined(); expect(props.code_id).toBeUndefined(); }); });