Skip to content

Commit ec2f0ed

Browse files
committed
test: stabilize subagent persistence registry coverage
1 parent 579c50d commit ec2f0ed

1 file changed

Lines changed: 17 additions & 30 deletions

File tree

src/agents/subagent-registry.persistence.test.ts

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,23 @@ import {
77
clearSessionStoreCacheForTest,
88
drainSessionStoreLockQueuesForTest,
99
} from "../config/sessions/store.js";
10+
import { callGateway } from "../gateway/call.js";
11+
import { onAgentEvent } from "../infra/agent-events.js";
1012
import { captureEnv, withEnv } from "../test-utils/env.js";
13+
import { persistSubagentSessionTiming } from "./subagent-registry-helpers.js";
14+
import {
15+
addSubagentRunForTests,
16+
clearSubagentRunSteerRestart,
17+
getLatestSubagentRunByChildSessionKey,
18+
getSubagentRunByChildSessionKey,
19+
initSubagentRegistry,
20+
listSubagentRunsForRequester,
21+
resetSubagentRegistryForTests,
22+
} from "./subagent-registry.js";
23+
import {
24+
loadSubagentRegistryFromDisk,
25+
resolveSubagentRegistryPath,
26+
} from "./subagent-registry.store.js";
1127

1228
const { announceSpy } = vi.hoisted(() => ({
1329
announceSpy: vi.fn(async () => true),
@@ -20,29 +36,6 @@ vi.mock("./subagent-orphan-recovery.js", () => ({
2036
scheduleOrphanRecovery: vi.fn(),
2137
}));
2238

23-
let addSubagentRunForTests: typeof import("./subagent-registry.js").addSubagentRunForTests;
24-
let clearSubagentRunSteerRestart: typeof import("./subagent-registry.js").clearSubagentRunSteerRestart;
25-
let getSubagentRunByChildSessionKey: typeof import("./subagent-registry.js").getSubagentRunByChildSessionKey;
26-
let getLatestSubagentRunByChildSessionKey: typeof import("./subagent-registry.js").getLatestSubagentRunByChildSessionKey;
27-
let initSubagentRegistry: typeof import("./subagent-registry.js").initSubagentRegistry;
28-
let listSubagentRunsForRequester: typeof import("./subagent-registry.js").listSubagentRunsForRequester;
29-
let resetSubagentRegistryForTests: typeof import("./subagent-registry.js").resetSubagentRegistryForTests;
30-
let loadSubagentRegistryFromDisk: typeof import("./subagent-registry.store.js").loadSubagentRegistryFromDisk;
31-
32-
async function loadSubagentRegistryModules(): Promise<void> {
33-
vi.resetModules();
34-
({
35-
addSubagentRunForTests,
36-
clearSubagentRunSteerRestart,
37-
getLatestSubagentRunByChildSessionKey,
38-
getSubagentRunByChildSessionKey,
39-
initSubagentRegistry,
40-
listSubagentRunsForRequester,
41-
resetSubagentRegistryForTests,
42-
} = await import("./subagent-registry.js"));
43-
({ loadSubagentRegistryFromDisk } = await import("./subagent-registry.store.js"));
44-
}
45-
4639
describe("subagent registry persistence", () => {
4740
const envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]);
4841
let tempStateDir: string | null = null;
@@ -184,10 +177,7 @@ describe("subagent registry persistence", () => {
184177
await flushQueuedRegistryWork();
185178
};
186179

187-
beforeEach(async () => {
188-
await loadSubagentRegistryModules();
189-
const { callGateway } = await import("../gateway/call.js");
190-
const { onAgentEvent } = await import("../infra/agent-events.js");
180+
beforeEach(() => {
191181
vi.mocked(callGateway).mockReset();
192182
vi.mocked(callGateway).mockResolvedValue({
193183
status: "ok",
@@ -214,7 +204,6 @@ describe("subagent registry persistence", () => {
214204
tempStateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-subagent-"));
215205
process.env.OPENCLAW_STATE_DIR = tempStateDir;
216206

217-
const { persistSubagentSessionTiming } = await import("./subagent-registry-helpers.js");
218207
const now = Date.now();
219208
const startedAt = now;
220209
const endedAt = now + 500;
@@ -601,8 +590,6 @@ describe("subagent registry persistence", () => {
601590

602591
it("uses isolated temp state when OPENCLAW_STATE_DIR is unset in tests", async () => {
603592
delete process.env.OPENCLAW_STATE_DIR;
604-
vi.resetModules();
605-
const { resolveSubagentRegistryPath } = await import("./subagent-registry.store.js");
606593
const registryPath = resolveSubagentRegistryPath();
607594
expect(registryPath).toContain(path.join(os.tmpdir(), "openclaw-test-state"));
608595
});

0 commit comments

Comments
 (0)