mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 22:18:27 +00:00
test(agents): dedupe sessions_spawn requester run setup
This commit is contained in:
@@ -11,6 +11,24 @@ import {
|
||||
} from "./subagent-registry.js";
|
||||
|
||||
describe("sessions_spawn requesterOrigin threading", () => {
|
||||
const spawnAndReadRequesterRun = async (opts?: { agentThreadId?: number }) => {
|
||||
const tool = await getSessionsSpawnTool({
|
||||
agentSessionKey: "main",
|
||||
agentChannel: "telegram",
|
||||
agentTo: "telegram:123",
|
||||
...(opts?.agentThreadId === undefined ? {} : { agentThreadId: opts.agentThreadId }),
|
||||
});
|
||||
const result = await tool.execute("call", {
|
||||
task: "do thing",
|
||||
runTimeoutSeconds: 1,
|
||||
});
|
||||
expect(result.details).toMatchObject({ status: "accepted", runId: "run-1" });
|
||||
|
||||
const runs = listSubagentRunsForRequester("main");
|
||||
expect(runs).toHaveLength(1);
|
||||
return runs[0];
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
const callGatewayMock = getCallGatewayMock();
|
||||
resetSubagentRegistryForTests();
|
||||
@@ -36,22 +54,8 @@ describe("sessions_spawn requesterOrigin threading", () => {
|
||||
});
|
||||
|
||||
it("captures threadId in requesterOrigin", async () => {
|
||||
const tool = await getSessionsSpawnTool({
|
||||
agentSessionKey: "main",
|
||||
agentChannel: "telegram",
|
||||
agentTo: "telegram:123",
|
||||
agentThreadId: 42,
|
||||
});
|
||||
|
||||
const result = await tool.execute("call", {
|
||||
task: "do thing",
|
||||
runTimeoutSeconds: 1,
|
||||
});
|
||||
expect(result.details).toMatchObject({ status: "accepted", runId: "run-1" });
|
||||
|
||||
const runs = listSubagentRunsForRequester("main");
|
||||
expect(runs).toHaveLength(1);
|
||||
expect(runs[0]?.requesterOrigin).toMatchObject({
|
||||
const run = await spawnAndReadRequesterRun({ agentThreadId: 42 });
|
||||
expect(run?.requesterOrigin).toMatchObject({
|
||||
channel: "telegram",
|
||||
to: "telegram:123",
|
||||
threadId: 42,
|
||||
@@ -59,20 +63,7 @@ describe("sessions_spawn requesterOrigin threading", () => {
|
||||
});
|
||||
|
||||
it("stores requesterOrigin without threadId when none is provided", async () => {
|
||||
const tool = await getSessionsSpawnTool({
|
||||
agentSessionKey: "main",
|
||||
agentChannel: "telegram",
|
||||
agentTo: "telegram:123",
|
||||
});
|
||||
|
||||
const result = await tool.execute("call", {
|
||||
task: "do thing",
|
||||
runTimeoutSeconds: 1,
|
||||
});
|
||||
expect(result.details).toMatchObject({ status: "accepted", runId: "run-1" });
|
||||
|
||||
const runs = listSubagentRunsForRequester("main");
|
||||
expect(runs).toHaveLength(1);
|
||||
expect(runs[0]?.requesterOrigin?.threadId).toBeUndefined();
|
||||
const run = await spawnAndReadRequesterRun();
|
||||
expect(run?.requesterOrigin?.threadId).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user