testing/staging fixin
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 16m15s
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 16m15s
This commit is contained in:
@@ -262,8 +262,9 @@ function parseConfig(): EnvConfig {
|
|||||||
'',
|
'',
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
|
||||||
// In test environment, throw instead of exiting to allow test frameworks to catch
|
// In test/staging environment, throw instead of exiting to allow test frameworks to catch
|
||||||
if (process.env.NODE_ENV === 'test') {
|
// and to provide better visibility into config errors during staging deployments
|
||||||
|
if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'staging') {
|
||||||
throw new Error(errorMessage);
|
throw new Error(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,6 +324,19 @@ export const isDevelopment = config.server.nodeEnv === 'development';
|
|||||||
*/
|
*/
|
||||||
export const isStaging = config.server.nodeEnv === 'staging';
|
export const isStaging = config.server.nodeEnv === 'staging';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if running in a test-like environment (test or staging).
|
||||||
|
* Use this for behaviors that should be shared between unit/integration tests
|
||||||
|
* and the staging deployment server, such as:
|
||||||
|
* - Using mock AI services (no GEMINI_API_KEY required)
|
||||||
|
* - Verbose error logging
|
||||||
|
* - Fallback URL handling
|
||||||
|
*
|
||||||
|
* Do NOT use this for security bypasses (auth, rate limiting) - those should
|
||||||
|
* only be active in NODE_ENV=test, not staging.
|
||||||
|
*/
|
||||||
|
export const isTestLikeEnvironment = isTest || isStaging;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if SMTP is configured (all required fields present).
|
* Returns true if SMTP is configured (all required fields present).
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -161,9 +161,12 @@ export const errorHandler = (err: Error, req: Request, res: Response, next: Next
|
|||||||
`Unhandled API Error (ID: ${errorId})`,
|
`Unhandled API Error (ID: ${errorId})`,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Also log to console in test environment for visibility in test runners
|
// Also log to console in test/staging environments for visibility in test runners
|
||||||
if (process.env.NODE_ENV === 'test') {
|
if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'staging') {
|
||||||
console.error(`--- [TEST] UNHANDLED ERROR (ID: ${errorId}) ---`, err);
|
console.error(
|
||||||
|
`--- [${process.env.NODE_ENV?.toUpperCase()}] UNHANDLED ERROR (ID: ${errorId}) ---`,
|
||||||
|
err,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// In production, send a generic message to avoid leaking implementation details.
|
// In production, send a generic message to avoid leaking implementation details.
|
||||||
|
|||||||
@@ -239,10 +239,13 @@ router.post(
|
|||||||
'Handling /upload-and-process',
|
'Handling /upload-and-process',
|
||||||
);
|
);
|
||||||
|
|
||||||
// Fix: Explicitly clear userProfile if no auth header is present in test env
|
// Fix: Explicitly clear userProfile if no auth header is present in test/staging env
|
||||||
// This prevents mockAuth from injecting a non-existent user ID for anonymous requests.
|
// This prevents mockAuth from injecting a non-existent user ID for anonymous requests.
|
||||||
let userProfile = req.user as UserProfile | undefined;
|
let userProfile = req.user as UserProfile | undefined;
|
||||||
if (process.env.NODE_ENV === 'test' && !req.headers['authorization']) {
|
if (
|
||||||
|
(process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'staging') &&
|
||||||
|
!req.headers['authorization']
|
||||||
|
) {
|
||||||
userProfile = undefined;
|
userProfile = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,11 @@ export class AIService {
|
|||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.logger.info('---------------- [AIService] Constructor Start ----------------');
|
this.logger.info('---------------- [AIService] Constructor Start ----------------');
|
||||||
|
|
||||||
const isTestEnvironment = process.env.NODE_ENV === 'test' || !!process.env.VITEST_POOL_ID;
|
// Use mock AI in test and staging environments (no real API calls, no GEMINI_API_KEY needed)
|
||||||
|
const isTestEnvironment =
|
||||||
|
process.env.NODE_ENV === 'test' ||
|
||||||
|
process.env.NODE_ENV === 'staging' ||
|
||||||
|
!!process.env.VITEST_POOL_ID;
|
||||||
|
|
||||||
if (aiClient) {
|
if (aiClient) {
|
||||||
this.logger.info(
|
this.logger.info(
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ export function getBaseUrl(logger: Logger): string {
|
|||||||
let baseUrl = (process.env.FRONTEND_URL || process.env.BASE_URL || '').trim();
|
let baseUrl = (process.env.FRONTEND_URL || process.env.BASE_URL || '').trim();
|
||||||
if (!baseUrl || !baseUrl.startsWith('http')) {
|
if (!baseUrl || !baseUrl.startsWith('http')) {
|
||||||
const port = process.env.PORT || 3000;
|
const port = process.env.PORT || 3000;
|
||||||
// In test/development, use http://localhost. In production, this should never be reached.
|
// In test/staging/development, use http://localhost. In production, this should never be reached.
|
||||||
const fallbackUrl =
|
const fallbackUrl =
|
||||||
process.env.NODE_ENV === 'test'
|
process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'staging'
|
||||||
? `http://localhost:${port}`
|
? `http://localhost:${port}`
|
||||||
: `http://example.com:${port}`;
|
: `http://example.com:${port}`;
|
||||||
if (baseUrl) {
|
if (baseUrl) {
|
||||||
@@ -39,4 +39,4 @@ export function getBaseUrl(logger: Logger): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return finalUrl;
|
return finalUrl;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user