chore: update CI configuration and enhance test stability

- Added deterministic API key and environment variables in e2e-tests.yml to ensure consistent test behavior.
- Refactored CodexProvider tests to improve type safety and mock handling, ensuring reliable test execution.
- Updated provider-factory tests to mock installation detection for CodexProvider, enhancing test isolation.
- Adjusted Playwright configuration to conditionally use external backend, improving flexibility in test environments.
- Enhanced kill-test-servers script to handle external server scenarios, ensuring proper cleanup of test processes.

These changes improve the reliability and maintainability of the testing framework, leading to a more stable development experience.
This commit is contained in:
DhanushSantosh
2026-01-07 00:27:38 +05:30
parent 96f154d440
commit 251f0fd88e
12 changed files with 194 additions and 160 deletions

View File

@@ -10,24 +10,42 @@ const execAsync = promisify(exec);
const SERVER_PORT = process.env.TEST_SERVER_PORT || 3008;
const UI_PORT = process.env.TEST_PORT || 3007;
const USE_EXTERNAL_SERVER = !!process.env.VITE_SERVER_URL;
async function killProcessOnPort(port) {
try {
const { stdout } = await execAsync(`lsof -ti:${port}`);
const pids = stdout.trim().split('\n').filter(Boolean);
const hasLsof = await execAsync('command -v lsof').then(
() => true,
() => false
);
if (pids.length > 0) {
console.log(`[KillTestServers] Found process(es) on port ${port}: ${pids.join(', ')}`);
for (const pid of pids) {
try {
await execAsync(`kill -9 ${pid}`);
console.log(`[KillTestServers] Killed process ${pid}`);
} catch (error) {
// Process might have already exited
if (hasLsof) {
const { stdout } = await execAsync(`lsof -ti:${port}`);
const pids = stdout.trim().split('\n').filter(Boolean);
if (pids.length > 0) {
console.log(`[KillTestServers] Found process(es) on port ${port}: ${pids.join(', ')}`);
for (const pid of pids) {
try {
await execAsync(`kill -9 ${pid}`);
console.log(`[KillTestServers] Killed process ${pid}`);
} catch (error) {
// Process might have already exited
}
}
await new Promise((resolve) => setTimeout(resolve, 500));
}
// Wait a moment for the port to be released
return;
}
const hasFuser = await execAsync('command -v fuser').then(
() => true,
() => false
);
if (hasFuser) {
await execAsync(`fuser -k -9 ${port}/tcp`).catch(() => undefined);
await new Promise((resolve) => setTimeout(resolve, 500));
return;
}
} catch (error) {
// No process on port, which is fine
@@ -36,7 +54,9 @@ async function killProcessOnPort(port) {
async function main() {
console.log('[KillTestServers] Checking for existing test servers...');
await killProcessOnPort(Number(SERVER_PORT));
if (!USE_EXTERNAL_SERVER) {
await killProcessOnPort(Number(SERVER_PORT));
}
await killProcessOnPort(Number(UI_PORT));
console.log('[KillTestServers] Done');
}