mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-07 22:44:16 +00:00
perf(test): speed up memory batch + web logout
This commit is contained in:
@@ -79,6 +79,7 @@ describe("memory indexing with OpenAI batches", () => {
|
||||
});
|
||||
|
||||
it("uses OpenAI batch uploads when enabled", async () => {
|
||||
const restoreTimeouts = useFastShortTimeouts();
|
||||
const content = ["hello", "from", "batch"].join("\n\n");
|
||||
await fs.writeFile(path.join(workspaceDir, "memory", "2026-01-07.md"), content);
|
||||
|
||||
@@ -162,27 +163,31 @@ describe("memory indexing with OpenAI batches", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const result = await getMemorySearchManager({ cfg, agentId: "main" });
|
||||
expect(result.manager).not.toBeNull();
|
||||
if (!result.manager) {
|
||||
throw new Error("manager missing");
|
||||
}
|
||||
manager = result.manager;
|
||||
const labels: string[] = [];
|
||||
await manager.sync({
|
||||
force: true,
|
||||
progress: (update) => {
|
||||
if (update.label) {
|
||||
labels.push(update.label);
|
||||
}
|
||||
},
|
||||
});
|
||||
try {
|
||||
const result = await getMemorySearchManager({ cfg, agentId: "main" });
|
||||
expect(result.manager).not.toBeNull();
|
||||
if (!result.manager) {
|
||||
throw new Error("manager missing");
|
||||
}
|
||||
manager = result.manager;
|
||||
const labels: string[] = [];
|
||||
await manager.sync({
|
||||
force: true,
|
||||
progress: (update) => {
|
||||
if (update.label) {
|
||||
labels.push(update.label);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const status = manager.status();
|
||||
expect(status.chunks).toBeGreaterThan(0);
|
||||
expect(embedBatch).not.toHaveBeenCalled();
|
||||
expect(fetchMock).toHaveBeenCalled();
|
||||
expect(labels.some((label) => label.toLowerCase().includes("batch"))).toBe(true);
|
||||
const status = manager.status();
|
||||
expect(status.chunks).toBeGreaterThan(0);
|
||||
expect(embedBatch).not.toHaveBeenCalled();
|
||||
expect(fetchMock).toHaveBeenCalled();
|
||||
expect(labels.some((label) => label.toLowerCase().includes("batch"))).toBe(true);
|
||||
} finally {
|
||||
restoreTimeouts();
|
||||
}
|
||||
});
|
||||
|
||||
it("retries OpenAI batch create on transient failures", async () => {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import fs from "node:fs";
|
||||
import fsPromises from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { isPathWithinBase } from "../../test/helpers/paths.js";
|
||||
import { withTempHome } from "../../test/helpers/temp-home.js";
|
||||
|
||||
const runtime = {
|
||||
log: vi.fn(),
|
||||
@@ -10,6 +10,15 @@ const runtime = {
|
||||
exit: vi.fn(),
|
||||
};
|
||||
|
||||
async function withTempDir<T>(fn: (dir: string) => Promise<T>): Promise<T> {
|
||||
const dir = await fsPromises.mkdtemp(path.join(os.tmpdir(), "openclaw-test-web-logout-"));
|
||||
try {
|
||||
return await fn(dir);
|
||||
} finally {
|
||||
await fsPromises.rm(dir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
describe("web logout", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
@@ -20,38 +29,28 @@ describe("web logout", () => {
|
||||
});
|
||||
|
||||
it("deletes cached credentials when present", { timeout: 60_000 }, async () => {
|
||||
await withTempHome(async (home) => {
|
||||
await withTempDir(async (authDir) => {
|
||||
const { logoutWeb } = await import("./session.js");
|
||||
const { resolveDefaultWebAuthDir } = await import("./auth-store.js");
|
||||
const authDir = resolveDefaultWebAuthDir();
|
||||
|
||||
expect(isPathWithinBase(home, authDir)).toBe(true);
|
||||
|
||||
fs.mkdirSync(authDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(authDir, "creds.json"), "{}");
|
||||
const result = await logoutWeb({ runtime: runtime as never });
|
||||
|
||||
const result = await logoutWeb({ authDir, runtime: runtime as never });
|
||||
expect(result).toBe(true);
|
||||
expect(fs.existsSync(authDir)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
it("no-ops when nothing to delete", { timeout: 60_000 }, async () => {
|
||||
await withTempHome(async () => {
|
||||
await withTempDir(async (authDir) => {
|
||||
const { logoutWeb } = await import("./session.js");
|
||||
const result = await logoutWeb({ runtime: runtime as never });
|
||||
const result = await logoutWeb({ authDir, runtime: runtime as never });
|
||||
expect(result).toBe(false);
|
||||
expect(runtime.log).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps shared oauth.json when using legacy auth dir", async () => {
|
||||
await withTempHome(async () => {
|
||||
await withTempDir(async (credsDir) => {
|
||||
const { logoutWeb } = await import("./session.js");
|
||||
|
||||
const { resolveOAuthDir } = await import("../config/paths.js");
|
||||
const credsDir = resolveOAuthDir();
|
||||
|
||||
fs.mkdirSync(credsDir, { recursive: true });
|
||||
fs.writeFileSync(path.join(credsDir, "creds.json"), "{}");
|
||||
fs.writeFileSync(path.join(credsDir, "oauth.json"), '{"token":true}');
|
||||
|
||||
Reference in New Issue
Block a user