Add ACP-backed role sessions
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { parseConfig } from "../src/config.js";
|
||||
import { QqAdapter } from "../src/platforms/qq/adapter.js";
|
||||
|
||||
const config = parseConfig({ configVersion: 2, backends: [{ id: "kimi", command: "kimi", args: ["acp"] }], defaultRole: "assistant", roles: [{ id: "assistant", backend: "kimi", workspace: "/tmp" }], platforms: { qq: {
|
||||
enabled: true, connectionMode: "webhook", appId: "id", clientSecret: "secret", verifySignature: false, botNames: ["Bot"]
|
||||
} } });
|
||||
|
||||
test("normalizes GROUP and C2C author openid while ACK remains immediate", async () => {
|
||||
const received: any[] = [];
|
||||
const gateway = { receive: async (message: unknown) => { received.push(message); throw new Error("ACP failed"); } };
|
||||
const adapter = new QqAdapter(config.platforms.qq, gateway as never);
|
||||
const group = await adapter.handleWebhook({ body: { op: 0, t: "GROUP_AT_MESSAGE_CREATE", d: { id: "m1", group_openid: "g1", author: { user_openid: "u1" }, content: "@Bot hi" } }, headers: {}, query: {}, req: {} as never });
|
||||
const c2c = await adapter.handleWebhook({ body: { op: 0, t: "C2C_MESSAGE_CREATE", d: { id: "m2", author: { user_openid: "u2" }, content: "hello" } }, headers: {}, query: {}, req: {} as never });
|
||||
assert.deepEqual(group.body, { op: 12 }); assert.deepEqual(c2c.body, { op: 12 });
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
assert.equal(received[0].chatId, "group:g1"); assert.equal(received[0].userId, "u1");
|
||||
assert.equal(received[1].chatId, "user:u2"); assert.equal(received[1].userId, "u2");
|
||||
});
|
||||
|
||||
test("sendMessage uses nested author.user_openid for C2C endpoint", async () => {
|
||||
const original = globalThis.fetch; const urls: string[] = [];
|
||||
globalThis.fetch = (async (input: string | URL | Request) => {
|
||||
urls.push(String(input));
|
||||
if (String(input).includes("getAppAccessToken")) return new Response(JSON.stringify({ access_token: "token", expires_in: 7200 }), { status: 200 });
|
||||
return new Response(JSON.stringify({ id: "sent" }), { status: 200 });
|
||||
}) as typeof fetch;
|
||||
try {
|
||||
const adapter = new QqAdapter(config.platforms.qq, { receive: async () => ({ ok: true }) } as never);
|
||||
await adapter.sendMessage({ target: { platform: "qq", chatId: "user:u2", raw: { author: { user_openid: "u2" } } }, text: "reply", replyTo: "m2" });
|
||||
assert.ok(urls.some((url) => url.endsWith("/v2/users/u2/messages")));
|
||||
} finally { globalThis.fetch = original; }
|
||||
});
|
||||
Reference in New Issue
Block a user