2025-10-05 20:03:07 +02:00
|
|
|
import {
|
|
|
|
|
runAllHealthChecks,
|
|
|
|
|
formatHealthCheckError,
|
|
|
|
|
} from './health-checks.js';
|
2025-10-05 19:40:14 +02:00
|
|
|
|
2025-10-07 21:57:32 +00:00
|
|
|
const DEFAULT_RPC_URL = 'http://127.0.0.1:8545';
|
|
|
|
|
const DEFAULT_WEBAPP_URL = 'http://localhost:8081';
|
|
|
|
|
const DEFAULT_GRAPHQL_URL = 'http://localhost:8081/graphql';
|
2025-10-05 19:40:14 +02:00
|
|
|
|
2025-10-07 21:57:32 +00:00
|
|
|
export interface StackConfig {
|
|
|
|
|
rpcUrl: string;
|
|
|
|
|
webAppUrl: string;
|
|
|
|
|
graphqlUrl: string;
|
2025-10-05 19:40:14 +02:00
|
|
|
}
|
|
|
|
|
|
2025-10-07 21:57:32 +00:00
|
|
|
/**
|
|
|
|
|
* Get stack configuration from environment variables.
|
|
|
|
|
* Tests should NOT start their own stack - they require a pre-existing healthy stack.
|
|
|
|
|
*/
|
|
|
|
|
export function getStackConfig(): StackConfig {
|
|
|
|
|
return {
|
|
|
|
|
rpcUrl: process.env.STACK_RPC_URL ?? DEFAULT_RPC_URL,
|
|
|
|
|
webAppUrl: process.env.STACK_WEBAPP_URL ?? DEFAULT_WEBAPP_URL,
|
|
|
|
|
graphqlUrl: process.env.STACK_GRAPHQL_URL ?? DEFAULT_GRAPHQL_URL,
|
|
|
|
|
};
|
2025-10-05 19:40:14 +02:00
|
|
|
}
|
|
|
|
|
|
2025-10-05 20:03:07 +02:00
|
|
|
/**
|
2025-10-07 21:57:32 +00:00
|
|
|
* Validate that a healthy stack exists and is functional.
|
|
|
|
|
* If validation fails, the test run should exit immediately.
|
|
|
|
|
*
|
|
|
|
|
* Tests do NOT manage stack lifecycle - stack must be started externally via:
|
|
|
|
|
* ./scripts/dev.sh start
|
2025-10-05 20:03:07 +02:00
|
|
|
*/
|
2025-10-07 21:57:32 +00:00
|
|
|
export async function validateStackHealthy(config: StackConfig): Promise<void> {
|
|
|
|
|
const results = await runAllHealthChecks(config);
|
2025-10-05 20:03:07 +02:00
|
|
|
|
|
|
|
|
const failures = results.filter(r => !r.success);
|
|
|
|
|
if (failures.length > 0) {
|
2025-10-07 21:57:32 +00:00
|
|
|
const errorMessage = formatHealthCheckError(results);
|
|
|
|
|
console.error('\n❌ Stack health validation failed');
|
|
|
|
|
console.error('Tests require a pre-existing healthy stack.');
|
|
|
|
|
console.error('Start the stack with: ./scripts/dev.sh start\n');
|
|
|
|
|
console.error(errorMessage);
|
|
|
|
|
process.exit(1);
|
2025-10-05 19:40:14 +02:00
|
|
|
}
|
|
|
|
|
|
2025-10-07 21:57:32 +00:00
|
|
|
console.log('✅ Stack health validation passed');
|
2025-10-05 19:40:14 +02:00
|
|
|
}
|