Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

fix(test): stop integration runs when teardown fails

pulse-triage[bot]ff2a1732060c
diff --git a/tests/integration/scripts/run-tests-cleanup.test.mjs b/tests/integration/scripts/run-tests-cleanup.test.mjs
new file mode 100644
index 0000000000..db707d7d39
--- /dev/null
+++ b/tests/integration/scripts/run-tests-cleanup.test.mjs
@@ -0,0 +1,45 @@
+import assert from 'node:assert/strict';
+import { mkdtempSync, writeFileSync, readFileSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import path from 'node:path';
+import { spawnSync } from 'node:child_process';
+import { fileURLToPath } from 'node:url';
+import test from 'node:test';
+
+const runner = fileURLToPath(new URL('./run-tests.sh', import.meta.url));
+
+for (const suite of ['core', 'all']) {
+ for (const cleanupStatus of [0, 17]) {
+ test(`${suite} success requires cleanup success (cleanup exit ${cleanupStatus})`, () => {
+ const dir = mkdtempSync(path.join(tmpdir(), 'pulse-cleanup-test-'));
+ try {
+ const stubs = {
+ docker: `if [ "$1 $2 $4" = "compose -f down" ]; then exit ${cleanupStatus}; fi
+ case "$1 $2" in
+ 'inspect -f') echo true ;;
+ esac
+ exit 0`,
+ curl: 'exit 0',
+ go: 'exit 0',
+ node: 'exit 0',
+ npx: `echo test >> '${dir}/tests-run'\nexit 0`,
+ };
+ for (const [name, body] of Object.entries(stubs)) {
+ writeFileSync(path.join(dir, name), `#!/bin/bash\n${body}\n`, { mode: 0o755 });
+ }
+ const result = spawnSync('bash', [runner, suite], {
+ env: { ...process.env, PATH: `${dir}:${process.env.PATH}` },
+ encoding: 'utf8',
+ });
+ assert.equal(result.status, cleanupStatus === 0 ? 0 : 1, result.stdout + result.stderr);
+ assert.equal(result.stdout.includes('All tests passed!'), cleanupStatus === 0);
+ if (cleanupStatus !== 0) {
+ assert.equal(readFileSync(path.join(dir, 'tests-run'), 'utf8'), 'test\n',
+ 'cleanup failure must stop before another suite can inherit dirty state');
+ }
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+ });
+ }
+}
diff --git a/tests/integration/scripts/run-tests.sh b/tests/integration/scripts/run-tests.sh
index 11bfa4cb04..bc9c44d8a4 100755
--- a/tests/integration/scripts/run-tests.sh
+++ b/tests/integration/scripts/run-tests.sh
@@ -174,7 +174,13 @@ run_suite() {
# Cleanup
echo "Cleaning up..."
- compose down -v
+ # run_suite is called in an || list, where Bash disables errexit.
+ # Stop the entire run if teardown fails: later suites must not inherit
+ # containers or volumes from a previous scenario.
+ if ! compose down -v; then
+ echo -e "${RED}❌ Failed to clean up test environment; stopping run${NC}"
+ exit 1
+ fi
return $TEST_RESULT
}