test(perf): avoid module reset churn in daemon lifecycle tests

This commit is contained in:
Peter Steinberger
2026-03-02 15:43:11 +00:00
parent 3f2848433a
commit db3d8d82c1

View File

@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
type RestartHealthSnapshot = {
healthy: boolean;
@@ -56,8 +56,13 @@ vi.mock("./lifecycle-core.js", () => ({
}));
describe("runDaemonRestart health checks", () => {
let runDaemonRestart: (opts?: { json?: boolean }) => Promise<boolean>;
beforeAll(async () => {
({ runDaemonRestart } = await import("./lifecycle.js"));
});
beforeEach(() => {
vi.resetModules();
service.readCommand.mockClear();
service.restart.mockClear();
runServiceRestart.mockClear();
@@ -104,7 +109,6 @@ describe("runDaemonRestart health checks", () => {
waitForGatewayHealthyRestart.mockResolvedValueOnce(unhealthy).mockResolvedValueOnce(healthy);
terminateStaleGatewayPids.mockResolvedValue([1993]);
const { runDaemonRestart } = await import("./lifecycle.js");
const result = await runDaemonRestart({ json: true });
expect(result).toBe(true);
@@ -122,8 +126,6 @@ describe("runDaemonRestart health checks", () => {
};
waitForGatewayHealthyRestart.mockResolvedValue(unhealthy);
const { runDaemonRestart } = await import("./lifecycle.js");
await expect(runDaemonRestart({ json: true })).rejects.toMatchObject({
message: "Gateway restart timed out after 60s waiting for health checks.",
hints: ["openclaw gateway status --deep", "openclaw doctor"],