fix: skip integration tests when API keys are missing

Co-Authored-By: Han Xiao <han.xiao@jina.ai>
This commit is contained in:
Devin AI 2025-02-08 00:56:26 +00:00
parent 226825d630
commit a4084ea906
2 changed files with 37 additions and 1 deletions

View File

@ -46,7 +46,19 @@ export GEMINI_API_KEY=... # for gemini
# export LLM_PROVIDER=openai # for openai
export JINA_API_KEY=jina_... # free jina api key, get from https://jina.ai/reader
# Optional: Enable secure mode for the server
# export SECURE_MODE=true # requires API key for all requests
# export API_KEY=your-key # if not set, a random UUID will be generated
npm run dev $QUERY
## Testing
Integration tests require the following environment variables to be set:
- GOOGLE_API_KEY: Google API key for Gemini
- JINA_API_KEY: Jina API key
Tests will be skipped if these environment variables are not available.
```
## Demo
@ -131,6 +143,15 @@ Response:
}
```
## Secure Mode
The server supports a secure mode that requires API key authentication for all requests. To enable secure mode:
1. Set the environment variable `SECURE_MODE=true`
2. Optionally set `API_KEY=your-key` (if not set, a random UUID will be generated)
When secure mode is enabled, clients must include the API key in the `x-api-key` header.
### GET /api/v1/stream/:requestId
Connect to the Server-Sent Events stream to receive progress updates and the final answer:
```bash
@ -248,4 +269,4 @@ It should not be surprised that plain `gemini-2.0-flash` has a 0% pass rate, as
| Average Tokens | 428 | 59,408 |
| Median Tokens | 434 | 16,001 |
| Maximum Tokens | 463 | 347,222 |
| Minimum Tokens | 374 | 5,594 |
| Minimum Tokens | 374 | 5,594 |

View File

@ -1,11 +1,26 @@
import { getResponse } from '../agent';
describe('getResponse', () => {
const requiredEnvVars = ['GOOGLE_API_KEY', 'JINA_API_KEY'];
beforeAll(() => {
const missingVars = requiredEnvVars.filter(key => !process.env[key]);
if (missingVars.length > 0) {
console.warn(`Skipping tests: missing required env vars: ${missingVars.join(', ')}`);
process.env.SKIP_INTEGRATION = 'true';
}
});
afterEach(() => {
jest.useRealTimers();
});
it('should handle search action', async () => {
if (process.env.SKIP_INTEGRATION) {
console.warn('Skipping integration test: missing required env vars');
return;
}
const result = await getResponse('What is TypeScript?', 10000);
expect(result.result.action).toBeDefined();
expect(result.context).toBeDefined();