




















@@ -90,7 +90,11 @@ function resolveEffectiveToolInventoryArg(callIndex = 0): Record<string, unknown
9090const calls = runtimeMocks.resolveEffectiveToolInventory.mock.calls as unknown as Array<
9191[Record<string, unknown>]
9292>;
93-return calls[callIndex]?.[0];
93+return calls.at(callIndex)?.[0];
94+}
95+96+function firstRespondCall(respond: ReturnType<typeof vi.fn>): RespondCall | undefined {
97+return respond.mock.calls.at(0) as RespondCall | undefined;
9498}
959996100describe("tools.effective handler", () => {
@@ -105,7 +109,7 @@ describe("tools.effective handler", () => {
105109it("rejects invalid params", async () => {
106110const { respond, invoke } = createInvokeParams({ includePlugins: false });
107111await invoke();
108-const call = respond.mock.calls[0] as RespondCall | undefined;
112+const call = firstRespondCall(respond);
109113expect(call?.[0]).toBe(false);
110114expect(call?.[2]?.code).toBe(ErrorCodes.INVALID_REQUEST);
111115expect(call?.[2]?.message).toContain("invalid tools.effective params");
@@ -114,7 +118,7 @@ describe("tools.effective handler", () => {
114118it("rejects missing sessionKey", async () => {
115119const { respond, invoke } = createInvokeParams({});
116120await invoke();
117-const call = respond.mock.calls[0] as RespondCall | undefined;
121+const call = firstRespondCall(respond);
118122expect(call?.[0]).toBe(false);
119123expect(call?.[2]?.code).toBe(ErrorCodes.INVALID_REQUEST);
120124expect(call?.[2]?.message).toContain("invalid tools.effective params");
@@ -123,7 +127,7 @@ describe("tools.effective handler", () => {
123127it("rejects caller-supplied auth context params", async () => {
124128const { respond, invoke } = createInvokeParams({ senderIsOwner: true });
125129await invoke();
126-const call = respond.mock.calls[0] as RespondCall | undefined;
130+const call = firstRespondCall(respond);
127131expect(call?.[0]).toBe(false);
128132expect(call?.[2]?.code).toBe(ErrorCodes.INVALID_REQUEST);
129133expect(call?.[2]?.message).toContain("invalid tools.effective params");
@@ -135,7 +139,7 @@ describe("tools.effective handler", () => {
135139agentId: "unknown-agent",
136140});
137141await invoke();
138-const call = respond.mock.calls[0] as RespondCall | undefined;
142+const call = firstRespondCall(respond);
139143expect(call?.[0]).toBe(false);
140144expect(call?.[2]?.code).toBe(ErrorCodes.INVALID_REQUEST);
141145expect(call?.[2]?.message).toContain("unknown agent id");
@@ -151,7 +155,7 @@ describe("tools.effective handler", () => {
151155} as never);
152156const { respond, invoke } = createInvokeParams({ sessionKey: "missing-session" });
153157await invoke();
154-const call = respond.mock.calls[0] as RespondCall | undefined;
158+const call = firstRespondCall(respond);
155159expect(call?.[0]).toBe(false);
156160expect(call?.[2]?.code).toBe(ErrorCodes.INVALID_REQUEST);
157161expect(call?.[2]?.message).toContain('unknown session key "missing-session"');
@@ -160,7 +164,7 @@ describe("tools.effective handler", () => {
160164it("returns the effective runtime inventory", async () => {
161165const { respond, invoke } = createInvokeParams({ sessionKey: "main:abc" });
162166await invoke();
163-const call = respond.mock.calls[0] as RespondCall | undefined;
167+const call = firstRespondCall(respond);
164168expect(call?.[0]).toBe(true);
165169const payload = call?.[1] as ToolsEffectivePayload | undefined;
166170expect(payload?.agentId).toBe("main");
@@ -190,8 +194,8 @@ describe("tools.effective handler", () => {
190194await second.invoke();
191195192196expect(runtimeMocks.resolveEffectiveToolInventory).toHaveBeenCalledTimes(1);
193-expect((first.respond.mock.calls[0] as RespondCall | undefined)?.[0]).toBe(true);
194-expect((second.respond.mock.calls[0] as RespondCall | undefined)?.[0]).toBe(true);
197+expect(firstRespondCall(first.respond)?.[0]).toBe(true);
198+expect(firstRespondCall(second.respond)?.[0]).toBe(true);
195199});
196200197201it("invalidates the cache when only the channel registry version changes", async () => {
@@ -203,7 +207,7 @@ describe("tools.effective handler", () => {
203207await second.invoke();
204208205209expect(runtimeMocks.resolveEffectiveToolInventory).toHaveBeenCalledTimes(2);
206-expect((second.respond.mock.calls[0] as RespondCall | undefined)?.[0]).toBe(true);
210+expect(firstRespondCall(second.respond)?.[0]).toBe(true);
207211});
208212209213it("coalesces identical cache misses while inventory resolution is pending", async () => {
@@ -213,8 +217,8 @@ describe("tools.effective handler", () => {
213217await Promise.all([first.invoke(), second.invoke()]);
214218215219expect(runtimeMocks.resolveEffectiveToolInventory).toHaveBeenCalledTimes(1);
216-expect((first.respond.mock.calls[0] as RespondCall | undefined)?.[0]).toBe(true);
217-expect((second.respond.mock.calls[0] as RespondCall | undefined)?.[0]).toBe(true);
220+expect(firstRespondCall(first.respond)?.[0]).toBe(true);
221+expect(firstRespondCall(second.respond)?.[0]).toBe(true);
218222});
219223220224it("returns stale cached inventory immediately while refreshing in the background", async () => {
@@ -271,15 +275,15 @@ describe("tools.effective handler", () => {
271275const stale = createInvokeParams({ sessionKey: "main:abc" });
272276await stale.invoke();
273277274-expect((stale.respond.mock.calls[0] as RespondCall | undefined)?.[1]).toBe(stalePayload);
278+expect(firstRespondCall(stale.respond)?.[1]).toBe(stalePayload);
275279expect(runtimeMocks.resolveEffectiveToolInventory).toHaveBeenCalledTimes(1);
276280277281await new Promise<void>((resolve) => setImmediate(resolve));
278282expect(runtimeMocks.resolveEffectiveToolInventory).toHaveBeenCalledTimes(2);
279283280284const fresh = createInvokeParams({ sessionKey: "main:abc" });
281285await fresh.invoke();
282-expect((fresh.respond.mock.calls[0] as RespondCall | undefined)?.[1]).toBe(refreshedPayload);
286+expect(firstRespondCall(fresh.respond)?.[1]).toBe(refreshedPayload);
283287});
284288285289it("falls back to origin.threadId when delivery context omits thread metadata", async () => {
@@ -316,7 +320,7 @@ describe("tools.effective handler", () => {
316320await invoke();
317321318322expect(resolveEffectiveToolInventoryArg()?.currentThreadTs).toBe("42");
319-expect((respond.mock.calls[0] as RespondCall | undefined)?.[0]).toBe(true);
323+expect(firstRespondCall(respond)?.[0]).toBe(true);
320324});
321325322326it("passes senderIsOwner=true for admin-scoped callers", async () => {
@@ -348,7 +352,7 @@ describe("tools.effective handler", () => {
348352},
349353} as never);
350354await invoke();
351-const call = respond.mock.calls[0] as RespondCall | undefined;
355+const call = firstRespondCall(respond);
352356expect(call?.[0]).toBe(false);
353357expect(call?.[2]?.code).toBe(ErrorCodes.INVALID_REQUEST);
354358expect(call?.[2]?.message).toContain('unknown agent id "other"');
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。