mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-20 22:40:58 +00:00
fix(ci): reduce test runtime retention hotspots
This commit is contained in:
@@ -1,19 +1,12 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { listChannelPlugins } from "../channels/plugins/index.js";
|
||||
import type { ChannelPlugin } from "../channels/plugins/types.js";
|
||||
import { buildChannelSummary } from "./channel-summary.js";
|
||||
|
||||
vi.mock("../channels/plugins/index.js", () => ({
|
||||
listChannelPlugins: vi.fn(),
|
||||
}));
|
||||
|
||||
let buildChannelSummary: typeof import("./channel-summary.js").buildChannelSummary;
|
||||
let listChannelPlugins: typeof import("../channels/plugins/index.js").listChannelPlugins;
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
({ buildChannelSummary } = await import("./channel-summary.js"));
|
||||
({ listChannelPlugins } = await import("../channels/plugins/index.js"));
|
||||
});
|
||||
|
||||
function makeSlackHttpSummaryPlugin(): ChannelPlugin {
|
||||
return {
|
||||
id: "slack",
|
||||
|
||||
@@ -104,16 +104,26 @@ describe("QmdMemoryManager", () => {
|
||||
let stateDir: string;
|
||||
let cfg: OpenClawConfig;
|
||||
const agentId = "main";
|
||||
const openManagers = new Set<QmdMemoryManager>();
|
||||
|
||||
function trackManager<T extends QmdMemoryManager | null>(manager: T): T {
|
||||
if (manager) {
|
||||
openManagers.add(manager);
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
async function createManager(params?: { mode?: "full" | "status"; cfg?: OpenClawConfig }) {
|
||||
const cfgToUse = params?.cfg ?? cfg;
|
||||
const resolved = resolveMemoryBackendConfig({ cfg: cfgToUse, agentId });
|
||||
const manager = await QmdMemoryManager.create({
|
||||
cfg: cfgToUse,
|
||||
agentId,
|
||||
resolved,
|
||||
mode: params?.mode ?? "status",
|
||||
});
|
||||
const manager = trackManager(
|
||||
await QmdMemoryManager.create({
|
||||
cfg: cfgToUse,
|
||||
agentId,
|
||||
resolved,
|
||||
mode: params?.mode ?? "status",
|
||||
}),
|
||||
);
|
||||
expect(manager).toBeTruthy();
|
||||
if (!manager) {
|
||||
throw new Error("manager missing");
|
||||
@@ -161,7 +171,14 @@ describe("QmdMemoryManager", () => {
|
||||
} as OpenClawConfig;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
Array.from(openManagers, async (manager) => {
|
||||
await manager.close();
|
||||
}),
|
||||
);
|
||||
openManagers.clear();
|
||||
await fs.rm(tmpRoot, { recursive: true, force: true });
|
||||
vi.useRealTimers();
|
||||
delete process.env.OPENCLAW_STATE_DIR;
|
||||
if (originalPath === undefined) {
|
||||
@@ -365,12 +382,14 @@ describe("QmdMemoryManager", () => {
|
||||
});
|
||||
|
||||
const resolved = resolveMemoryBackendConfig({ cfg, agentId: devAgentId });
|
||||
const manager = await QmdMemoryManager.create({
|
||||
cfg,
|
||||
agentId: devAgentId,
|
||||
resolved,
|
||||
mode: "full",
|
||||
});
|
||||
const manager = trackManager(
|
||||
await QmdMemoryManager.create({
|
||||
cfg,
|
||||
agentId: devAgentId,
|
||||
resolved,
|
||||
mode: "full",
|
||||
}),
|
||||
);
|
||||
expect(manager).toBeTruthy();
|
||||
await manager?.close();
|
||||
|
||||
@@ -755,7 +774,7 @@ describe("QmdMemoryManager", () => {
|
||||
const resolved = resolveMemoryBackendConfig({ cfg, agentId });
|
||||
const createPromise = QmdMemoryManager.create({ cfg, agentId, resolved, mode: "status" });
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
const manager = await createPromise;
|
||||
const manager = trackManager(await createPromise);
|
||||
expect(manager).toBeTruthy();
|
||||
if (!manager) {
|
||||
throw new Error("manager missing");
|
||||
@@ -1985,7 +2004,7 @@ describe("QmdMemoryManager", () => {
|
||||
const resolved = resolveMemoryBackendConfig({ cfg, agentId });
|
||||
const createPromise = QmdMemoryManager.create({ cfg, agentId, resolved, mode: "status" });
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
const manager = await createPromise;
|
||||
const manager = trackManager(await createPromise);
|
||||
expect(manager).toBeTruthy();
|
||||
if (!manager) {
|
||||
throw new Error("manager missing");
|
||||
|
||||
Reference in New Issue
Block a user