test: reduce models-config temp-home churn

This commit is contained in:
Peter Steinberger
2026-04-05 17:03:55 +01:00
parent eced1fa905
commit de0d6efc6e
3 changed files with 19 additions and 6 deletions

View File

@@ -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 }) {

View File

@@ -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();

View File

@@ -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 {