Refactor error handling, client, and tests for Ollama integration
This commit is contained in:
@@ -45,6 +45,8 @@ describe('ToolExecutor', () => {
|
||||
describe('create_file tool', () => {
|
||||
it('should successfully create a file with valid arguments', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_1',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -60,6 +62,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should handle object arguments directly', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_2',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: {
|
||||
@@ -75,6 +79,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should successfully create a file in a subdirectory', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_3',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -93,6 +99,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should handle multiple slashes gracefully by normalizing path', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_4',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -108,6 +116,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should handle empty content gracefully', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_5',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -123,6 +133,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should allow filenames with consecutive dots', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_6',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -138,6 +150,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject path traversal attempts with ..', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_7',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -152,6 +166,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject path traversal attempts with .\\', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_8',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -166,6 +182,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject path traversal attempts with /..', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_9',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -180,6 +198,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject absolute paths starting with /', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_10',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -194,6 +214,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject absolute paths starting with \\', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_11',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -208,6 +230,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject Windows drive letters', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_12',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -222,6 +246,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject empty path', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_13',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -236,6 +262,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject undefined path', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_14',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -249,6 +277,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject path with invalid characters <', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_15',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -263,6 +293,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject path with invalid characters >', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_16',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -277,6 +309,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject path with invalid characters :', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_17',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -291,6 +325,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject path with invalid characters |', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_18',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -305,6 +341,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject path with invalid characters ?', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_19',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -319,6 +357,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject path with invalid characters *', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_20',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -333,6 +373,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject path longer than 200 characters', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_21',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -347,6 +389,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject path with ~ character', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_22',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -361,6 +405,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject non-string content', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_23',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -375,6 +421,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should reject non-string path', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_24',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -390,6 +438,8 @@ describe('ToolExecutor', () => {
|
||||
it('should handle vault.create rejection gracefully', async () => {
|
||||
mockVault.create = jest.fn().mockRejectedValue(new Error('Permission denied'));
|
||||
const call: ToolCall = {
|
||||
id: 'call_25',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: JSON.stringify({
|
||||
@@ -403,6 +453,8 @@ describe('ToolExecutor', () => {
|
||||
|
||||
it('should handle invalid JSON in arguments', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_26',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'create_file',
|
||||
arguments: 'invalid json',
|
||||
@@ -416,6 +468,8 @@ describe('ToolExecutor', () => {
|
||||
describe('unknown tool', () => {
|
||||
it('should return failure for unknown tool', async () => {
|
||||
const call: ToolCall = {
|
||||
id: 'call_27',
|
||||
type: 'function',
|
||||
function: {
|
||||
name: 'unknown_tool',
|
||||
arguments: JSON.stringify({}),
|
||||
|
||||
Reference in New Issue
Block a user