




















@@ -174,17 +174,23 @@ async function runSubagentSpawning(
174174return await handler(event, {});
175175}
176176177+function expectSubagentHookError(result: unknown): { status: "error"; error: string } {
178+expect((result as { status?: unknown } | undefined)?.status).toBe("error");
179+const error = (result as { error?: unknown } | undefined)?.error;
180+expect(typeof error).toBe("string");
181+return result as { status: "error"; error: string };
182+}
183+177184async function expectSubagentSpawningError(params?: {
178185config?: Record<string, unknown>;
179186errorContains?: string;
180187event?: ReturnType<typeof createSpawnEvent>;
181188}) {
182189const result = await runSubagentSpawning(params?.config, params?.event);
183190expect(hookMocks.autoBindSpawnedDiscordSubagent).not.toHaveBeenCalled();
184-expect(result).toMatchObject({ status: "error" });
191+const errorResult = expectSubagentHookError(result);
185192if (params?.errorContains) {
186-const errorText = (result as { error?: string }).error ?? "";
187-expect(errorText).toContain(params.errorContains);
193+expect(errorResult.error).toContain(params.errorContains);
188194}
189195}
190196@@ -228,7 +234,7 @@ describe("discord subagent hook handlers", () => {
228234label: "banana",
229235boundBy: "system",
230236});
231-expect(result).toMatchObject({ status: "ok", threadBindingReady: true });
237+expect(result).toStrictEqual({ status: "ok", threadBindingReady: true });
232238});
233239234240it("returns error when thread-bound subagent spawn is disabled", async () => {
@@ -324,7 +330,7 @@ describe("discord subagent hook handlers", () => {
324330});
325331326332expect(hookMocks.autoBindSpawnedDiscordSubagent).toHaveBeenCalledTimes(1);
327-expect(result).toMatchObject({ status: "ok", threadBindingReady: true });
333+expect(result).toStrictEqual({ status: "ok", threadBindingReady: true });
328334});
329335330336it("defaults thread-bound subagent spawn to enabled when unset", async () => {
@@ -337,7 +343,7 @@ describe("discord subagent hook handlers", () => {
337343});
338344339345expect(hookMocks.autoBindSpawnedDiscordSubagent).toHaveBeenCalledTimes(1);
340-expect(result).toMatchObject({ status: "ok", threadBindingReady: true });
346+expect(result).toStrictEqual({ status: "ok", threadBindingReady: true });
341347});
342348343349it("no-ops when thread binding is requested on non-discord channel", async () => {
@@ -361,9 +367,8 @@ describe("discord subagent hook handlers", () => {
361367hookMocks.autoBindSpawnedDiscordSubagent.mockResolvedValueOnce(null);
362368const result = await runSubagentSpawning();
363369364-expect(result).toMatchObject({ status: "error" });
365-const errorText = (result as { error?: string }).error ?? "";
366-expect(errorText).toMatch(/unable to create or bind/i);
370+const errorResult = expectSubagentHookError(result);
371+expect(errorResult.error).toMatch(/unable to create or bind/i);
367372});
368373369374it("unbinds thread routing on subagent_ended", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。