Files
cim_summary/backend/test-firebase-complete.js
Jon 185c780486
Some checks failed
CI/CD Pipeline / Backend - Lint & Test (push) Has been cancelled
CI/CD Pipeline / Frontend - Lint & Test (push) Has been cancelled
CI/CD Pipeline / Security Scan (push) Has been cancelled
CI/CD Pipeline / Build Backend (push) Has been cancelled
CI/CD Pipeline / Build Frontend (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Deploy to Staging (push) Has been cancelled
CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / Performance Tests (push) Has been cancelled
CI/CD Pipeline / Dependency Updates (push) Has been cancelled
🚀 Update to Claude 3.7 latest and fix LLM processing issues
- Updated Anthropic API to latest version (2024-01-01)
- Set Claude 3.7 Sonnet Latest as primary model
- Removed deprecated Opus 3.5 references
- Fixed LLM response validation and JSON parsing
- Improved error handling and logging
- Updated model configurations and pricing
- Enhanced document processing reliability
- Fixed TypeScript type issues
- Updated environment configuration
2025-08-17 17:31:56 -04:00

270 lines
7.4 KiB
JavaScript
Executable File

#!/usr/bin/env node
/**
* Comprehensive Firebase Environment Testing Script
* Tests all critical components for Firebase Functions deployment
*/
const { Storage } = require('@google-cloud/storage');
const { DocumentProcessorServiceClient } = require('@google-cloud/documentai');
const admin = require('firebase-admin');
// Colors for console output
const colors = {
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
reset: '\x1b[0m'
};
function log(message, color = 'blue') {
console.log(`${colors[color]}[TEST]${colors.reset} ${message}`);
}
function logSuccess(message) {
log(message, 'green');
}
function logError(message) {
log(message, 'red');
}
function logWarning(message) {
log(message, 'yellow');
}
async function testFirebaseAdmin() {
log('Testing Firebase Admin SDK initialization...');
try {
// Check if Firebase Admin is initialized
if (!admin.apps.length) {
logError('Firebase Admin SDK not initialized');
return false;
}
const app = admin.app();
logSuccess(`Firebase Admin initialized with project: ${app.options.projectId}`);
// Test auth service
const auth = admin.auth();
logSuccess('Firebase Auth service accessible');
return true;
} catch (error) {
logError(`Firebase Admin test failed: ${error.message}`);
return false;
}
}
async function testGoogleCloudStorage() {
log('Testing Google Cloud Storage...');
try {
const storage = new Storage();
const bucketName = process.env.GCS_BUCKET_NAME || 'cim-processor-testing-uploads';
// Test bucket access
const bucket = storage.bucket(bucketName);
const [exists] = await bucket.exists();
if (exists) {
logSuccess(`GCS bucket accessible: ${bucketName}`);
// Test file operations
const testFile = bucket.file('test-firebase-access.txt');
await testFile.save('Firebase Functions test', {
metadata: { contentType: 'text/plain' }
});
logSuccess('GCS file write test passed');
// Clean up
await testFile.delete();
logSuccess('GCS file cleanup successful');
return true;
} else {
logError(`GCS bucket not found: ${bucketName}`);
return false;
}
} catch (error) {
logError(`GCS test failed: ${error.message}`);
return false;
}
}
async function testDocumentAI() {
log('Testing Document AI...');
try {
const client = new DocumentProcessorServiceClient();
const projectId = process.env.GCLOUD_PROJECT_ID || 'cim-summarizer-testing';
const location = process.env.DOCUMENT_AI_LOCATION || 'us';
// List processors
const [processors] = await client.listProcessors({
parent: `projects/${projectId}/locations/${location}`,
});
if (processors.length > 0) {
logSuccess(`Found ${processors.length} Document AI processor(s)`);
processors.forEach((processor, index) => {
log(` ${index + 1}. ${processor.displayName} (${processor.name.split('/').pop()})`);
});
return true;
} else {
logWarning('No Document AI processors found');
return false;
}
} catch (error) {
logError(`Document AI test failed: ${error.message}`);
return false;
}
}
async function testEnvironmentVariables() {
log('Testing environment variables...');
const requiredVars = [
'GCLOUD_PROJECT_ID',
'GCS_BUCKET_NAME',
'DOCUMENT_AI_OUTPUT_BUCKET_NAME',
'LLM_PROVIDER',
'AGENTIC_RAG_ENABLED',
'PROCESSING_STRATEGY'
];
const missingVars = [];
for (const varName of requiredVars) {
if (!process.env[varName]) {
missingVars.push(varName);
} else {
logSuccess(`${varName}: ${process.env[varName]}`);
}
}
if (missingVars.length > 0) {
logError(`Missing environment variables: ${missingVars.join(', ')}`);
return false;
}
logSuccess('All required environment variables are set');
return true;
}
async function testFirebaseFunctionsEnvironment() {
log('Testing Firebase Functions environment...');
const isCloudFunction = process.env.FUNCTION_TARGET || process.env.FUNCTIONS_EMULATOR || process.env.GCLOUD_PROJECT;
if (isCloudFunction) {
logSuccess('Running in Firebase Functions environment');
log(` FUNCTION_TARGET: ${process.env.FUNCTION_TARGET || 'not set'}`);
log(` FUNCTIONS_EMULATOR: ${process.env.FUNCTIONS_EMULATOR || 'not set'}`);
log(` GCLOUD_PROJECT: ${process.env.GCLOUD_PROJECT || 'not set'}`);
return true;
} else {
logWarning('Not running in Firebase Functions environment');
return false;
}
}
async function testSupabaseConnection() {
log('Testing Supabase connection...');
try {
// This would require the Supabase client to be imported
// For now, just check if the environment variables are set
const supabaseUrl = process.env.SUPABASE_URL;
const supabaseKey = process.env.SUPABASE_ANON_KEY;
if (supabaseUrl && supabaseKey) {
logSuccess('Supabase environment variables configured');
log(` URL: ${supabaseUrl}`);
log(` Key: ${supabaseKey.substring(0, 10)}...`);
return true;
} else {
logError('Supabase environment variables missing');
return false;
}
} catch (error) {
logError(`Supabase test failed: ${error.message}`);
return false;
}
}
async function runAllTests() {
log('🚀 Starting comprehensive Firebase environment tests...', 'blue');
console.log('');
const tests = [
{ name: 'Firebase Functions Environment', fn: testFirebaseFunctionsEnvironment },
{ name: 'Environment Variables', fn: testEnvironmentVariables },
{ name: 'Firebase Admin SDK', fn: testFirebaseAdmin },
{ name: 'Google Cloud Storage', fn: testGoogleCloudStorage },
{ name: 'Document AI', fn: testDocumentAI },
{ name: 'Supabase Connection', fn: testSupabaseConnection }
];
const results = [];
for (const test of tests) {
log(`Running ${test.name}...`);
try {
const result = await test.fn();
results.push({ name: test.name, passed: result });
console.log('');
} catch (error) {
logError(`${test.name} failed with error: ${error.message}`);
results.push({ name: test.name, passed: false, error: error.message });
console.log('');
}
}
// Summary
console.log('📊 Test Results Summary:');
console.log('========================');
const passed = results.filter(r => r.passed).length;
const total = results.length;
results.forEach(result => {
const status = result.passed ? '✅ PASS' : '❌ FAIL';
const color = result.passed ? 'green' : 'red';
log(`${status} ${result.name}`, color);
if (result.error) {
log(` Error: ${result.error}`, 'red');
}
});
console.log('');
log(`Overall: ${passed}/${total} tests passed`, passed === total ? 'green' : 'red');
if (passed === total) {
logSuccess('🎉 All tests passed! Firebase environment is ready for deployment.');
} else {
logError('⚠️ Some tests failed. Please fix the issues before deploying.');
process.exit(1);
}
}
// Run tests if this script is executed directly
if (require.main === module) {
runAllTests().catch(error => {
logError(`Test suite failed: ${error.message}`);
process.exit(1);
});
}
module.exports = {
testFirebaseAdmin,
testGoogleCloudStorage,
testDocumentAI,
testEnvironmentVariables,
testFirebaseFunctionsEnvironment,
testSupabaseConnection,
runAllTests
};