mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 20:34:32 +00:00
test(agents): dedupe sessions_spawn requester run setup
This commit is contained in:
@@ -11,6 +11,24 @@ import {
|
|||||||
} from "./subagent-registry.js";
|
} from "./subagent-registry.js";
|
||||||
|
|
||||||
describe("sessions_spawn requesterOrigin threading", () => {
|
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(() => {
|
beforeEach(() => {
|
||||||
const callGatewayMock = getCallGatewayMock();
|
const callGatewayMock = getCallGatewayMock();
|
||||||
resetSubagentRegistryForTests();
|
resetSubagentRegistryForTests();
|
||||||
@@ -36,22 +54,8 @@ describe("sessions_spawn requesterOrigin threading", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("captures threadId in requesterOrigin", async () => {
|
it("captures threadId in requesterOrigin", async () => {
|
||||||
const tool = await getSessionsSpawnTool({
|
const run = await spawnAndReadRequesterRun({ agentThreadId: 42 });
|
||||||
agentSessionKey: "main",
|
expect(run?.requesterOrigin).toMatchObject({
|
||||||
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({
|
|
||||||
channel: "telegram",
|
channel: "telegram",
|
||||||
to: "telegram:123",
|
to: "telegram:123",
|
||||||
threadId: 42,
|
threadId: 42,
|
||||||
@@ -59,20 +63,7 @@ describe("sessions_spawn requesterOrigin threading", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("stores requesterOrigin without threadId when none is provided", async () => {
|
it("stores requesterOrigin without threadId when none is provided", async () => {
|
||||||
const tool = await getSessionsSpawnTool({
|
const run = await spawnAndReadRequesterRun();
|
||||||
agentSessionKey: "main",
|
expect(run?.requesterOrigin?.threadId).toBeUndefined();
|
||||||
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();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user