website refactor

This commit is contained in:
2026-01-17 22:55:03 +01:00
parent 64d9e7fd16
commit 69d4cce7f1
64 changed files with 1146 additions and 1014 deletions

View File

@@ -6,33 +6,53 @@
import { describe, test, expect, beforeAll, afterAll } from 'vitest';
import { getWebsiteRouteContracts, RouteContract } from '../shared/website/RouteContractSpec';
import { WebsiteServerHarness } from '../integration/harness/WebsiteServerHarness';
import { ApiServerHarness } from '../integration/harness/ApiServerHarness';
const WEBSITE_BASE_URL = process.env.WEBSITE_BASE_URL || 'http://localhost:3000';
const API_BASE_URL = process.env.API_BASE_URL || 'http://localhost:3001';
describe('Website SSR Contract Suite', () => {
const contracts = getWebsiteRouteContracts();
let harness: WebsiteServerHarness | null = null;
let websiteHarness: WebsiteServerHarness | null = null;
let apiHarness: ApiServerHarness | null = null;
let errorCount500 = 0;
beforeAll(async () => {
// Only start harness if WEBSITE_BASE_URL is localhost and not already reachable
// 1. Ensure API is running
if (API_BASE_URL.includes('localhost')) {
try {
await fetch(`${API_BASE_URL}/health`);
console.log(`API already running at ${API_BASE_URL}`);
} catch (e) {
console.log(`Starting API server harness on ${API_BASE_URL}...`);
apiHarness = new ApiServerHarness({
port: parseInt(new URL(API_BASE_URL).port) || 3001,
});
await apiHarness.start();
}
}
// 2. Ensure Website is running
if (WEBSITE_BASE_URL.includes('localhost')) {
try {
await fetch(WEBSITE_BASE_URL, { method: 'HEAD' });
console.log(`Server already running at ${WEBSITE_BASE_URL}`);
console.log(`Website server already running at ${WEBSITE_BASE_URL}`);
} catch (e) {
console.log(`Starting website server harness on ${WEBSITE_BASE_URL}...`);
harness = new WebsiteServerHarness({
websiteHarness = new WebsiteServerHarness({
port: parseInt(new URL(WEBSITE_BASE_URL).port) || 3000,
});
await harness.start();
await websiteHarness.start();
}
}
});
}, 120000);
afterAll(async () => {
if (harness) {
await harness.stop();
if (websiteHarness) {
await websiteHarness.stop();
}
if (apiHarness) {
await apiHarness.stop();
}
// Fail suite on bursts of 500s (e.g. > 3)
@@ -41,8 +61,8 @@ describe('Website SSR Contract Suite', () => {
}
// Fail on uncaught exceptions in logs
if (harness?.hasErrorPatterns()) {
console.error('Server logs contained error patterns:\n' + harness.getLogTail(50));
if (websiteHarness?.hasErrorPatterns()) {
console.error('Server logs contained error patterns:\n' + websiteHarness.getLogTail(50));
throw new Error('Suite failed due to error patterns in server logs');
}
});
@@ -54,7 +74,7 @@ describe('Website SSR Contract Suite', () => {
try {
response = await fetch(url, { redirect: 'manual' });
} catch (e) {
const logTail = harness ? `\nServer Log Tail:\n${harness.getLogTail(20)}` : '';
const logTail = websiteHarness ? `\nServer Log Tail:\n${websiteHarness.getLogTail(20)}` : '';
throw new Error(`Failed to fetch ${url}: ${e.message}${logTail}`);
}
@@ -71,7 +91,7 @@ Route: ${contract.path}
Status: ${status}
Location: ${location || 'N/A'}
HTML (clipped): ${text.slice(0, 500)}...
${harness ? `\nServer Log Tail:\n${harness.getLogTail(10)}` : ''}
${websiteHarness ? `\nServer Log Tail:\n${websiteHarness.getLogTail(10)}` : ''}
`.trim();
// 1. Status class matches expectedStatus