

























11import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
2233const listSkillCommandsForAgents = vi.hoisted(() => vi.fn());
4-const parseStrictPositiveInteger = vi.hoisted(() => vi.fn());
4+const parseTcpPort = vi.hoisted(() => vi.fn());
55const fetchMattermostUserTeams = vi.hoisted(() => vi.fn());
66const normalizeMattermostBaseUrl = vi.hoisted(() => vi.fn((value: string | undefined) => value));
77const isSlashCommandsEnabled = vi.hoisted(() => vi.fn());
@@ -12,7 +12,7 @@ const activateSlashCommands = vi.hoisted(() => vi.fn());
12121313vi.mock("./runtime-api.js", () => ({
1414 listSkillCommandsForAgents,
15-parseStrictPositiveInteger,
15+parseTcpPort,
1616}));
17171818vi.mock("./client.js", async () => {
@@ -59,7 +59,7 @@ describe("mattermost monitor slash", () => {
59596060beforeEach(() => {
6161listSkillCommandsForAgents.mockReset();
62-parseStrictPositiveInteger.mockReset();
62+parseTcpPort.mockReset();
6363fetchMattermostUserTeams.mockReset();
6464normalizeMattermostBaseUrl.mockClear();
6565isSlashCommandsEnabled.mockReset();
@@ -94,7 +94,7 @@ describe("mattermost monitor slash", () => {
9494vi.stubEnv("OPENCLAW_GATEWAY_PORT", "18888");
9595resolveSlashCommandConfig.mockReturnValue({ enabled: true, nativeSkills: true });
9696isSlashCommandsEnabled.mockReturnValue(true);
97-parseStrictPositiveInteger.mockReturnValue(18888);
97+parseTcpPort.mockReturnValue(18888);
9898fetchMattermostUserTeams.mockResolvedValue([{ id: "team-1" }, { id: "team-2" }]);
9999resolveCallbackUrl.mockReturnValue("https://openclaw.test/slash");
100100listSkillCommandsForAgents.mockReturnValue([
@@ -166,10 +166,34 @@ describe("mattermost monitor slash", () => {
166166);
167167});
168168169+it("falls back to the configured gateway port when the env port is out of range", async () => {
170+vi.stubEnv("OPENCLAW_GATEWAY_PORT", "65536");
171+resolveSlashCommandConfig.mockReturnValue({ enabled: true, nativeSkills: false });
172+isSlashCommandsEnabled.mockReturnValue(true);
173+parseTcpPort.mockReturnValue(null);
174+fetchMattermostUserTeams.mockResolvedValue([{ id: "team-1" }]);
175+resolveCallbackUrl.mockReturnValue("https://openclaw.test/slash");
176+registerSlashCommands.mockResolvedValue([{ token: "token-1", trigger: "ping" }]);
177+178+await registerMattermostMonitorSlashCommands({
179+client: {} as never,
180+cfg: { gateway: { port: 18789 } } as never,
181+runtime: { log: vi.fn(), error: vi.fn() } as never,
182+account: { config: { commands: {} }, accountId: "default" } as never,
183+baseUrl: "https://chat.example.com",
184+botUserId: "bot-user",
185+});
186+187+expect(parseTcpPort).toHaveBeenCalledWith("65536");
188+expect(resolveCallbackUrl).toHaveBeenCalledWith(
189+expect.objectContaining({ gatewayPort: 18789 }),
190+);
191+});
192+169193it("warns on loopback callback urls and reports partial team failures", async () => {
170194resolveSlashCommandConfig.mockReturnValue({ enabled: true, nativeSkills: false });
171195isSlashCommandsEnabled.mockReturnValue(true);
172-parseStrictPositiveInteger.mockReturnValue(undefined);
196+parseTcpPort.mockReturnValue(null);
173197fetchMattermostUserTeams.mockResolvedValue([{ id: "team-1" }, { id: "team-2" }]);
174198resolveCallbackUrl.mockReturnValue("http://127.0.0.1:18789/slash");
175199registerSlashCommands
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。