refactor: remove redundant ?? undefined in Slack probe (#44775)

Merged via squash.

Prepared head SHA: ecc73fe47c
Co-authored-by: Cafexss <13113185+Cafexss@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
This commit is contained in:
0xffee 2026-03-14 02:52:15 +08:00 committed by GitHub
parent 9e28f5aac2
commit 5ba1bfdb7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 67 additions and 2 deletions

View File

@ -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

64
src/slack/probe.test.ts Normal file
View File

@ -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<unknown>) => 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 });
});
});

View File

@ -26,8 +26,8 @@ export async function probeSlack(token: string, timeoutMs = 2500): Promise<Slack
ok: true,
status: 200,
elapsedMs: Date.now() - start,
bot: { id: result.user_id ?? undefined, name: result.user ?? undefined },
team: { id: result.team_id ?? undefined, name: result.team ?? undefined },
bot: { id: result.user_id, name: result.user },
team: { id: result.team_id, name: result.team },
};
} catch (err) {
const message = err instanceof Error ? err.message : String(err);