mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-24 15:41:40 +00:00
63 lines
2.1 KiB
TypeScript
63 lines
2.1 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const getLatestSubagentRunByChildSessionKeyMock = vi.fn();
|
|
const replaceSubagentRunAfterSteerMock = vi.fn();
|
|
|
|
vi.mock("../agents/subagent-registry-read.js", async () => {
|
|
const actual = await vi.importActual<typeof import("../agents/subagent-registry-read.js")>(
|
|
"../agents/subagent-registry-read.js",
|
|
);
|
|
return {
|
|
...actual,
|
|
getLatestSubagentRunByChildSessionKey: (...args: unknown[]) =>
|
|
getLatestSubagentRunByChildSessionKeyMock(...args),
|
|
};
|
|
});
|
|
|
|
vi.mock("./session-subagent-reactivation.runtime.js", () => ({
|
|
replaceSubagentRunAfterSteer: (...args: unknown[]) => replaceSubagentRunAfterSteerMock(...args),
|
|
}));
|
|
|
|
import { reactivateCompletedSubagentSession } from "./session-subagent-reactivation.js";
|
|
|
|
describe("reactivateCompletedSubagentSession", () => {
|
|
beforeEach(() => {
|
|
getLatestSubagentRunByChildSessionKeyMock.mockReset();
|
|
replaceSubagentRunAfterSteerMock.mockReset();
|
|
});
|
|
|
|
it("reactivates the newest ended row even when stale active rows still exist for the same child session", async () => {
|
|
const childSessionKey = "agent:main:subagent:followup-race";
|
|
const latestEndedRun = {
|
|
runId: "run-current-ended",
|
|
childSessionKey,
|
|
requesterSessionKey: "agent:main:main",
|
|
requesterDisplayKey: "main",
|
|
task: "current ended task",
|
|
cleanup: "keep" as const,
|
|
createdAt: 20,
|
|
startedAt: 21,
|
|
endedAt: 22,
|
|
outcome: { status: "ok" as const },
|
|
};
|
|
|
|
getLatestSubagentRunByChildSessionKeyMock.mockReturnValue(latestEndedRun);
|
|
replaceSubagentRunAfterSteerMock.mockReturnValue(true);
|
|
|
|
await expect(
|
|
reactivateCompletedSubagentSession({
|
|
sessionKey: childSessionKey,
|
|
runId: "run-next",
|
|
}),
|
|
).resolves.toBe(true);
|
|
|
|
expect(getLatestSubagentRunByChildSessionKeyMock).toHaveBeenCalledWith(childSessionKey);
|
|
expect(replaceSubagentRunAfterSteerMock).toHaveBeenCalledWith({
|
|
previousRunId: "run-current-ended",
|
|
nextRunId: "run-next",
|
|
fallback: latestEndedRun,
|
|
runTimeoutSeconds: 0,
|
|
});
|
|
});
|
|
});
|