#!/usr/bin/env node
/**
* Test JSON string parameter handling
*
* Verifies orchestrator-tool correctly handles steps/actions as JSON strings
* (how Claude Desktop sends them) vs native arrays (how direct API calls send them).
*/
import { ConversationManager } from './dist/core/conversation-manager.js';
const conversationManager = new ConversationManager();
await conversationManager.waitForToolsLoaded();
const conversationId = `test-json-strings-${Date.now()}`;
console.log('๐งช Testing JSON string parameter handling...\n');
// Test 1: Pipeline with JSON string (Claude Desktop format)
console.log('Test 1: Pipeline with JSON string (Claude Desktop serialization)');
const pipelineJsonString = JSON.stringify([
{
action: 'create-resource',
args: { name: 'test-item', data: { value: 100 } },
},
{
action: 'read-resource',
args: { name: 'test-item' },
},
]);
const result1 = await conversationManager.negotiate(
conversationId,
'pipeline',
{ steps: pipelineJsonString }, // โ String, not array
'orchestrator-tool'
);
console.log('Result:', result1.success ? 'โ
SUCCESS' : 'โ FAILED');
if (result1.error) {
console.log('Error:', result1.error);
} else {
console.log('Steps executed:', result1.output?.steps);
}
console.log();
// Test 2: Pipeline with native array (direct API format)
console.log('Test 2: Pipeline with native array (direct API call)');
const result2 = await conversationManager.negotiate(
conversationId,
'pipeline',
{
steps: [
{
action: 'create-resource',
args: { name: 'test-item-2', data: { value: 200 } },
},
{
action: 'read-resource',
args: { name: 'test-item-2' },
},
],
}, // โ Native array
'orchestrator-tool'
);
console.log('Result:', result2.success ? 'โ
SUCCESS' : 'โ FAILED');
if (result2.error) {
console.log('Error:', result2.error);
} else {
console.log('Steps executed:', result2.output?.steps);
}
console.log();
// Test 3: Aggregate with JSON string
console.log('Test 3: Aggregate with JSON string (Claude Desktop serialization)');
const aggregateJsonString = JSON.stringify([
{ action: 'greet', args: {} },
{ action: 'list-resources', args: {} },
]);
const result3 = await conversationManager.negotiate(
conversationId,
'aggregate',
{ actions: aggregateJsonString },
'orchestrator-tool'
);
console.log('Result:', result3.success ? 'โ
SUCCESS' : 'โ FAILED');
if (result3.error) {
console.log('Error:', result3.error);
} else {
console.log('Actions executed:', result3.output?.actions);
}
console.log();
console.log('=== Summary ===');
const allPassed = result1.success && result2.success && result3.success;
console.log(allPassed ? 'โ
All tests passed!' : 'โ Some tests failed');
console.log('\nโ
orchestrator-tool now handles both JSON strings and native arrays correctly!');
process.exit(allPassed ? 0 : 1);