mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-17 20:21:13 +00:00
test: reduce models-config temp-home churn
This commit is contained in:
@@ -12,7 +12,12 @@ import { resetModelsJsonReadyCacheForTest } from "./models-config.js";
|
||||
import { resolveImplicitProviders } from "./models-config.providers.implicit.js";
|
||||
|
||||
export function withModelsTempHome<T>(fn: (home: string) => Promise<T>): Promise<T> {
|
||||
return withTempHomeBase(fn, { prefix: "openclaw-models-" });
|
||||
// Models-config tests do not exercise session persistence; skip draining
|
||||
// unrelated session lock state during temp-home teardown.
|
||||
return withTempHomeBase(fn, {
|
||||
prefix: "openclaw-models-",
|
||||
skipSessionCleanup: true,
|
||||
});
|
||||
}
|
||||
|
||||
export function installModelsConfigTestHooks(opts?: { restoreFetch?: boolean }) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { resolveOpenClawAgentDir } from "./agent-paths.js";
|
||||
import {
|
||||
CUSTOM_PROXY_MODELS_CONFIG,
|
||||
@@ -119,12 +119,14 @@ async function runEnvProviderCase(params: {
|
||||
}
|
||||
|
||||
describe("models-config", () => {
|
||||
beforeEach(async () => {
|
||||
vi.resetModules();
|
||||
beforeAll(async () => {
|
||||
({ clearConfigCache, clearRuntimeConfigSnapshot } = await import("../config/config.js"));
|
||||
({ clearRuntimeAuthProfileStoreSnapshots } = await import("./auth-profiles/store.js"));
|
||||
({ ensureOpenClawModelsJson, resetModelsJsonReadyCacheForTest } =
|
||||
await import("./models-config.js"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
clearRuntimeAuthProfileStoreSnapshots();
|
||||
clearRuntimeConfigSnapshot();
|
||||
clearConfigCache();
|
||||
|
||||
@@ -101,7 +101,11 @@ async function allocateTempHomeBase(prefix: string): Promise<string> {
|
||||
|
||||
export async function withTempHome<T>(
|
||||
fn: (home: string) => Promise<T>,
|
||||
opts: { env?: Record<string, EnvValue>; prefix?: string } = {},
|
||||
opts: {
|
||||
env?: Record<string, EnvValue>;
|
||||
prefix?: string;
|
||||
skipSessionCleanup?: boolean;
|
||||
} = {},
|
||||
): Promise<T> {
|
||||
const prefix = opts.prefix ?? "openclaw-test-home-";
|
||||
const base = await allocateTempHomeBase(prefix);
|
||||
@@ -130,7 +134,9 @@ export async function withTempHome<T>(
|
||||
try {
|
||||
return await fn(base);
|
||||
} finally {
|
||||
await cleanupSessionStateForTest().catch(() => undefined);
|
||||
if (!opts.skipSessionCleanup) {
|
||||
await cleanupSessionStateForTest().catch(() => undefined);
|
||||
}
|
||||
restoreExtraEnv(envSnapshot);
|
||||
restoreEnv(snapshot);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user