























@@ -9,6 +9,7 @@
99 */
10101111import { describe, expect, it, vi } from "vitest";
12+import type { QQBotInboundAccess } from "../../adapter/index.js";
1213import type { InboundPipelineDeps } from "../inbound-context.js";
1314import type { QueuedMessage } from "../message-queue.js";
1415import type { GatewayAccount, GatewayPluginRuntime } from "../types.js";
@@ -61,12 +62,23 @@ function buildRuntime(
6162formatInboundEnvelope: vi.fn(() => ""),
6263resolveEnvelopeFormatOptions: vi.fn(() => ({})),
6364},
65+session: {
66+resolveStorePath: vi.fn(() => ""),
67+recordInboundSession: vi.fn(async () => undefined),
68+},
69+turn: { run: vi.fn(async () => undefined) },
6470text: { chunkMarkdownText: vi.fn(() => []) },
6571},
6672tts: { textToSpeech: vi.fn() },
6773};
6874}
697576+function buildAllowAccess(): QQBotInboundAccess {
77+return {
78+senderAccess: { decision: "allow" },
79+} as unknown as QQBotInboundAccess;
80+}
81+7082function buildDeps(
7183cfg: unknown,
7284runtime: GatewayPluginRuntime,
@@ -77,12 +89,17 @@ function buildDeps(
7789 cfg,
7890 runtime,
7991startTyping: vi.fn(),
80-adapters: {} as InboundPipelineDeps["adapters"],
92+adapters: {
93+access: {
94+resolveInboundAccess: vi.fn(() => buildAllowAccess()),
95+resolveSlashCommandAuthorization: vi.fn(() => true),
96+},
97+} as unknown as InboundPipelineDeps["adapters"],
8198};
8299}
8310084101describe("runAccessStage — dynamic cfg routing (#69546)", () => {
85-it("re-evaluates resolveAgentRoute against the cfg supplied on each call", () => {
102+it("re-evaluates resolveAgentRoute against the cfg supplied on each call", async () => {
86103const account = buildAccount();
87104const peerId = "480562E9913A985D4A79822A643E27B6";
88105@@ -111,13 +128,13 @@ describe("runAccessStage — dynamic cfg routing (#69546)", () => {
111128112129const event = buildEvent(peerId);
113130114-const first = runAccessStage(event, buildDeps(accountOnly, runtime, account));
131+const first = await runAccessStage(event, buildDeps(accountOnly, runtime, account));
115132expect(first.kind).toBe("allow");
116133if (first.kind === "allow") {
117134expect(first.route.agentId).toBe("study");
118135}
119136120-const second = runAccessStage(event, buildDeps(withPeer, runtime, account));
137+const second = await runAccessStage(event, buildDeps(withPeer, runtime, account));
121138expect(second.kind).toBe("allow");
122139if (second.kind === "allow") {
123140expect(second.route.agentId).toBe("tutor");
@@ -128,7 +145,7 @@ describe("runAccessStage — dynamic cfg routing (#69546)", () => {
128145expect(captured[1]?.cfg).toBe(withPeer);
129146});
130147131-it("never reads bindings from a previous cfg reference", () => {
148+it("never reads bindings from a previous cfg reference", async () => {
132149const account = buildAccount();
133150const seenCfgs = new Set<unknown>();
134151const runtime = buildRuntime((params) => {
@@ -140,9 +157,9 @@ describe("runAccessStage — dynamic cfg routing (#69546)", () => {
140157const cfgB: StubCfg = { bindings: [] };
141158const cfgC: StubCfg = { bindings: [] };
142159143-runAccessStage(buildEvent("a"), buildDeps(cfgA, runtime, account));
144-runAccessStage(buildEvent("b"), buildDeps(cfgB, runtime, account));
145-runAccessStage(buildEvent("c"), buildDeps(cfgC, runtime, account));
160+await runAccessStage(buildEvent("a"), buildDeps(cfgA, runtime, account));
161+await runAccessStage(buildEvent("b"), buildDeps(cfgB, runtime, account));
162+await runAccessStage(buildEvent("c"), buildDeps(cfgC, runtime, account));
146163147164expect(seenCfgs.size).toBe(3);
148165expect(seenCfgs.has(cfgA)).toBe(true);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。