mirror of
https://fastgit.cc/github.com/openclaw/openclaw
synced 2026-04-30 22:12:32 +08:00
test: isolate agent auth and spawn hotspots
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createPerSenderSessionConfig } from "./test-helpers/session-config.js";
|
||||
|
||||
const callGatewayMock = vi.fn();
|
||||
@@ -17,6 +17,7 @@ let configOverride: Record<string, unknown> = {
|
||||
let addSubagentRunForTests: typeof import("./subagent-registry.js").addSubagentRunForTests;
|
||||
let resetSubagentRegistryForTests: typeof import("./subagent-registry.js").resetSubagentRegistryForTests;
|
||||
let subagentRegistryTesting: typeof import("./subagent-registry.js").__testing;
|
||||
let setSubagentSpawnDepsForTest: typeof import("./subagent-spawn.js").__testing.setDepsForTest;
|
||||
let createSessionsSpawnTool: typeof import("./tools/sessions-spawn-tool.js").createSessionsSpawnTool;
|
||||
|
||||
vi.mock("../config/config.js", async () => {
|
||||
@@ -68,11 +69,18 @@ beforeAll(async () => {
|
||||
addSubagentRunForTests,
|
||||
resetSubagentRegistryForTests,
|
||||
} = await import("./subagent-registry.js"));
|
||||
({
|
||||
__testing: { setDepsForTest: setSubagentSpawnDepsForTest },
|
||||
} = await import("./subagent-spawn.js"));
|
||||
({ createSessionsSpawnTool } = await import("./tools/sessions-spawn-tool.js"));
|
||||
});
|
||||
|
||||
describe("sessions_spawn depth + child limits", () => {
|
||||
beforeEach(() => {
|
||||
setSubagentSpawnDepsForTest({
|
||||
callGateway: (opts) => callGatewayMock(opts),
|
||||
getGlobalHookRunner: () => null,
|
||||
});
|
||||
subagentRegistryTesting.setDepsForTest({
|
||||
captureSubagentCompletionReply: () => Promise.resolve(undefined),
|
||||
cleanupBrowserSessionsForLifecycleEnd: () => Promise.resolve(),
|
||||
@@ -104,6 +112,10 @@ describe("sessions_spawn depth + child limits", () => {
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
setSubagentSpawnDepsForTest();
|
||||
});
|
||||
|
||||
it("rejects spawning when caller depth reaches maxSpawnDepth", async () => {
|
||||
const tool = createSessionsSpawnTool({
|
||||
agentSessionKey: "agent:main:subagent:parent",
|
||||
|
||||
@@ -9,6 +9,11 @@ vi.mock("../plugins/provider-runtime.js", () => ({
|
||||
resolveExternalAuthProfilesWithPlugins: () => [],
|
||||
}));
|
||||
|
||||
vi.mock("./auth-profiles/external-cli-sync.js", () => ({
|
||||
readManagedExternalCliCredential: () => null,
|
||||
syncExternalCliCredentials: () => false,
|
||||
}));
|
||||
|
||||
type AuthProfileStore = Parameters<typeof saveAuthProfileStore>[0];
|
||||
|
||||
async function createAgentDir() {
|
||||
|
||||
Reference in New Issue
Block a user