#!/usr/bin/env node
/**
* Manual Test Script - Error Handling Fix Verification
*
* This script demonstrates the fixed behavior where custom field failures
* are properly reported to users instead of being silently swallowed.
*
* Usage: node scripts/test-error-handling.js
*/
import { IssuesAPIClient } from '../dist/api/domains/issues-api.js';
// Mock config for demonstration
const config = {
baseURL: 'https://test.youtrack.cloud',
token: 'test-token'
};
// Create a mock client for demonstration purposes
class DemoIssuesClient extends IssuesAPIClient {
// Override applyCommand to simulate YouTrack API failures
async applyCommand(issueId, command) {
console.log(` š§ Attempting to apply command: "${command}" to ${issueId}`);
// Simulate YouTrack 400 errors for certain field values
if (command.includes('Type: Bug')) {
const error = new Error('YouTrack API Error (400): Type expected: Bug');
console.log(` ā Command failed: ${error.message}`);
throw error;
}
if (command.includes('Priority: High')) {
const error = new Error('YouTrack API Error (400): Priority expected: High');
console.log(` ā Command failed: ${error.message}`);
throw error;
}
if (command.includes('Type: Feature')) {
const error = new Error('YouTrack API Error (400): Type expected: Feature');
console.log(` ā Command failed: ${error.message}`);
throw error;
}
// Other commands succeed
console.log(` ā
Command applied successfully`);
return { data: { success: true } };
}
// Override post to simulate issue creation success
async post(endpoint, data) {
if (endpoint === '/issues') {
console.log(` ā
Issue created: TEST-123`);
return {
data: {
id: 'TEST-123',
idReadable: 'TEST-123',
summary: data.summary,
description: data.description
}
};
}
return super.post(endpoint, data);
}
}
async function runTests() {
console.log('\n' + '='.repeat(80));
console.log('ERROR HANDLING FIX VERIFICATION');
console.log('='.repeat(80) + '\n');
const client = new DemoIssuesClient(config);
// Test 1: Type field fails
console.log('š TEST 1: Creating issue with invalid Type field');
console.log('-'.repeat(80));
try {
const result = await client.createIssue('TEST', {
summary: 'Test Issue with Invalid Type',
description: 'This issue has an invalid Type field value',
type: 'Bug' // This will fail
});
console.log('\nš¤ Response to User/Assistant:');
console.log(result.content[0].text);
console.log('\nā
FIXED: User is properly warned about field failure!\n');
} catch (error) {
console.log('\nā ERROR: Unexpected exception:', error.message);
}
// Test 2: Multiple fields fail
console.log('\nš TEST 2: Creating issue with multiple invalid fields');
console.log('-'.repeat(80));
try {
const result = await client.createIssue('TEST', {
summary: 'Test Issue with Multiple Invalid Fields',
description: 'This issue has multiple invalid field values',
type: 'Bug', // This will fail
priority: 'High' // This will fail
});
console.log('\nš¤ Response to User/Assistant:');
console.log(result.content[0].text);
console.log('\nā
FIXED: User sees all field failures!\n');
} catch (error) {
console.log('\nā ERROR: Unexpected exception:', error.message);
}
// Test 3: All fields succeed
console.log('\nš TEST 3: Creating issue with valid fields');
console.log('-'.repeat(80));
try {
const result = await client.createIssue('TEST', {
summary: 'Test Issue with Valid Fields',
description: 'This issue has valid field values',
state: 'Open', // This will succeed
assignee: 'me' // This will succeed
});
console.log('\nš¤ Response to User/Assistant:');
console.log(result.content[0].text);
console.log('\nā
SUCCESS: No warnings when all fields apply successfully!\n');
} catch (error) {
console.log('\nā ERROR: Unexpected exception:', error.message);
}
// Test 4: Mixed success and failure
console.log('\nš TEST 4: Creating issue with mixed field results');
console.log('-'.repeat(80));
try {
const result = await client.createIssue('TEST', {
summary: 'Test Issue with Mixed Fields',
description: 'Some fields will succeed, some will fail',
type: 'Feature', // This will fail
state: 'Open', // This will succeed
priority: 'High' // This will fail
});
console.log('\nš¤ Response to User/Assistant:');
console.log(result.content[0].text);
console.log('\nā
FIXED: User sees which fields failed and which succeeded!\n');
} catch (error) {
console.log('\nā ERROR: Unexpected exception:', error.message);
}
console.log('='.repeat(80));
console.log('VERIFICATION COMPLETE');
console.log('='.repeat(80) + '\n');
console.log('šÆ KEY IMPROVEMENTS:');
console.log(' ā
Users now see warnings when custom fields fail');
console.log(' ā
Error messages include the actual YouTrack API error');
console.log(' ā
Issue ID is provided so users can manually fix fields');
console.log(' ā
Common causes are explained to help troubleshooting');
console.log(' ā
Success messages are accurate (no false positives)');
console.log('\nš The production bug is FIXED!\n');
}
runTests().catch(console.error);