mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:10:45 +00:00
test: speed up auto-reply reply shard
This commit is contained in:
@@ -65,6 +65,42 @@ vi.mock("../../agents/auth-profiles/store.js", () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../../agents/model-auth.js", () => {
|
||||
const store = () => ({
|
||||
version: 1,
|
||||
profiles: authProfilesStoreMock.profiles,
|
||||
});
|
||||
const hasWorkspaceCredential = (env: NodeJS.ProcessEnv = process.env) =>
|
||||
Boolean(env.WORKSPACE_MODEL_LIST_CREDENTIALS || env.WORKSPACE_MODEL_CREDENTIALS);
|
||||
return {
|
||||
ensureAuthProfileStore: store,
|
||||
hasRuntimeAvailableProviderAuth: ({
|
||||
provider,
|
||||
env,
|
||||
}: {
|
||||
provider: string;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
}) => provider === "anthropic" && hasWorkspaceCredential(env),
|
||||
resolveAuthProfileOrder: ({ provider }: { provider: string }) =>
|
||||
Object.entries(authProfilesStoreMock.profiles)
|
||||
.filter(([, profile]) => profile.provider === provider)
|
||||
.map(([profileId]) => profileId),
|
||||
resolveEnvApiKey: (provider: string, env: NodeJS.ProcessEnv = process.env) => {
|
||||
if (provider !== "anthropic") {
|
||||
return null;
|
||||
}
|
||||
if (env.WORKSPACE_MODEL_CREDENTIALS) {
|
||||
return { apiKey: "sk-workspace", source: "workspace model credentials" };
|
||||
}
|
||||
if (env.WORKSPACE_MODEL_LIST_CREDENTIALS) {
|
||||
return { apiKey: "sk-workspace", source: "workspace model list credentials" };
|
||||
}
|
||||
return null;
|
||||
},
|
||||
resolveUsableCustomProviderApiKey: () => null,
|
||||
};
|
||||
});
|
||||
|
||||
import { resolveAgentDir, resolveSessionAgentId } from "../../agents/agent-scope.js";
|
||||
import {
|
||||
clearRuntimeAuthProfileStoreSnapshots,
|
||||
|
||||
@@ -12,6 +12,11 @@ const hookRunnerMocks = vi.hoisted(() => ({
|
||||
runSessionStart: vi.fn<HookRunner["runSessionStart"]>(),
|
||||
runSessionEnd: vi.fn<HookRunner["runSessionEnd"]>(),
|
||||
}));
|
||||
const sessionCleanupMocks = vi.hoisted(() => ({
|
||||
closeTrackedBrowserTabsForSessions: vi.fn(async () => 0),
|
||||
resetRegisteredAgentHarnessSessions: vi.fn(async () => undefined),
|
||||
retireSessionMcpRuntime: vi.fn(async () => false),
|
||||
}));
|
||||
|
||||
vi.mock("../../plugins/hook-runner-global.js", () => ({
|
||||
getGlobalHookRunner: () =>
|
||||
@@ -22,6 +27,39 @@ vi.mock("../../plugins/hook-runner-global.js", () => ({
|
||||
}) as unknown as HookRunner,
|
||||
}));
|
||||
|
||||
vi.mock("../../agents/harness/registry.js", () => ({
|
||||
resetRegisteredAgentHarnessSessions: sessionCleanupMocks.resetRegisteredAgentHarnessSessions,
|
||||
}));
|
||||
|
||||
vi.mock("../../agents/pi-bundle-mcp-tools.js", () => ({
|
||||
retireSessionMcpRuntime: sessionCleanupMocks.retireSessionMcpRuntime,
|
||||
}));
|
||||
|
||||
vi.mock("../../plugin-sdk/browser-maintenance.js", () => ({
|
||||
closeTrackedBrowserTabsForSessions: sessionCleanupMocks.closeTrackedBrowserTabsForSessions,
|
||||
}));
|
||||
|
||||
vi.mock("../../agents/session-write-lock.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("../../agents/session-write-lock.js")>(
|
||||
"../../agents/session-write-lock.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
acquireSessionWriteLock: vi.fn(async () => ({ release: async () => {} })),
|
||||
resolveSessionLockMaxHoldFromTimeout: vi.fn(
|
||||
({
|
||||
timeoutMs,
|
||||
graceMs = 2 * 60 * 1000,
|
||||
minMs = 5 * 60 * 1000,
|
||||
}: {
|
||||
timeoutMs: number;
|
||||
graceMs?: number;
|
||||
minMs?: number;
|
||||
}) => Math.max(minMs, timeoutMs + graceMs),
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
async function createStorePath(prefix: string): Promise<string> {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), `${prefix}-`));
|
||||
return path.join(root, "sessions.json");
|
||||
@@ -102,6 +140,9 @@ describe("session hook context wiring", () => {
|
||||
hookRunnerMocks.hasHooks.mockReset();
|
||||
hookRunnerMocks.runSessionStart.mockReset();
|
||||
hookRunnerMocks.runSessionEnd.mockReset();
|
||||
sessionCleanupMocks.closeTrackedBrowserTabsForSessions.mockClear();
|
||||
sessionCleanupMocks.resetRegisteredAgentHarnessSessions.mockClear();
|
||||
sessionCleanupMocks.retireSessionMcpRuntime.mockClear();
|
||||
hookRunnerMocks.runSessionStart.mockResolvedValue(undefined);
|
||||
hookRunnerMocks.runSessionEnd.mockResolvedValue(undefined);
|
||||
hookRunnerMocks.hasHooks.mockImplementation(
|
||||
|
||||
@@ -5,8 +5,6 @@ export function createAutoReplyReplyVitestConfig(env?: Record<string, string | u
|
||||
return createScopedVitestConfig([...autoReplyReplySubtreeTestInclude], {
|
||||
dir: "src/auto-reply",
|
||||
env,
|
||||
fileParallelism: false,
|
||||
maxWorkers: 1,
|
||||
name: "auto-reply-reply",
|
||||
sequence: {
|
||||
groupOrder: 1,
|
||||
|
||||
Reference in New Issue
Block a user