- test(e2e): add playwright harness and test stack - test(e2e): add core flow - fix(ui): preserve same-origin browser form submissions - fix(ui): offer reload inside stale edit dialogs - test(e2e): add persona session and accessibility suites - test(e2e): preserve per-run artifacts and clean pulled images - test(e2e): verify import and audit state across navigation - test(e2e): tighten verification helpers and persona checks - test(e2e): bound response body reads of the browser observer - test: recover review compatibility assertions - test: stabilize audit and user flow assertions
53 lines
2.1 KiB
TypeScript
53 lines
2.1 KiB
TypeScript
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
// Copyright (C) 2026 Bryan Joshua Pedini
|
|
|
|
import fs from 'node:fs';
|
|
import { docker, projectResources, runnerContainer } from './docker';
|
|
import { project, runDir } from './env';
|
|
import { stackDown } from './stack';
|
|
|
|
export async function detectLeaks(allowed: ReadonlySet<string> = new Set()): Promise<string[]> {
|
|
const leaks: string[] = [];
|
|
const resources = await projectResources();
|
|
const self = runnerContainer();
|
|
const runnerNetworks = new Set<string>();
|
|
const inspect = await docker(['inspect', '--format', '{{range $k, $v := .NetworkSettings.Networks}}{{$k}} {{end}}', self]);
|
|
if (inspect.code === 0) for (const n of inspect.stdout.trim().split(/\s+/).filter(Boolean)) runnerNetworks.add(n);
|
|
const containers = resources.containers.filter((c) => c !== self && !allowed.has(c));
|
|
if (containers.length > 0) {
|
|
leaks.push(`containers left behind: ${containers.join(', ')}`);
|
|
await docker(['rm', '--force', '--volumes', ...containers]);
|
|
}
|
|
const volumes = resources.volumes.filter((v) => !allowed.has(v));
|
|
if (volumes.length > 0) {
|
|
leaks.push(`volumes left behind: ${volumes.join(', ')}`);
|
|
await docker(['volume', 'rm', '--force', ...volumes]);
|
|
}
|
|
const networks = resources.networks.filter((n) => !runnerNetworks.has(n) && !allowed.has(n));
|
|
if (networks.length > 0) {
|
|
leaks.push(`networks left behind: ${networks.join(', ')}`);
|
|
await docker(['network', 'rm', ...networks]);
|
|
}
|
|
return leaks;
|
|
}
|
|
|
|
export default async function globalTeardown(): Promise<void> {
|
|
const p = project();
|
|
const problems: string[] = [];
|
|
try {
|
|
await stackDown();
|
|
} catch (e) {
|
|
problems.push(`stack teardown failed: ${(e as Error).message}`);
|
|
}
|
|
try {
|
|
problems.push(...(await detectLeaks()));
|
|
} catch (e) {
|
|
problems.push(`leak detection failed: ${(e as Error).message}`);
|
|
}
|
|
fs.rmSync(runDir(), { recursive: true, force: true });
|
|
if (problems.length > 0) {
|
|
throw new Error(`[cdwu-e2e] resource leaks detected for run ${p} (cleaned up, failing the run):\n- ${problems.join('\n- ')}`);
|
|
}
|
|
console.log(`[cdwu-e2e] run ${p}: stack removed, no leaked containers, volumes or networks`);
|
|
}
|