Skip to content

Commit d65c9be

Browse files
committed
fix(irc): drop the never-read mentionPatterns config key
The IRC schema accepted channels.irc.mentionPatterns and the type declared it, but nothing in the IRC runtime ever read it, so operators could set a mention allowlist that silently did nothing. Restored after an earlier rebase of this branch resolved a conflict in extensions/irc/src/config-schema.ts in favour of main and reverted the removal, leaving the PR carrying only generated-baseline churn.
1 parent 9826dca commit d65c9be

14 files changed

Lines changed: 138 additions & 52 deletions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"core": 2361,
3-
"channel": 3679,
3+
"channel": 3677,
44
"plugin": 4028
55
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
fb4ce03b779efdf6c4d88f32d1b8e5014acbb8ae9862ffd79689afbd474b9fa2 config-baseline.json
1+
e885ccf2231149680a9544368f707592a7764a76feb17aa00dd7e44f84e4c943 config-baseline.json
22
b0ded1a606c27b41dc14041b12ff32ebf44314032be6af31d38856bf6db10df6 config-baseline.core.json
3-
9754785c4422c619a4d9e89d3a645339cd4adb1fe929a31092364857257acb67 config-baseline.channel.json
3+
f2783084231404a0586bf6cfa6981df6617c51186984d84bb9fc8e7ba9237d92 config-baseline.channel.json
44
30ea5089672338a910478e45a04d7ddb6bd3e62cb52b3f209d2372ddc0dbfc31 config-baseline.plugin.json

‎extensions/irc/doctor-contract-api.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,44 @@ describe("irc normalizeCompatibilityConfig streaming aliases", () => {
5959
expect(second.config).toBe(first.config);
6060
});
6161
});
62+
63+
describe("irc retired mentionPatterns migration", () => {
64+
it("flags and strips the retired key at root and account scope", () => {
65+
const cfg = ircConfig({
66+
host: "irc.libera.chat",
67+
mentionPatterns: ["\\bopenclaw\\b"],
68+
accounts: { work: { nick: "openclaw-ops", mentionPatterns: ["\\bops\\b"] } },
69+
});
70+
71+
const rootRule = legacyConfigRules.find(
72+
(rule) => rule.path.join(".") === "channels.irc" && rule.message?.includes("mentionPatterns"),
73+
);
74+
const accountRule = legacyConfigRules.find(
75+
(rule) =>
76+
rule.path.join(".") === "channels.irc.accounts" &&
77+
rule.message?.includes("mentionPatterns"),
78+
);
79+
expect(rootRule?.match?.({ mentionPatterns: ["x"] }, {})).toBe(true);
80+
expect(rootRule?.match?.({ host: "irc.libera.chat" }, {})).toBe(false);
81+
expect(accountRule?.match?.({ work: { mentionPatterns: ["x"] } }, {})).toBe(true);
82+
expect(accountRule?.match?.({ work: { nick: "n" } }, {})).toBe(false);
83+
84+
const result = normalizeCompatibilityConfig({ cfg });
85+
const irc = expectDefined(
86+
(result.config.channels as Record<string, Record<string, unknown>> | undefined)?.irc,
87+
"channels.irc",
88+
);
89+
expect(irc.mentionPatterns).toBeUndefined();
90+
expect(irc.host).toBe("irc.libera.chat");
91+
const accounts = irc.accounts as Record<string, Record<string, unknown> | undefined>;
92+
const workAccount = expectDefined(accounts.work, "channels.irc.accounts.work");
93+
expect(workAccount.mentionPatterns).toBeUndefined();
94+
expect(workAccount.nick).toBe("openclaw-ops");
95+
expect(result.changes.some((change) => change.includes("mentionPatterns"))).toBe(true);
96+
});
97+
98+
it("leaves a config without the retired key untouched", () => {
99+
const result = normalizeCompatibilityConfig({ cfg: ircConfig({ host: "irc.libera.chat" }) });
100+
expect(result.changes.some((change) => change.includes("mentionPatterns"))).toBe(false);
101+
});
102+
});

‎extensions/irc/doctor-contract-api.ts‎

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import type {
44
ChannelDoctorLegacyConfigRule,
55
} from "openclaw/plugin-sdk/channel-contract";
66
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
7-
import { defineChannelAliasMigration } from "openclaw/plugin-sdk/runtime-doctor-migrations";
7+
import {
8+
asObjectRecord,
9+
defineChannelAliasMigration,
10+
stripRetiredChannelKeys,
11+
} from "openclaw/plugin-sdk/runtime-doctor-migrations";
812

913
// IRC's nested streaming schema is delivery-only ({chunkMode, block}); it has
1014
// no preview mode, so only the delivery flat aliases are legal legacy input.
@@ -17,13 +21,46 @@ const streamingAliasMigration = defineChannelAliasMigration({
1721
accountStreamingReplacesRoot: true,
1822
});
1923

20-
export const legacyConfigRules: ChannelDoctorLegacyConfigRule[] =
21-
streamingAliasMigration.legacyConfigRules;
24+
// channels.irc.mentionPatterns was declared by the schema but never read by any
25+
// IRC or core code path, and its string-array shape collided with the core
26+
// mentionPatterns policy object. Mention patterns come from
27+
// messages.groupChat.mentionPatterns, so the key is stripped rather than wired.
28+
const RETIRED_IRC_KEYS = new Set(["mentionPatterns"]);
29+
30+
export const legacyConfigRules: ChannelDoctorLegacyConfigRule[] = [
31+
...streamingAliasMigration.legacyConfigRules,
32+
{
33+
path: ["channels", "irc"],
34+
match: (value) => Object.hasOwn(asObjectRecord(value) ?? {}, "mentionPatterns"),
35+
message:
36+
'channels.irc.mentionPatterns was accepted but never read; configure mention patterns with messages.groupChat.mentionPatterns. Run "openclaw doctor --fix".',
37+
},
38+
{
39+
path: ["channels", "irc", "accounts"],
40+
match: (value) =>
41+
Object.values(asObjectRecord(value) ?? {}).some((account) =>
42+
Object.hasOwn(asObjectRecord(account) ?? {}, "mentionPatterns"),
43+
),
44+
message:
45+
'channels.irc.accounts.<id>.mentionPatterns was accepted but never read; configure mention patterns with messages.groupChat.mentionPatterns. Run "openclaw doctor --fix".',
46+
},
47+
];
2248

2349
export function normalizeCompatibilityConfig({
2450
cfg,
2551
}: {
2652
cfg: OpenClawConfig;
2753
}): ChannelDoctorConfigMutation {
28-
return streamingAliasMigration.normalizeChannelConfig({ cfg });
54+
const aliases = streamingAliasMigration.normalizeChannelConfig({ cfg });
55+
const changes = [...aliases.changes];
56+
const stripped = stripRetiredChannelKeys({
57+
cfg: aliases.config,
58+
channelId: "irc",
59+
keys: RETIRED_IRC_KEYS,
60+
scope: "root-and-accounts",
61+
onRemove: (removed) => {
62+
changes.push(`Removed ${removed.pathPrefix}.${removed.key}; it was never read.`);
63+
},
64+
});
65+
return { config: stripped.config, changes };
2966
}

‎extensions/irc/src/config-schema.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,26 @@ describe("irc config schema", () => {
150150
);
151151
});
152152
});
153+
154+
describe("retired IRC mentionPatterns", () => {
155+
it("rejects the retired key at root and account scope", () => {
156+
expectInvalidConfig(
157+
parseIrcConfig({ host: "irc.libera.chat", mentionPatterns: ["\\bopenclaw\\b"] }),
158+
);
159+
expectInvalidConfig(
160+
parseIrcConfig({
161+
host: "irc.libera.chat",
162+
accounts: { work: { nick: "openclaw-ops", mentionPatterns: ["\\bops\\b"] } },
163+
}),
164+
);
165+
});
166+
167+
it("still accepts the same config once the retired key is gone", () => {
168+
expectValidConfig(
169+
parseIrcConfig({
170+
host: "irc.libera.chat",
171+
accounts: { work: { nick: "openclaw-ops" } },
172+
}),
173+
);
174+
});
175+
});

‎extensions/irc/src/config-schema.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ const IrcAccountSchemaBase = z
5555
groupAllowFrom: z.array(z.union([z.string(), z.number()])).optional(),
5656
groups: z.record(z.string(), ChannelGroupEntrySchema.optional()).optional(),
5757
channels: z.array(z.string()).optional(),
58-
mentionPatterns: z.array(z.string()).optional(),
5958
markdown: MarkdownConfigSchema,
6059
...ReplyRuntimeConfigSchemaShape,
6160
})

‎extensions/irc/src/types.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ export type IrcAccountConfig = {
5858
groupAllowFrom?: Array<string | number>;
5959
groups?: Record<string, IrcChannelConfig>;
6060
channels?: string[];
61-
mentionPatterns?: string[];
6261
markdown?: MarkdownConfig;
6362
historyLimit?: number;
6463
dmHistoryLimit?: number;

‎src/channels/plugins/config-schema.test.ts‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { describe, expect, expectTypeOf, it, vi } from "vitest";
33
import { z } from "zod";
44
import {
55
ChannelGroupEntrySchema,
6-
ChannelMentionPatternsSchemas,
76
buildChannelConfigSchema,
87
buildGroupEntrySchema,
98
buildJsonChannelConfigSchema,
@@ -40,16 +39,6 @@ describe("channel config composition", () => {
4039
expect(schema.safeParse({ skills: ["search"] }).success).toBe(false);
4140
});
4241

43-
it("keeps canonical mention policy while allowing IRC array sugar", () => {
44-
const canonical = ChannelMentionPatternsSchemas.canonical;
45-
const arraySugar = ChannelMentionPatternsSchemas.stringArray;
46-
47-
expect(canonical.safeParse({ mode: "allow", denyIn: ["room"] }).success).toBe(true);
48-
expect(canonical.safeParse(["openclaw"]).success).toBe(false);
49-
expect(arraySugar.safeParse(["openclaw"]).success).toBe(true);
50-
expect(arraySugar.safeParse({ mode: "deny", allowIn: ["#bots"] }).success).toBe(false);
51-
});
52-
5342
it("applies one shared refinement to root and account entries", () => {
5443
const base = z.object({
5544
policy: z.enum(["closed", "open"]).optional(),

‎src/channels/plugins/config-schema.ts‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
import { z, type ZodRawShape, type ZodTypeAny } from "zod";
77
import { ToolPolicySchema } from "../../config/zod-schema.agent-runtime.js";
8-
import { DmPolicySchema, MentionPatternsPolicySchema } from "../../config/zod-schema.core.js";
8+
import { DmPolicySchema } from "../../config/zod-schema.core.js";
99
import { validateJsonSchemaValue } from "../../plugins/schema-validator.js";
1010
import type { JsonSchemaObject } from "../../shared/json-schema.types.js";
1111
import { parseConfigPathArrayIndex } from "../../shared/path-array-index.js";
@@ -58,12 +58,6 @@ export function buildGroupEntrySchema<
5858
return z.object({ ...baseShape, ...(extraShape ?? ({} as T)) }).strict();
5959
}
6060

61-
/** Shared mention-policy schemas. IRC retains its shipped string-array form. */
62-
export const ChannelMentionPatternsSchemas = {
63-
canonical: MentionPatternsPolicySchema,
64-
stringArray: z.array(z.string()),
65-
} as const;
66-
6761
/** Build the common nested DM config block used by channel account schemas. */
6862
export function buildNestedDmConfigSchema(extraShape?: ZodRawShape) {
6963
const baseShape = {

‎src/config/bundled-channel-config-metadata.generated.ts‎

Lines changed: 13 additions & 13 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)