Skip to content

Commit 298cae6

Browse files
fix(mattermost): collect setup URL in wizard
Fixes #76670.\n\nSummary:\n- Collect the Mattermost bot token and server URL as separate wizard patches so validation does not run before the URL is entered.\n- Preserve non-interactive Mattermost setup validation for explicit --bot-token + --http-url flows.\n- Add a regression test and changelog entry.\n\nVerification:\n- Reporter manually verified setup against a real Mattermost server.\n- pnpm test extensions/mattermost\n- pnpm tsgo:extensions\n- pnpm tsgo:extensions:test\n- pnpm exec oxfmt --check --threads=1 extensions/mattermost/src/setup-core.ts extensions/mattermost/src/setup-surface.ts extensions/mattermost/src/setup.test.ts\n- git diff --check upstream/main...HEAD
1 parent fd5352b commit 298cae6

4 files changed

Lines changed: 86 additions & 15 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ Docs: https://docs.openclaw.ai
116116

117117
- Telegram/Codex: generate DM topic labels with Codex-compatible simple-completion requests so auto-created private topics can be renamed instead of staying `New Chat`.
118118
- Web fetch: bound guarded dispatcher cleanup after request timeouts so timed-out fetches return tool errors instead of leaving Gateway tool lanes active. (#78439) Thanks @obviyus.
119+
- Mattermost/setup: prompt for and persist the server base URL after the bot token in `openclaw setup --wizard`, instead of failing validation before `--http-url` is collected. Fixes #76670. Thanks @jacobtomlinson.
119120
- Gate Slack startup user allowlist resolution [AI]. (#77898) Thanks @pgondhi987.
120121
- OpenAI/Codex: suppress stale `openai-codex` GPT-5.1/5.2/5.3 model refs that ChatGPT/Codex OAuth accounts now reject, keeping model lists, config validation, and forward-compat resolution on current 5.4/5.5 routes. Fixes #67158. Thanks @drpau.
121122
- CLI/update: keep pnpm package updates on the running custom global install root and pass pnpm's `--global-dir` so `openclaw update` does not create a second default-prefix install when `OPENCLAW_HOME` or the shell points at a custom OpenClaw directory. Fixes #78377. Thanks @amknight.

‎extensions/mattermost/src/setup-core.ts‎

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,33 @@ export function resolveMattermostAccountWithSecrets(cfg: OpenClawConfig, account
3030
});
3131
}
3232

33+
export function applyMattermostSetupConfigPatch(params: {
34+
cfg: OpenClawConfig;
35+
accountId: string;
36+
name?: string;
37+
patch: Record<string, unknown>;
38+
}): OpenClawConfig {
39+
const namedConfig = applyAccountNameToChannelSection({
40+
cfg: params.cfg,
41+
channelKey: channel,
42+
accountId: params.accountId,
43+
name: params.name,
44+
});
45+
const next =
46+
params.accountId !== DEFAULT_ACCOUNT_ID
47+
? migrateBaseNameToDefaultAccount({
48+
cfg: namedConfig,
49+
channelKey: channel,
50+
})
51+
: namedConfig;
52+
return applySetupAccountConfigPatch({
53+
cfg: next,
54+
channelKey: channel,
55+
accountId: params.accountId,
56+
patch: params.patch,
57+
});
58+
}
59+
3360
export const mattermostSetupAdapter: ChannelSetupAdapter = {
3461
resolveAccountId: ({ accountId }) => normalizeAccountId(accountId),
3562
applyAccountName: ({ cfg, accountId, name }) =>
@@ -66,23 +93,10 @@ export const mattermostSetupAdapter: ChannelSetupAdapter = {
6693
applyAccountConfig: ({ cfg, accountId, input }) => {
6794
const token = input.botToken ?? input.token;
6895
const baseUrl = normalizeMattermostBaseUrl(input.httpUrl);
69-
const namedConfig = applyAccountNameToChannelSection({
96+
return applyMattermostSetupConfigPatch({
7097
cfg,
71-
channelKey: channel,
7298
accountId,
7399
name: input.name,
74-
});
75-
const next =
76-
accountId !== DEFAULT_ACCOUNT_ID
77-
? migrateBaseNameToDefaultAccount({
78-
cfg: namedConfig,
79-
channelKey: channel,
80-
})
81-
: namedConfig;
82-
return applySetupAccountConfigPatch({
83-
cfg: next,
84-
channelKey: channel,
85-
accountId,
86100
patch: input.useEnv
87101
? {}
88102
: {

‎extensions/mattermost/src/setup-surface.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import {
66
formatDocsLink,
77
type ChannelSetupWizard,
88
} from "openclaw/plugin-sdk/setup";
9-
import { isMattermostConfigured, resolveMattermostAccountWithSecrets } from "./setup-core.js";
9+
import {
10+
applyMattermostSetupConfigPatch,
11+
isMattermostConfigured,
12+
resolveMattermostAccountWithSecrets,
13+
} from "./setup-core.js";
1014
import { normalizeMattermostBaseUrl } from "./setup.client.runtime.js";
1115
import { hasConfiguredSecretInput } from "./setup.secret-input.runtime.js";
1216

@@ -81,6 +85,12 @@ export const mattermostSetupWizard: ChannelSetupWizard = {
8185
hasConfiguredValue: hasConfiguredSecretInput(resolvedAccount.config.botToken),
8286
};
8387
},
88+
applySet: async ({ cfg, accountId, value }) =>
89+
applyMattermostSetupConfigPatch({
90+
cfg,
91+
accountId,
92+
patch: { botToken: value },
93+
}),
8494
},
8595
],
8696
textInputs: [
@@ -106,6 +116,12 @@ export const mattermostSetupWizard: ChannelSetupWizard = {
106116
? undefined
107117
: "Mattermost base URL must include a valid base URL.",
108118
normalizeValue: ({ value }) => normalizeMattermostBaseUrl(value) ?? value.trim(),
119+
applySet: async ({ cfg, accountId, value }) =>
120+
applyMattermostSetupConfigPatch({
121+
cfg,
122+
accountId,
123+
patch: { baseUrl: value },
124+
}),
109125
},
110126
],
111127
disable: (cfg: OpenClawConfig) => ({

‎extensions/mattermost/src/setup.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
2+
import {
3+
createSetupWizardAdapter,
4+
createQueuedWizardPrompter,
5+
runSetupWizardConfigure,
6+
} from "openclaw/plugin-sdk/plugin-test-runtime";
27
import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/setup";
38
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
49
import type { OpenClawConfig, OpenClawPluginApi } from "../runtime-api.js";
@@ -352,6 +357,41 @@ describe("mattermost setup", () => {
352357
},
353358
});
354359
});
360+
361+
it("prompts for bot token and server URL before validating wizard setup", async () => {
362+
normalizeMattermostBaseUrl.mockImplementation((value: string | undefined) =>
363+
value?.startsWith("http") ? value : undefined,
364+
);
365+
const queued = createQueuedWizardPrompter({
366+
textValues: ["bot-token", "https://chat.example.com"],
367+
});
368+
const adapter = createSetupWizardAdapter({
369+
plugin: {
370+
id: "mattermost",
371+
meta: { label: "Mattermost" },
372+
config: {
373+
listAccountIds: () => [DEFAULT_ACCOUNT_ID],
374+
},
375+
setup: mattermostSetupAdapter,
376+
} as never,
377+
wizard: mattermostSetupWizard,
378+
});
379+
380+
const result = await runSetupWizardConfigure({
381+
configure: adapter.configure,
382+
cfg: { channels: { mattermost: {} } } as OpenClawConfig,
383+
prompter: queued.prompter,
384+
options: { secretInputMode: "plaintext" as const },
385+
});
386+
387+
const textMessages = queued.text.mock.calls.map(
388+
([params]) => (params as { message: string }).message,
389+
);
390+
expect(textMessages).toEqual(["Enter Mattermost bot token", "Enter Mattermost base URL"]);
391+
expect(result.cfg.channels?.mattermost?.botToken).toBe("bot-token");
392+
expect(result.cfg.channels?.mattermost?.baseUrl).toBe("https://chat.example.com");
393+
expect(result.accountId).toBe(DEFAULT_ACCOUNT_ID);
394+
});
355395
});
356396

357397
function registerEnvDefaults() {

0 commit comments

Comments
 (0)