



















11// Status scan shared tests cover gateway probe snapshots, Tailscale URLs, and shared scan helpers.
2-import fs from "node:fs";
3-import os from "node:os";
42import path from "node:path";
53import { DatabaseSync } from "node:sqlite";
6-import { beforeEach, describe, expect, it, vi } from "vitest";
4+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5+import { cleanupTempDirs, makeTempDir } from "../../test/helpers/temp-dir.js";
76import {
87buildTailscaleHttpsUrl,
98resolveGatewayProbeSnapshot,
109resolveSharedMemoryStatusSnapshot,
1110} from "./status.scan.shared.js";
121112+const tempDirs: string[] = [];
13+14+afterEach(() => {
15+cleanupTempDirs(tempDirs);
16+});
17+1318const mocks = vi.hoisted(() => ({
1419buildGatewayConnectionDetailsWithResolvers: vi.fn(),
1520resolveGatewayProbeTarget: vi.fn(),
@@ -574,7 +579,7 @@ describe("resolveSharedMemoryStatusSnapshot", () => {
574579});
575580576581it("recognizes shipped memory tables before the manager migrates them", async () => {
577-const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-status-memory-"));
582+const tempDir = makeTempDir(tempDirs, "openclaw-status-memory-");
578583const databasePath = path.join(tempDir, "openclaw-agent.sqlite");
579584const db = new DatabaseSync(databasePath);
580585db.exec(`
@@ -616,25 +621,21 @@ describe("resolveSharedMemoryStatusSnapshot", () => {
616621};
617622const getMemorySearchManager = vi.fn(async () => ({ manager }));
618623619-try {
620-const result = await resolveSharedMemoryStatusSnapshot({
621-cfg: {},
622-agentStatus: { defaultId: "main" },
623-memoryPlugin: { enabled: true, slot: "memory-core" },
624-resolveMemoryConfig: vi.fn(() => ({ store: { databasePath } })),
625- getMemorySearchManager,
626-requireDefaultDatabasePath: () => databasePath,
627-});
628-629-expect(getMemorySearchManager).toHaveBeenCalledOnce();
630-expect(result?.files).toBe(1);
631-} finally {
632-fs.rmSync(tempDir, { recursive: true, force: true });
633-}
624+const result = await resolveSharedMemoryStatusSnapshot({
625+cfg: {},
626+agentStatus: { defaultId: "main" },
627+memoryPlugin: { enabled: true, slot: "memory-core" },
628+resolveMemoryConfig: vi.fn(() => ({ store: { databasePath } })),
629+ getMemorySearchManager,
630+requireDefaultDatabasePath: () => databasePath,
631+});
632+633+expect(getMemorySearchManager).toHaveBeenCalledOnce();
634+expect(result?.files).toBe(1);
634635});
635636636637it("does not initialize memory status for an agent database owned by another feature", async () => {
637-const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-status-memory-"));
638+const tempDir = makeTempDir(tempDirs, "openclaw-status-memory-");
638639const databasePath = path.join(tempDir, "openclaw-agent.sqlite");
639640const db = new DatabaseSync(databasePath);
640641db.exec(`
@@ -649,20 +650,16 @@ describe("resolveSharedMemoryStatusSnapshot", () => {
649650db.close();
650651const getMemorySearchManager = vi.fn(async () => ({ manager: null }));
651652652-try {
653-const result = await resolveSharedMemoryStatusSnapshot({
654-cfg: {},
655-agentStatus: { defaultId: "main" },
656-memoryPlugin: { enabled: true, slot: "memory-core" },
657-resolveMemoryConfig: vi.fn(() => ({ store: { databasePath } })),
658- getMemorySearchManager,
659-requireDefaultDatabasePath: () => databasePath,
660-});
661-662-expect(result).toBeNull();
663-expect(getMemorySearchManager).not.toHaveBeenCalled();
664-} finally {
665-fs.rmSync(tempDir, { recursive: true, force: true });
666-}
653+const result = await resolveSharedMemoryStatusSnapshot({
654+cfg: {},
655+agentStatus: { defaultId: "main" },
656+memoryPlugin: { enabled: true, slot: "memory-core" },
657+resolveMemoryConfig: vi.fn(() => ({ store: { databasePath } })),
658+ getMemorySearchManager,
659+requireDefaultDatabasePath: () => databasePath,
660+});
661+662+expect(result).toBeNull();
663+expect(getMemorySearchManager).not.toHaveBeenCalled();
667664});
668665});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。