Switch to using dotenv to get test environment variables

This commit is contained in:
ColemanRoo
2025-01-03 21:35:25 -06:00
parent 66c5485534
commit 8e54360a86
3 changed files with 28 additions and 13 deletions

14
package-lock.json generated
View File

@@ -56,6 +56,7 @@
"@typescript-eslint/parser": "^7.11.0", "@typescript-eslint/parser": "^7.11.0",
"@vscode/test-cli": "^0.0.9", "@vscode/test-cli": "^0.0.9",
"@vscode/test-electron": "^2.4.0", "@vscode/test-electron": "^2.4.0",
"dotenv": "^16.4.7",
"esbuild": "^0.24.0", "esbuild": "^0.24.0",
"eslint": "^8.57.0", "eslint": "^8.57.0",
"husky": "^9.1.7", "husky": "^9.1.7",
@@ -8000,6 +8001,19 @@
"url": "https://github.com/fb55/domutils?sponsor=1" "url": "https://github.com/fb55/domutils?sponsor=1"
} }
}, },
"node_modules/dotenv": {
"version": "16.4.7",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz",
"integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==",
"dev": true,
"license": "BSD-2-Clause",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/duck": { "node_modules/duck": {
"version": "0.1.12", "version": "0.1.12",
"resolved": "https://registry.npmjs.org/duck/-/duck-0.1.12.tgz", "resolved": "https://registry.npmjs.org/duck/-/duck-0.1.12.tgz",

View File

@@ -185,6 +185,7 @@
"@typescript-eslint/parser": "^7.11.0", "@typescript-eslint/parser": "^7.11.0",
"@vscode/test-cli": "^0.0.9", "@vscode/test-cli": "^0.0.9",
"@vscode/test-electron": "^2.4.0", "@vscode/test-electron": "^2.4.0",
"dotenv": "^16.4.7",
"esbuild": "^0.24.0", "esbuild": "^0.24.0",
"eslint": "^8.57.0", "eslint": "^8.57.0",
"husky": "^9.1.7", "husky": "^9.1.7",
@@ -196,9 +197,9 @@
}, },
"dependencies": { "dependencies": {
"@anthropic-ai/bedrock-sdk": "^0.10.2", "@anthropic-ai/bedrock-sdk": "^0.10.2",
"@aws-sdk/client-bedrock-runtime": "^3.706.0",
"@anthropic-ai/sdk": "^0.26.0", "@anthropic-ai/sdk": "^0.26.0",
"@anthropic-ai/vertex-sdk": "^0.4.1", "@anthropic-ai/vertex-sdk": "^0.4.1",
"@aws-sdk/client-bedrock-runtime": "^3.706.0",
"@google/generative-ai": "^0.18.0", "@google/generative-ai": "^0.18.0",
"@modelcontextprotocol/sdk": "^1.0.1", "@modelcontextprotocol/sdk": "^1.0.1",
"@types/clone-deep": "^4.0.4", "@types/clone-deep": "^4.0.4",

View File

@@ -2,6 +2,11 @@ const assert = require('assert');
const vscode = require('vscode'); const vscode = require('vscode');
const path = require('path'); const path = require('path');
const fs = require('fs'); const fs = require('fs');
const dotenv = require('dotenv');
// Load test environment variables
const testEnvPath = path.join(__dirname, '.test_env');
dotenv.config({ path: testEnvPath });
suite('Roo Cline Extension Test Suite', () => { suite('Roo Cline Extension Test Suite', () => {
vscode.window.showInformationMessage('Starting Roo Cline extension tests.'); vscode.window.showInformationMessage('Starting Roo Cline extension tests.');
@@ -34,14 +39,11 @@ suite('Roo Cline Extension Test Suite', () => {
} }
// Verify API key is set and valid // Verify API key is set and valid
const testEnvPath = path.join(__dirname, '.test_env'); const apiKey = process.env.OPEN_ROUTER_API_KEY;
const envContent = fs.readFileSync(testEnvPath, 'utf8'); if (!apiKey) {
const match = envContent.match(/OPEN_ROUTER_API_KEY=(.+)/); done(new Error('OPEN_ROUTER_API_KEY environment variable is not set'));
if (!match) {
done(new Error('OpenRouter API key should be present in .test_env'));
return; return;
} }
const apiKey = match[1];
if (!apiKey.startsWith('sk-or-v1-')) { if (!apiKey.startsWith('sk-or-v1-')) {
done(new Error('OpenRouter API key should have correct format')); done(new Error('OpenRouter API key should have correct format'));
return; return;
@@ -180,14 +182,12 @@ suite('Roo Cline Extension Test Suite', () => {
// Set up API configuration // Set up API configuration
await provider.updateGlobalState('apiProvider', 'openrouter'); await provider.updateGlobalState('apiProvider', 'openrouter');
await provider.updateGlobalState('openRouterModelId', 'anthropic/claude-3.5-sonnet'); await provider.updateGlobalState('openRouterModelId', 'anthropic/claude-3.5-sonnet');
const testEnvPath = path.join(__dirname, '.test_env'); const apiKey = process.env.OPEN_ROUTER_API_KEY;
const envContent = fs.readFileSync(testEnvPath, 'utf8'); if (!apiKey) {
const match = envContent.match(/OPEN_ROUTER_API_KEY=(.+)/); assert.fail('OPEN_ROUTER_API_KEY environment variable is not set');
if (!match) {
assert.fail('OpenRouter API key should be present in .test_env');
return; return;
} }
await provider.storeSecret('openRouterApiKey', match[1]); await provider.storeSecret('openRouterApiKey', apiKey);
// Create webview panel with development options // Create webview panel with development options
const extensionUri = extension.extensionUri; const extensionUri = extension.extensionUri;