From ecc73fe47c5ba8be28005e8752cff85eb01ae643 Mon Sep 17 00:00:00 2001 From: Altay Date: Fri, 13 Mar 2026 21:44:51 +0300 Subject: [PATCH] test: cover Slack probe auth mapping --- CHANGELOG.md | 1 + src/slack/probe.test.ts | 64 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 src/slack/probe.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 79bc5bfb064..1fd48042765 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ Docs: https://docs.openclaw.ai - macOS/onboarding: avoid self-restarting freshly bootstrapped launchd gateways and give new daemon installs longer to become healthy, so `openclaw onboard --install-daemon` no longer false-fails on slower Macs and fresh VM snapshots. - Agents/compaction: preserve safeguard compaction summary language continuity via default and configurable custom instructions so persona drift is reduced after auto-compaction. (#10456) Thanks @keepitmello. - Agents/tool warnings: distinguish gated core tools like `apply_patch` from plugin-only unknown entries in `tools.profile` warnings, so unavailable core tools now report current runtime/provider/model/config gating instead of suggesting a missing plugin. +- Slack/probe: keep `auth.test()` bot and team metadata mapping stable while simplifying the probe result path. (#44775) Thanks @Cafexss. ## 2026.3.12 diff --git a/src/slack/probe.test.ts b/src/slack/probe.test.ts new file mode 100644 index 00000000000..501d808d492 --- /dev/null +++ b/src/slack/probe.test.ts @@ -0,0 +1,64 @@ +import { beforeEach, describe, expect, it, vi } from "vitest"; + +const authTestMock = vi.hoisted(() => vi.fn()); +const createSlackWebClientMock = vi.hoisted(() => vi.fn()); +const withTimeoutMock = vi.hoisted(() => vi.fn()); + +vi.mock("./client.js", () => ({ + createSlackWebClient: createSlackWebClientMock, +})); + +vi.mock("../utils/with-timeout.js", () => ({ + withTimeout: withTimeoutMock, +})); + +const { probeSlack } = await import("./probe.js"); + +describe("probeSlack", () => { + beforeEach(() => { + authTestMock.mockReset(); + createSlackWebClientMock.mockReset(); + withTimeoutMock.mockReset(); + + createSlackWebClientMock.mockReturnValue({ + auth: { + test: authTestMock, + }, + }); + withTimeoutMock.mockImplementation(async (promise: Promise) => await promise); + }); + + it("maps Slack auth metadata on success", async () => { + vi.spyOn(Date, "now").mockReturnValueOnce(100).mockReturnValueOnce(145); + authTestMock.mockResolvedValue({ + ok: true, + user_id: "U123", + user: "openclaw-bot", + team_id: "T123", + team: "OpenClaw", + }); + + await expect(probeSlack("xoxb-test", 2500)).resolves.toEqual({ + ok: true, + status: 200, + elapsedMs: 45, + bot: { id: "U123", name: "openclaw-bot" }, + team: { id: "T123", name: "OpenClaw" }, + }); + expect(createSlackWebClientMock).toHaveBeenCalledWith("xoxb-test"); + expect(withTimeoutMock).toHaveBeenCalledWith(expect.any(Promise), 2500); + }); + + it("keeps optional auth metadata fields undefined when Slack omits them", async () => { + vi.spyOn(Date, "now").mockReturnValueOnce(200).mockReturnValueOnce(235); + authTestMock.mockResolvedValue({ ok: true }); + + const result = await probeSlack("xoxb-test"); + + expect(result.ok).toBe(true); + expect(result.status).toBe(200); + expect(result.elapsedMs).toBe(35); + expect(result.bot).toStrictEqual({ id: undefined, name: undefined }); + expect(result.team).toStrictEqual({ id: undefined, name: undefined }); + }); +});