mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 07:57:28 +00:00
refactor: share chat abort auth invocation
This commit is contained in:
@@ -6,6 +6,30 @@ import {
|
|||||||
} from "./chat.abort.test-helpers.js";
|
} from "./chat.abort.test-helpers.js";
|
||||||
import { chatHandlers } from "./chat.js";
|
import { chatHandlers } from "./chat.js";
|
||||||
|
|
||||||
|
async function invokeSingleRunAbort({
|
||||||
|
context,
|
||||||
|
runId = "run-1",
|
||||||
|
connId,
|
||||||
|
deviceId,
|
||||||
|
scopes,
|
||||||
|
}: {
|
||||||
|
context: ReturnType<typeof createChatAbortContext>;
|
||||||
|
runId?: string;
|
||||||
|
connId: string;
|
||||||
|
deviceId: string;
|
||||||
|
scopes: string[];
|
||||||
|
}) {
|
||||||
|
return await invokeChatAbortHandler({
|
||||||
|
handler: chatHandlers["chat.abort"],
|
||||||
|
context,
|
||||||
|
request: { sessionKey: "main", runId },
|
||||||
|
client: {
|
||||||
|
connId,
|
||||||
|
connect: { device: { id: deviceId }, scopes },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
describe("chat.abort authorization", () => {
|
describe("chat.abort authorization", () => {
|
||||||
it("rejects explicit run aborts from other clients", async () => {
|
it("rejects explicit run aborts from other clients", async () => {
|
||||||
const context = createChatAbortContext({
|
const context = createChatAbortContext({
|
||||||
@@ -17,14 +41,11 @@ describe("chat.abort authorization", () => {
|
|||||||
]),
|
]),
|
||||||
});
|
});
|
||||||
|
|
||||||
const respond = await invokeChatAbortHandler({
|
const respond = await invokeSingleRunAbort({
|
||||||
handler: chatHandlers["chat.abort"],
|
|
||||||
context,
|
context,
|
||||||
request: { sessionKey: "main", runId: "run-1" },
|
connId: "conn-other",
|
||||||
client: {
|
deviceId: "dev-other",
|
||||||
connId: "conn-other",
|
scopes: ["operator.write"],
|
||||||
connect: { device: { id: "dev-other" }, scopes: ["operator.write"] },
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const [ok, payload, error] = respond.mock.calls.at(-1) ?? [];
|
const [ok, payload, error] = respond.mock.calls.at(-1) ?? [];
|
||||||
@@ -92,14 +113,11 @@ describe("chat.abort authorization", () => {
|
|||||||
]),
|
]),
|
||||||
});
|
});
|
||||||
|
|
||||||
const respond = await invokeChatAbortHandler({
|
const respond = await invokeSingleRunAbort({
|
||||||
handler: chatHandlers["chat.abort"],
|
|
||||||
context,
|
context,
|
||||||
request: { sessionKey: "main", runId: "run-1" },
|
connId: "conn-admin",
|
||||||
client: {
|
deviceId: "dev-admin",
|
||||||
connId: "conn-admin",
|
scopes: ["operator.admin"],
|
||||||
connect: { device: { id: "dev-admin" }, scopes: ["operator.admin"] },
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const [ok, payload] = respond.mock.calls.at(-1) ?? [];
|
const [ok, payload] = respond.mock.calls.at(-1) ?? [];
|
||||||
|
|||||||
Reference in New Issue
Block a user