feat: add admin menu, persistent json config, multi-provider support, and custom model fallback revolver
This commit is contained in:
parent
637a3cf255
commit
1c955619e7
21 changed files with 3742 additions and 388 deletions
144
test-integration.ts
Normal file
144
test-integration.ts
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
import http from 'http';
|
||||
import assert from 'assert';
|
||||
import app from './src/index';
|
||||
import { config } from './src/config';
|
||||
|
||||
async function runIntegrationTests() {
|
||||
console.log('🧪 Starting HTTP Integration Tests...\n');
|
||||
|
||||
const server = http.createServer(app);
|
||||
await new Promise<void>((resolve) => server.listen(0, resolve));
|
||||
const port = (server.address() as any).port;
|
||||
const baseUrl = `http://localhost:${port}`;
|
||||
const validKey = config.apiPassword!;
|
||||
|
||||
try {
|
||||
// 1. GET /admin UI
|
||||
console.log('1. Testing GET /admin page load...');
|
||||
const adminRes = await fetch(`${baseUrl}/admin`);
|
||||
assert.strictEqual(adminRes.status, 200);
|
||||
const adminHtml = await adminRes.text();
|
||||
assert.ok(adminHtml.includes('GeminiRevolver — Admin Console'));
|
||||
assert.ok(adminHtml.includes('Admin Access'));
|
||||
assert.ok(adminHtml.includes('auth-gate-section'));
|
||||
console.log(' ✓ Admin UI served successfully with auth gate.');
|
||||
|
||||
// 2. Auth tests on /api/admin/verify
|
||||
console.log('\n2. Testing /api/admin/verify authentication...');
|
||||
const noAuth = await fetch(`${baseUrl}/api/admin/verify`);
|
||||
assert.strictEqual(noAuth.status, 401, 'Should fail without auth');
|
||||
|
||||
const badAuth = await fetch(`${baseUrl}/api/admin/verify`, {
|
||||
headers: { 'Authorization': 'Bearer wrong_password' }
|
||||
});
|
||||
assert.strictEqual(badAuth.status, 401, 'Should fail with bad key');
|
||||
|
||||
const goodAuth = await fetch(`${baseUrl}/api/admin/verify`, {
|
||||
headers: { 'Authorization': `Bearer ${validKey}` }
|
||||
});
|
||||
assert.strictEqual(goodAuth.status, 200, 'Should succeed with valid API password');
|
||||
const goodJson = await goodAuth.json() as any;
|
||||
assert.strictEqual(goodJson.valid, true);
|
||||
console.log(' ✓ Admin authentication verification verified.');
|
||||
|
||||
// 3. Provider CRUD via API
|
||||
console.log('\n3. Testing Provider CRUD via /api/admin/providers...');
|
||||
const createProvRes = await fetch(`${baseUrl}/api/admin/providers`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${validKey}`,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: 'Groq Primary Integration Test',
|
||||
type: 'groq',
|
||||
baseUrl: 'https://api.groq.com/openai/v1',
|
||||
keys: ['gsk_live_test_key_1', 'gsk_live_test_key_2']
|
||||
})
|
||||
});
|
||||
assert.strictEqual(createProvRes.status, 200);
|
||||
const createdProv = await createProvRes.json() as any;
|
||||
assert.strictEqual(createdProv.name, 'Groq Primary Integration Test');
|
||||
assert.strictEqual(createdProv.keys.length, 2);
|
||||
|
||||
// Config endpoint test
|
||||
const configRes = await fetch(`${baseUrl}/api/admin/config`, {
|
||||
headers: { 'Authorization': `Bearer ${validKey}` }
|
||||
});
|
||||
const configData = await configRes.json() as any;
|
||||
const fetchedProv = configData.providers.find((p: any) => p.id === createdProv.id);
|
||||
assert.ok(fetchedProv);
|
||||
assert.strictEqual(fetchedProv.keys[0].key, 'gsk_...ey_1', 'Keys should be masked in normal view');
|
||||
|
||||
console.log(' ✓ Provider creation and masked retrieval verified.');
|
||||
|
||||
// 4. Custom Model CRUD via API
|
||||
console.log('\n4. Testing Custom Model CRUD via /api/admin/models...');
|
||||
const createModelRes = await fetch(`${baseUrl}/api/admin/models`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${validKey}`,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: 'integration-custom-model',
|
||||
description: 'Model created during integration testing',
|
||||
isDefault: true,
|
||||
tiers: [
|
||||
{
|
||||
tierIndex: 0,
|
||||
name: 'Tier 0: Main',
|
||||
targets: [
|
||||
{ providerId: createdProv.id, model: 'llama-3.3-70b-versatile' }
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
});
|
||||
assert.strictEqual(createModelRes.status, 200);
|
||||
const createdModel = await createModelRes.json() as any;
|
||||
assert.strictEqual(createdModel.name, 'integration-custom-model');
|
||||
assert.strictEqual(createdModel.isDefault, true);
|
||||
|
||||
// Test GET /v1/models (Client perspective)
|
||||
console.log('\n5. Testing GET /v1/models reflects custom models...');
|
||||
const v1ModelsRes = await fetch(`${baseUrl}/v1/models`, {
|
||||
headers: { 'Authorization': `Bearer ${validKey}` }
|
||||
});
|
||||
assert.strictEqual(v1ModelsRes.status, 200);
|
||||
const v1Models = await v1ModelsRes.json() as any;
|
||||
const foundModel = v1Models.data.find((m: any) => m.id === 'integration-custom-model');
|
||||
assert.ok(foundModel, 'Created custom model must appear in GET /v1/models');
|
||||
console.log(' ✓ Custom model successfully exposed to OpenAI clients via /v1/models.');
|
||||
|
||||
// 6. Keys status telemetry endpoint
|
||||
console.log('\n6. Testing GET /api/admin/keys-status...');
|
||||
const statusRes = await fetch(`${baseUrl}/api/admin/keys-status`, {
|
||||
headers: { 'Authorization': `Bearer ${validKey}` }
|
||||
});
|
||||
assert.strictEqual(statusRes.status, 200);
|
||||
const statusData = await statusRes.json() as any;
|
||||
assert.ok(Array.isArray(statusData.providers));
|
||||
console.log(' ✓ Live key status telemetry verified.');
|
||||
|
||||
// Clean up created entities
|
||||
await fetch(`${baseUrl}/api/admin/models/${createdModel.id}`, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Authorization': `Bearer ${validKey}` }
|
||||
});
|
||||
await fetch(`${baseUrl}/api/admin/providers/${createdProv.id}`, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Authorization': `Bearer ${validKey}` }
|
||||
});
|
||||
console.log(' ✓ Cleanup completed.');
|
||||
|
||||
console.log('\n🎉 ALL HTTP INTEGRATION TESTS PASSED!');
|
||||
} finally {
|
||||
server.close();
|
||||
}
|
||||
}
|
||||
|
||||
runIntegrationTests().catch(err => {
|
||||
console.error('❌ Integration test failed:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue