mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-22 22:52:03 +00:00
refactor: modernize vitest projects config
This commit is contained in:
@@ -17,7 +17,7 @@ describe("test-projects args", () => {
|
||||
"exec",
|
||||
"vitest",
|
||||
"--config",
|
||||
"vitest.projects.config.ts",
|
||||
"vitest.config.ts",
|
||||
"src/foo.test.ts",
|
||||
]);
|
||||
});
|
||||
@@ -28,7 +28,7 @@ describe("test-projects args", () => {
|
||||
"vitest",
|
||||
"run",
|
||||
"--config",
|
||||
"vitest.projects.config.ts",
|
||||
"vitest.config.ts",
|
||||
"src/foo.test.ts",
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -6,35 +6,30 @@ import type {
|
||||
} from "../src/channels/plugins/types.js";
|
||||
import type { OpenClawConfig } from "../src/config/config.js";
|
||||
import type { OutboundSendDeps } from "../src/infra/outbound/deliver.js";
|
||||
import { resetPluginRuntimeStateForTest, setActivePluginRegistry } from "../src/plugins/runtime.js";
|
||||
import type { PluginRegistry } from "../src/plugins/registry.js";
|
||||
import { resetPluginRuntimeStateForTest, setActivePluginRegistry } from "../src/plugins/runtime.js";
|
||||
import { installSharedTestSetup } from "./setup.shared.js";
|
||||
|
||||
const testEnv = installSharedTestSetup();
|
||||
|
||||
const [
|
||||
{ resetContextWindowCacheForTest },
|
||||
{ resetModelsJsonReadyCacheForTest },
|
||||
{ drainSessionWriteLockStateForTest, resetSessionWriteLockStateForTest },
|
||||
{ createTopLevelChannelReplyToModeResolver },
|
||||
{ createTestRegistry },
|
||||
{ cleanupSessionStateForTest },
|
||||
] = await Promise.all([
|
||||
import("../src/agents/context.js"),
|
||||
import("../src/agents/models-config.js"),
|
||||
import("../src/agents/session-write-lock.js"),
|
||||
import("../src/channels/plugins/threading-helpers.js"),
|
||||
import("../src/test-utils/channel-plugins.js"),
|
||||
import("../src/test-utils/session-state-cleanup.js"),
|
||||
]);
|
||||
|
||||
const WORKER_RUNTIME_STATE = Symbol.for("openclaw.testSetupRuntimeState");
|
||||
const WORKER_RUNTIME_DEPS = Symbol.for("openclaw.testSetupRuntimeDeps");
|
||||
|
||||
type WorkerRuntimeState = {
|
||||
defaultPluginRegistry: PluginRegistry | null;
|
||||
materializedDefaultPluginRegistry: PluginRegistry | null;
|
||||
};
|
||||
|
||||
type WorkerRuntimeDeps = {
|
||||
resetContextWindowCacheForTest: typeof import("../src/agents/context.js").resetContextWindowCacheForTest;
|
||||
resetModelsJsonReadyCacheForTest: typeof import("../src/agents/models-config.js").resetModelsJsonReadyCacheForTest;
|
||||
drainSessionWriteLockStateForTest: typeof import("../src/agents/session-write-lock.js").drainSessionWriteLockStateForTest;
|
||||
resetSessionWriteLockStateForTest: typeof import("../src/agents/session-write-lock.js").resetSessionWriteLockStateForTest;
|
||||
createTopLevelChannelReplyToModeResolver: typeof import("../src/channels/plugins/threading-helpers.js").createTopLevelChannelReplyToModeResolver;
|
||||
createTestRegistry: typeof import("../src/test-utils/channel-plugins.js").createTestRegistry;
|
||||
cleanupSessionStateForTest: typeof import("../src/test-utils/session-state-cleanup.js").cleanupSessionStateForTest;
|
||||
};
|
||||
|
||||
const workerRuntimeState = (() => {
|
||||
const globalState = globalThis as typeof globalThis & {
|
||||
[WORKER_RUNTIME_STATE]?: WorkerRuntimeState;
|
||||
@@ -48,6 +43,52 @@ const workerRuntimeState = (() => {
|
||||
return globalState[WORKER_RUNTIME_STATE];
|
||||
})();
|
||||
|
||||
async function loadWorkerRuntimeDeps(): Promise<WorkerRuntimeDeps> {
|
||||
const [
|
||||
{ resetContextWindowCacheForTest },
|
||||
{ resetModelsJsonReadyCacheForTest },
|
||||
{ drainSessionWriteLockStateForTest, resetSessionWriteLockStateForTest },
|
||||
{ createTopLevelChannelReplyToModeResolver },
|
||||
{ createTestRegistry },
|
||||
{ cleanupSessionStateForTest },
|
||||
] = await Promise.all([
|
||||
import("../src/agents/context.js"),
|
||||
import("../src/agents/models-config.js"),
|
||||
import("../src/agents/session-write-lock.js"),
|
||||
import("../src/channels/plugins/threading-helpers.js"),
|
||||
import("../src/test-utils/channel-plugins.js"),
|
||||
import("../src/test-utils/session-state-cleanup.js"),
|
||||
]);
|
||||
|
||||
return {
|
||||
resetContextWindowCacheForTest,
|
||||
resetModelsJsonReadyCacheForTest,
|
||||
drainSessionWriteLockStateForTest,
|
||||
resetSessionWriteLockStateForTest,
|
||||
createTopLevelChannelReplyToModeResolver,
|
||||
createTestRegistry,
|
||||
cleanupSessionStateForTest,
|
||||
};
|
||||
}
|
||||
|
||||
const workerRuntimeDeps = await (() => {
|
||||
const globalState = globalThis as typeof globalThis & {
|
||||
[WORKER_RUNTIME_DEPS]?: Promise<WorkerRuntimeDeps>;
|
||||
};
|
||||
globalState[WORKER_RUNTIME_DEPS] ??= loadWorkerRuntimeDeps();
|
||||
return globalState[WORKER_RUNTIME_DEPS];
|
||||
})();
|
||||
|
||||
const {
|
||||
resetContextWindowCacheForTest,
|
||||
resetModelsJsonReadyCacheForTest,
|
||||
drainSessionWriteLockStateForTest,
|
||||
resetSessionWriteLockStateForTest,
|
||||
createTopLevelChannelReplyToModeResolver,
|
||||
createTestRegistry,
|
||||
cleanupSessionStateForTest,
|
||||
} = workerRuntimeDeps;
|
||||
|
||||
const pickSendFn = (id: ChannelId, deps?: OutboundSendDeps) => {
|
||||
return deps?.[id] as ((...args: unknown[]) => Promise<unknown>) | undefined;
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
|
||||
import baseConfig, { resolveLocalVitestMaxWorkers } from "../vitest.config.ts";
|
||||
|
||||
describe("resolveLocalVitestMaxWorkers", () => {
|
||||
it("defaults local runs to a single worker even on larger hosts", () => {
|
||||
it("uses a moderate local worker cap on larger hosts", () => {
|
||||
expect(
|
||||
resolveLocalVitestMaxWorkers(
|
||||
{
|
||||
@@ -13,7 +13,7 @@ describe("resolveLocalVitestMaxWorkers", () => {
|
||||
totalMemoryBytes: 64 * 1024 ** 3,
|
||||
},
|
||||
),
|
||||
).toBe(1);
|
||||
).toBe(4);
|
||||
});
|
||||
|
||||
it("lets OPENCLAW_VITEST_MAX_WORKERS override the inferred cap", () => {
|
||||
@@ -45,7 +45,7 @@ describe("resolveLocalVitestMaxWorkers", () => {
|
||||
).toBe(3);
|
||||
});
|
||||
|
||||
it("keeps memory-constrained hosts on the same single-worker default", () => {
|
||||
it("keeps memory-constrained hosts conservative", () => {
|
||||
expect(
|
||||
resolveLocalVitestMaxWorkers(
|
||||
{},
|
||||
@@ -54,10 +54,10 @@ describe("resolveLocalVitestMaxWorkers", () => {
|
||||
totalMemoryBytes: 16 * 1024 ** 3,
|
||||
},
|
||||
),
|
||||
).toBe(1);
|
||||
).toBe(2);
|
||||
});
|
||||
|
||||
it("keeps roomy hosts on the same single-worker default", () => {
|
||||
it("lets roomy hosts use more local parallelism", () => {
|
||||
expect(
|
||||
resolveLocalVitestMaxWorkers(
|
||||
{},
|
||||
@@ -66,7 +66,7 @@ describe("resolveLocalVitestMaxWorkers", () => {
|
||||
totalMemoryBytes: 128 * 1024 ** 3,
|
||||
},
|
||||
),
|
||||
).toBe(1);
|
||||
).toBe(6);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import projectsConfig from "../vitest.projects.config.ts";
|
||||
import baseConfig from "../vitest.config.ts";
|
||||
|
||||
describe("projects vitest config", () => {
|
||||
it("defines named unit and boundary projects", () => {
|
||||
expect(projectsConfig.test?.projects).toHaveLength(2);
|
||||
expect(projectsConfig.test?.projects?.map((project) => project.test?.name)).toEqual([
|
||||
"unit",
|
||||
"boundary",
|
||||
it("defines unit and boundary project config files at the root", () => {
|
||||
expect(baseConfig.test?.projects).toEqual([
|
||||
"vitest.unit.config.ts",
|
||||
"vitest.boundary.config.ts",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user