From 35d43de227470513ab6de9ac00e314aed6c7afa9 Mon Sep 17 00:00:00 2001 From: "detail-app[bot]" Date: Fri, 4 Sep 2026 02:59:43 +0000 Subject: [PATCH] test: clean up temporary sandbox directories after each test --- .../__test__/server/server-validate.test.ts | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/apps/dokploy/__test__/server/server-validate.test.ts b/apps/dokploy/__test__/server/server-validate.test.ts index 71e537116..99627d51b 100644 --- a/apps/dokploy/__test__/server/server-validate.test.ts +++ b/apps/dokploy/__test__/server/server-validate.test.ts @@ -1,9 +1,9 @@ import { execFileSync, execSync } from "node:child_process"; -import { chmodSync, mkdtempSync, writeFileSync } from "node:fs"; +import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import { validateSwarm } from "@dokploy/server"; -import { describe, expect, it } from "vitest"; +import { afterEach, describe, expect, it } from "vitest"; const resolveBin = (name: string) => execSync(`command -v ${name}`, { encoding: "utf8" }).trim(); @@ -45,20 +45,35 @@ const runValidateSwarm = (sandboxPath: string) => }).trim(); describe("validateSwarm", () => { + const sandboxDirs: string[] = []; + + const makeSandboxTracked = (localNodeState: string) => { + const dir = makeSandbox(localNodeState); + sandboxDirs.push(dir); + return dir; + }; + + afterEach(() => { + while (sandboxDirs.length > 0) { + const dir = sandboxDirs.pop()!; + rmSync(dir, { recursive: true, force: true }); + } + }); + it("reports true when the node is an active swarm member", () => { - expect(runValidateSwarm(makeSandbox("active"))).toBe("true"); + expect(runValidateSwarm(makeSandboxTracked("active"))).toBe("true"); }); it("reports false when the node is not part of any swarm (LocalNodeState=inactive)", () => { // Regression: the buggy `grep -q 'active'` matched `inactive` as a // substring (in+active), falsely reporting isSwarmInstalled=true. - expect(runValidateSwarm(makeSandbox("inactive"))).toBe("false"); + expect(runValidateSwarm(makeSandboxTracked("inactive"))).toBe("false"); }); it.each(["pending", "error", "locked"])( "reports false for the non-active LocalNodeState=%s", (state) => { - expect(runValidateSwarm(makeSandbox(state))).toBe("false"); + expect(runValidateSwarm(makeSandboxTracked(state))).toBe("false"); }, ); });