mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 11:50:20 +00:00
refactor(test): dedupe channel and monitor action suites
This commit is contained in:
@@ -170,6 +170,7 @@ beforeEach(() => {
|
||||
});
|
||||
|
||||
const resolveGatewayToken = (): string => TEST_GATEWAY_TOKEN;
|
||||
const gatewayAuthHeaders = () => ({ authorization: `Bearer ${resolveGatewayToken()}` });
|
||||
|
||||
const allowAgentsListForMain = () => {
|
||||
cfg = {
|
||||
@@ -229,16 +230,29 @@ const invokeTool = async (params: {
|
||||
});
|
||||
};
|
||||
|
||||
const invokeAgentsListAuthed = async (params: { sessionKey?: string } = {}) =>
|
||||
invokeAgentsList({
|
||||
port: sharedPort,
|
||||
headers: gatewayAuthHeaders(),
|
||||
sessionKey: params.sessionKey,
|
||||
});
|
||||
|
||||
const invokeToolAuthed = async (params: {
|
||||
tool: string;
|
||||
args?: Record<string, unknown>;
|
||||
action?: string;
|
||||
sessionKey?: string;
|
||||
}) =>
|
||||
invokeTool({
|
||||
port: sharedPort,
|
||||
headers: gatewayAuthHeaders(),
|
||||
...params,
|
||||
});
|
||||
|
||||
describe("POST /tools/invoke", () => {
|
||||
it("invokes a tool and returns {ok:true,result}", async () => {
|
||||
allowAgentsListForMain();
|
||||
const token = resolveGatewayToken();
|
||||
|
||||
const res = await invokeAgentsList({
|
||||
port: sharedPort,
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
sessionKey: "main",
|
||||
});
|
||||
const res = await invokeAgentsListAuthed({ sessionKey: "main" });
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
const body = await res.json();
|
||||
@@ -253,13 +267,7 @@ describe("POST /tools/invoke", () => {
|
||||
tools: { profile: "minimal", alsoAllow: ["agents_list"] },
|
||||
};
|
||||
|
||||
const token = resolveGatewayToken();
|
||||
|
||||
const resProfile = await invokeAgentsList({
|
||||
port: sharedPort,
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
sessionKey: "main",
|
||||
});
|
||||
const resProfile = await invokeAgentsListAuthed({ sessionKey: "main" });
|
||||
|
||||
expect(resProfile.status).toBe(200);
|
||||
const profileBody = await resProfile.json();
|
||||
@@ -270,11 +278,7 @@ describe("POST /tools/invoke", () => {
|
||||
tools: { alsoAllow: ["agents_list"] },
|
||||
};
|
||||
|
||||
const resImplicit = await invokeAgentsList({
|
||||
port: sharedPort,
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
sessionKey: "main",
|
||||
});
|
||||
const resImplicit = await invokeAgentsListAuthed({ sessionKey: "main" });
|
||||
expect(resImplicit.status).toBe(200);
|
||||
const implicitBody = await resImplicit.json();
|
||||
expect(implicitBody.ok).toBe(true);
|
||||
@@ -289,12 +293,7 @@ describe("POST /tools/invoke", () => {
|
||||
allowAgentsListForMain();
|
||||
pluginHttpHandlers = [async (req, res) => pluginHandler(req, res)];
|
||||
|
||||
const token = resolveGatewayToken();
|
||||
const res = await invokeAgentsList({
|
||||
port: sharedPort,
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
sessionKey: "main",
|
||||
});
|
||||
const res = await invokeAgentsListAuthed({ sessionKey: "main" });
|
||||
|
||||
expect(res.status).toBe(200);
|
||||
expect(pluginHandler).not.toHaveBeenCalled();
|
||||
@@ -315,13 +314,7 @@ describe("POST /tools/invoke", () => {
|
||||
],
|
||||
},
|
||||
};
|
||||
const token = resolveGatewayToken();
|
||||
|
||||
const denyRes = await invokeAgentsList({
|
||||
port: sharedPort,
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
sessionKey: "main",
|
||||
});
|
||||
const denyRes = await invokeAgentsListAuthed({ sessionKey: "main" });
|
||||
expect(denyRes.status).toBe(404);
|
||||
|
||||
allowAgentsListForMain();
|
||||
@@ -330,11 +323,7 @@ describe("POST /tools/invoke", () => {
|
||||
tools: { profile: "minimal" },
|
||||
};
|
||||
|
||||
const profileRes = await invokeAgentsList({
|
||||
port: sharedPort,
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
sessionKey: "main",
|
||||
});
|
||||
const profileRes = await invokeAgentsListAuthed({ sessionKey: "main" });
|
||||
expect(profileRes.status).toBe(404);
|
||||
});
|
||||
|
||||
@@ -352,13 +341,9 @@ describe("POST /tools/invoke", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const token = resolveGatewayToken();
|
||||
|
||||
const res = await invokeTool({
|
||||
port: sharedPort,
|
||||
const res = await invokeToolAuthed({
|
||||
tool: "sessions_spawn",
|
||||
args: { task: "test" },
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
sessionKey: "main",
|
||||
});
|
||||
|
||||
@@ -376,12 +361,8 @@ describe("POST /tools/invoke", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const token = resolveGatewayToken();
|
||||
|
||||
const res = await invokeTool({
|
||||
port: sharedPort,
|
||||
const res = await invokeToolAuthed({
|
||||
tool: "sessions_send",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
sessionKey: "main",
|
||||
});
|
||||
|
||||
@@ -396,12 +377,8 @@ describe("POST /tools/invoke", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const token = resolveGatewayToken();
|
||||
|
||||
const res = await invokeTool({
|
||||
port: sharedPort,
|
||||
const res = await invokeToolAuthed({
|
||||
tool: "gateway",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
sessionKey: "main",
|
||||
});
|
||||
|
||||
@@ -417,12 +394,8 @@ describe("POST /tools/invoke", () => {
|
||||
gateway: { tools: { allow: ["gateway"] } },
|
||||
};
|
||||
|
||||
const token = resolveGatewayToken();
|
||||
|
||||
const res = await invokeTool({
|
||||
port: sharedPort,
|
||||
const res = await invokeToolAuthed({
|
||||
tool: "gateway",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
sessionKey: "main",
|
||||
});
|
||||
|
||||
@@ -442,12 +415,8 @@ describe("POST /tools/invoke", () => {
|
||||
gateway: { tools: { allow: ["gateway"], deny: ["gateway"] } },
|
||||
};
|
||||
|
||||
const token = resolveGatewayToken();
|
||||
|
||||
const res = await invokeTool({
|
||||
port: sharedPort,
|
||||
const res = await invokeToolAuthed({
|
||||
tool: "gateway",
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
sessionKey: "main",
|
||||
});
|
||||
|
||||
@@ -477,19 +446,10 @@ describe("POST /tools/invoke", () => {
|
||||
session: { mainKey: "primary" },
|
||||
};
|
||||
|
||||
const token = resolveGatewayToken();
|
||||
|
||||
const resDefault = await invokeAgentsList({
|
||||
port: sharedPort,
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
});
|
||||
const resDefault = await invokeAgentsListAuthed();
|
||||
expect(resDefault.status).toBe(200);
|
||||
|
||||
const resMain = await invokeAgentsList({
|
||||
port: sharedPort,
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
sessionKey: "main",
|
||||
});
|
||||
const resMain = await invokeAgentsListAuthed({ sessionKey: "main" });
|
||||
expect(resMain.status).toBe(200);
|
||||
});
|
||||
|
||||
@@ -501,13 +461,9 @@ describe("POST /tools/invoke", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const token = resolveGatewayToken();
|
||||
|
||||
const inputRes = await invokeTool({
|
||||
port: sharedPort,
|
||||
const inputRes = await invokeToolAuthed({
|
||||
tool: "tools_invoke_test",
|
||||
args: { mode: "input" },
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
sessionKey: "main",
|
||||
});
|
||||
expect(inputRes.status).toBe(400);
|
||||
@@ -516,11 +472,9 @@ describe("POST /tools/invoke", () => {
|
||||
expect(inputBody.error?.type).toBe("tool_error");
|
||||
expect(inputBody.error?.message).toBe("mode invalid");
|
||||
|
||||
const crashRes = await invokeTool({
|
||||
port: sharedPort,
|
||||
const crashRes = await invokeToolAuthed({
|
||||
tool: "tools_invoke_test",
|
||||
args: { mode: "crash" },
|
||||
headers: { authorization: `Bearer ${token}` },
|
||||
sessionKey: "main",
|
||||
});
|
||||
expect(crashRes.status).toBe(500);
|
||||
|
||||
Reference in New Issue
Block a user