Files
antigravity-claude-proxy/tests/run-all.cjs
minhphuc429 53da774bb6 test: add count tokens endpoint test suite
Add comprehensive test suite for /v1/messages/count_tokens endpoint:
- Simple text messages
- Multi-turn conversations
- System prompts (string and array format)
- Tool definitions and tool use/result blocks
- Thinking blocks
- Content arrays with text blocks
- Error handling for invalid requests
- Long text tokenization

Also adds npm script test:counttokens for running tests individually.
2026-01-14 15:36:11 +07:00

107 lines
4.6 KiB
JavaScript

#!/usr/bin/env node
/**
* Test Runner
*
* Runs all tests in sequence and reports results.
* Usage: node tests/run-all.cjs
*/
const { spawn } = require('child_process');
const path = require('path');
const tests = [
{ name: 'Thinking Signatures', file: 'test-thinking-signatures.cjs' },
{ name: 'Multi-turn Tools (Non-Streaming)', file: 'test-multiturn-thinking-tools.cjs' },
{ name: 'Multi-turn Tools (Streaming)', file: 'test-multiturn-thinking-tools-streaming.cjs' },
{ name: 'Interleaved Thinking', file: 'test-interleaved-thinking.cjs' },
{ name: 'Image Support', file: 'test-images.cjs' },
{ name: 'Prompt Caching', file: 'test-caching-streaming.cjs' },
{ name: 'Cross-Model Thinking', file: 'test-cross-model-thinking.cjs' },
{ name: 'OAuth No-Browser Mode', file: 'test-oauth-no-browser.cjs' },
{ name: 'Empty Response Retry', file: 'test-empty-response-retry.cjs' },
{ name: 'Schema Sanitizer', file: 'test-schema-sanitizer.cjs' },
{ name: 'Count Tokens', file: 'test-count-tokens.cjs' }
];
async function runTest(test) {
return new Promise((resolve) => {
const testPath = path.join(__dirname, test.file);
const child = spawn('node', [testPath], {
stdio: 'inherit'
});
child.on('close', (code) => {
resolve({ ...test, passed: code === 0 });
});
child.on('error', (err) => {
console.error(`Error running ${test.name}:`, err);
resolve({ ...test, passed: false });
});
});
}
async function main() {
console.log('╔══════════════════════════════════════════════════════════════╗');
console.log('║ ANTIGRAVITY PROXY TEST SUITE ║');
console.log('╚══════════════════════════════════════════════════════════════╝');
console.log('');
console.log('Make sure the server is running on port 8080 before running tests.');
console.log('');
// Check if running specific test
const specificTest = process.argv[2];
let testsToRun = tests;
if (specificTest) {
testsToRun = tests.filter(t =>
t.file.includes(specificTest) || t.name.toLowerCase().includes(specificTest.toLowerCase())
);
if (testsToRun.length === 0) {
console.log(`No test found matching: ${specificTest}`);
console.log('\nAvailable tests:');
tests.forEach(t => console.log(` - ${t.name} (${t.file})`));
process.exit(1);
}
}
const results = [];
for (const test of testsToRun) {
console.log('\n');
console.log('╔' + '═'.repeat(60) + '╗');
console.log('║ Running: ' + test.name.padEnd(50) + '║');
console.log('╚' + '═'.repeat(60) + '╝');
console.log('');
const result = await runTest(test);
results.push(result);
console.log('\n');
}
// Summary
console.log('╔══════════════════════════════════════════════════════════════╗');
console.log('║ FINAL RESULTS ║');
console.log('╠══════════════════════════════════════════════════════════════╣');
let allPassed = true;
for (const result of results) {
const status = result.passed ? '✓ PASS' : '✗ FAIL';
const statusColor = result.passed ? '' : '';
console.log(`${status.padEnd(8)} ${result.name.padEnd(50)}`);
if (!result.passed) allPassed = false;
}
console.log('╠══════════════════════════════════════════════════════════════╣');
const overallStatus = allPassed ? '✓ ALL TESTS PASSED' : '✗ SOME TESTS FAILED';
console.log(`${overallStatus.padEnd(60)}`);
console.log('╚══════════════════════════════════════════════════════════════╝');
process.exit(allPassed ? 0 : 1);
}
main().catch(err => {
console.error('Test runner failed:', err);
process.exit(1);
});