mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-29 13:02:10 +03: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 () => {
|
it("uses OpenAI batch uploads when enabled", async () => {
|
||||||
|
const restoreTimeouts = useFastShortTimeouts();
|
||||||
const content = ["hello", "from", "batch"].join("\n\n");
|
const content = ["hello", "from", "batch"].join("\n\n");
|
||||||
await fs.writeFile(path.join(workspaceDir, "memory", "2026-01-07.md"), content);
|
await fs.writeFile(path.join(workspaceDir, "memory", "2026-01-07.md"), content);
|
||||||
|
|
||||||
@@ -162,6 +163,7 @@ describe("memory indexing with OpenAI batches", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
const result = await getMemorySearchManager({ cfg, agentId: "main" });
|
const result = await getMemorySearchManager({ cfg, agentId: "main" });
|
||||||
expect(result.manager).not.toBeNull();
|
expect(result.manager).not.toBeNull();
|
||||||
if (!result.manager) {
|
if (!result.manager) {
|
||||||
@@ -183,6 +185,9 @@ describe("memory indexing with OpenAI batches", () => {
|
|||||||
expect(embedBatch).not.toHaveBeenCalled();
|
expect(embedBatch).not.toHaveBeenCalled();
|
||||||
expect(fetchMock).toHaveBeenCalled();
|
expect(fetchMock).toHaveBeenCalled();
|
||||||
expect(labels.some((label) => label.toLowerCase().includes("batch"))).toBe(true);
|
expect(labels.some((label) => label.toLowerCase().includes("batch"))).toBe(true);
|
||||||
|
} finally {
|
||||||
|
restoreTimeouts();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("retries OpenAI batch create on transient failures", async () => {
|
it("retries OpenAI batch create on transient failures", async () => {
|
||||||
|
|||||||
+16
-17
@@ -1,8 +1,8 @@
|
|||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
|
import fsPromises from "node:fs/promises";
|
||||||
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
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 = {
|
const runtime = {
|
||||||
log: vi.fn(),
|
log: vi.fn(),
|
||||||
@@ -10,6 +10,15 @@ const runtime = {
|
|||||||
exit: vi.fn(),
|
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", () => {
|
describe("web logout", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
@@ -20,38 +29,28 @@ describe("web logout", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("deletes cached credentials when present", { timeout: 60_000 }, async () => {
|
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 { 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.mkdirSync(authDir, { recursive: true });
|
||||||
fs.writeFileSync(path.join(authDir, "creds.json"), "{}");
|
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(result).toBe(true);
|
||||||
expect(fs.existsSync(authDir)).toBe(false);
|
expect(fs.existsSync(authDir)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("no-ops when nothing to delete", { timeout: 60_000 }, async () => {
|
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 { 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(result).toBe(false);
|
||||||
expect(runtime.log).toHaveBeenCalled();
|
expect(runtime.log).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps shared oauth.json when using legacy auth dir", async () => {
|
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 { logoutWeb } = await import("./session.js");
|
||||||
|
|
||||||
const { resolveOAuthDir } = await import("../config/paths.js");
|
|
||||||
const credsDir = resolveOAuthDir();
|
|
||||||
|
|
||||||
fs.mkdirSync(credsDir, { recursive: true });
|
fs.mkdirSync(credsDir, { recursive: true });
|
||||||
fs.writeFileSync(path.join(credsDir, "creds.json"), "{}");
|
fs.writeFileSync(path.join(credsDir, "creds.json"), "{}");
|
||||||
fs.writeFileSync(path.join(credsDir, "oauth.json"), '{"token":true}');
|
fs.writeFileSync(path.join(credsDir, "oauth.json"), '{"token":true}');
|
||||||
|
|||||||
Reference in New Issue
Block a user