fix: repair ci audit and type drift

This commit is contained in:
Peter Steinberger
2026-03-13 20:59:47 +00:00
parent cfc9a21957
commit b84c7037de
21 changed files with 566 additions and 166 deletions

View File

@@ -9,13 +9,34 @@ import {
matchPluginCommand,
} from "./bot-native-commands.test-helpers.js";
type GetPluginCommandSpecsMock = {
mockReturnValue: (
value: ReturnType<typeof import("../plugins/commands.js").getPluginCommandSpecs>,
) => unknown;
};
type MatchPluginCommandMock = {
mockReturnValue: (
value: ReturnType<typeof import("../plugins/commands.js").matchPluginCommand>,
) => unknown;
};
type ExecutePluginCommandMock = {
mockResolvedValue: (
value: Awaited<ReturnType<typeof import("../plugins/commands.js").executePluginCommand>>,
) => unknown;
};
const getPluginCommandSpecsMock = getPluginCommandSpecs as unknown as GetPluginCommandSpecsMock;
const matchPluginCommandMock = matchPluginCommand as unknown as MatchPluginCommandMock;
const executePluginCommandMock = executePluginCommand as unknown as ExecutePluginCommandMock;
describe("registerTelegramNativeCommands (plugin auth)", () => {
it("does not register plugin commands in menu when native=false but keeps handlers available", () => {
const specs = Array.from({ length: 101 }, (_, i) => ({
name: `cmd_${i}`,
description: `Command ${i}`,
acceptsArgs: false,
}));
getPluginCommandSpecs.mockReturnValue(specs);
getPluginCommandSpecsMock.mockReturnValue(specs);
const { handlers, setMyCommands, log } = createNativeCommandsHarness({
cfg: {} as OpenClawConfig,
@@ -32,13 +53,16 @@ describe("registerTelegramNativeCommands (plugin auth)", () => {
const command = {
name: "plugin",
description: "Plugin command",
pluginId: "test-plugin",
requireAuth: false,
handler: vi.fn(),
} as const;
getPluginCommandSpecs.mockReturnValue([{ name: "plugin", description: "Plugin command" }]);
matchPluginCommand.mockReturnValue({ command, args: undefined });
executePluginCommand.mockResolvedValue({ text: "ok" });
getPluginCommandSpecsMock.mockReturnValue([
{ name: "plugin", description: "Plugin command", acceptsArgs: false },
]);
matchPluginCommandMock.mockReturnValue({ command, args: undefined });
executePluginCommandMock.mockResolvedValue({ text: "ok" });
const { handlers, bot } = createNativeCommandsHarness({
cfg: {} as OpenClawConfig,

View File

@@ -4,7 +4,8 @@ import {
registerTelegramNativeCommands,
type RegisterTelegramHandlerParams,
} from "./bot-native-commands.js";
import { createNativeCommandTestParams } from "./bot-native-commands.test-helpers.js";
type RegisterTelegramNativeCommandsParams = Parameters<typeof registerTelegramNativeCommands>[0];
// All mocks scoped to this file only — does not affect bot-native-commands.test.ts
@@ -108,6 +109,48 @@ function createDeferred<T>() {
return { promise, resolve };
}
function createNativeCommandTestParams(
params: Partial<RegisterTelegramNativeCommandsParams> = {},
): RegisterTelegramNativeCommandsParams {
const log = vi.fn();
return {
bot:
params.bot ??
({
api: {
setMyCommands: vi.fn().mockResolvedValue(undefined),
sendMessage: vi.fn().mockResolvedValue(undefined),
},
command: vi.fn(),
} as unknown as RegisterTelegramNativeCommandsParams["bot"]),
cfg: params.cfg ?? ({} as OpenClawConfig),
runtime:
params.runtime ?? ({ log } as unknown as RegisterTelegramNativeCommandsParams["runtime"]),
accountId: params.accountId ?? "default",
telegramCfg: params.telegramCfg ?? ({} as RegisterTelegramNativeCommandsParams["telegramCfg"]),
allowFrom: params.allowFrom ?? [],
groupAllowFrom: params.groupAllowFrom ?? [],
replyToMode: params.replyToMode ?? "off",
textLimit: params.textLimit ?? 4000,
useAccessGroups: params.useAccessGroups ?? false,
nativeEnabled: params.nativeEnabled ?? true,
nativeSkillsEnabled: params.nativeSkillsEnabled ?? false,
nativeDisabledExplicit: params.nativeDisabledExplicit ?? false,
resolveGroupPolicy:
params.resolveGroupPolicy ??
(() =>
({
allowlistEnabled: false,
allowed: true,
}) as ReturnType<RegisterTelegramNativeCommandsParams["resolveGroupPolicy"]>),
resolveTelegramGroupConfig:
params.resolveTelegramGroupConfig ??
(() => ({ groupConfig: undefined, topicConfig: undefined })),
shouldSkipUpdate: params.shouldSkipUpdate ?? (() => false),
opts: params.opts ?? { token: "token" },
};
}
type TelegramCommandHandler = (ctx: unknown) => Promise<void>;
function buildStatusCommandContext() {

View File

@@ -6,7 +6,6 @@ import { writeSkill } from "../agents/skills.e2e-test-helpers.js";
import type { OpenClawConfig } from "../config/config.js";
import type { TelegramAccountConfig } from "../config/types.js";
import { registerTelegramNativeCommands } from "./bot-native-commands.js";
import { createNativeCommandTestParams } from "./bot-native-commands.test-helpers.js";
const pluginCommandMocks = vi.hoisted(() => ({
getPluginCommandSpecs: vi.fn(() => []),
@@ -77,18 +76,40 @@ describe("registerTelegramNativeCommands skill allowlist integration", () => {
};
registerTelegramNativeCommands({
...createNativeCommandTestParams({
bot: {
api: {
setMyCommands,
sendMessage: vi.fn().mockResolvedValue(undefined),
},
command: vi.fn(),
} as unknown as Parameters<typeof registerTelegramNativeCommands>[0]["bot"],
cfg,
accountId: "bot-a",
telegramCfg: {} as TelegramAccountConfig,
bot: {
api: {
setMyCommands,
sendMessage: vi.fn().mockResolvedValue(undefined),
},
command: vi.fn(),
} as unknown as Parameters<typeof registerTelegramNativeCommands>[0]["bot"],
cfg,
runtime: { log: vi.fn() } as unknown as Parameters<
typeof registerTelegramNativeCommands
>[0]["runtime"],
accountId: "bot-a",
telegramCfg: {} as TelegramAccountConfig,
allowFrom: [],
groupAllowFrom: [],
replyToMode: "off",
textLimit: 4000,
useAccessGroups: false,
nativeEnabled: true,
nativeSkillsEnabled: true,
nativeDisabledExplicit: false,
resolveGroupPolicy: () =>
({
allowlistEnabled: false,
allowed: true,
}) as ReturnType<
Parameters<typeof registerTelegramNativeCommands>[0]["resolveGroupPolicy"]
>,
resolveTelegramGroupConfig: () => ({
groupConfig: undefined,
topicConfig: undefined,
}),
shouldSkipUpdate: () => false,
opts: { token: "token" },
});
await vi.waitFor(() => {

View File

@@ -5,10 +5,15 @@ import type { TelegramAccountConfig } from "../config/types.js";
import type { RuntimeEnv } from "../runtime.js";
import { registerTelegramNativeCommands } from "./bot-native-commands.js";
type RegisterTelegramNativeCommandsParams = Parameters<typeof registerTelegramNativeCommands>[0];
type GetPluginCommandSpecsFn = typeof import("../plugins/commands.js").getPluginCommandSpecs;
type MatchPluginCommandFn = typeof import("../plugins/commands.js").matchPluginCommand;
type ExecutePluginCommandFn = typeof import("../plugins/commands.js").executePluginCommand;
const pluginCommandMocks = vi.hoisted(() => ({
getPluginCommandSpecs: vi.fn(() => []),
matchPluginCommand: vi.fn(() => null),
executePluginCommand: vi.fn(async () => ({ text: "ok" })),
getPluginCommandSpecs: vi.fn<GetPluginCommandSpecsFn>(() => []),
matchPluginCommand: vi.fn<MatchPluginCommandFn>(() => null),
executePluginCommand: vi.fn<ExecutePluginCommandFn>(async () => ({ text: "ok" })),
}));
export const getPluginCommandSpecs = pluginCommandMocks.getPluginCommandSpecs;
export const matchPluginCommand = pluginCommandMocks.matchPluginCommand;
@@ -29,6 +34,48 @@ vi.mock("../pairing/pairing-store.js", () => ({
readChannelAllowFromStore: vi.fn(async () => []),
}));
export function createNativeCommandTestParams(
params: Partial<RegisterTelegramNativeCommandsParams> = {},
): RegisterTelegramNativeCommandsParams {
const log = vi.fn();
return {
bot:
params.bot ??
({
api: {
setMyCommands: vi.fn().mockResolvedValue(undefined),
sendMessage: vi.fn().mockResolvedValue(undefined),
},
command: vi.fn(),
} as unknown as RegisterTelegramNativeCommandsParams["bot"]),
cfg: params.cfg ?? ({} as OpenClawConfig),
runtime:
params.runtime ?? ({ log } as unknown as RegisterTelegramNativeCommandsParams["runtime"]),
accountId: params.accountId ?? "default",
telegramCfg: params.telegramCfg ?? ({} as RegisterTelegramNativeCommandsParams["telegramCfg"]),
allowFrom: params.allowFrom ?? [],
groupAllowFrom: params.groupAllowFrom ?? [],
replyToMode: params.replyToMode ?? "off",
textLimit: params.textLimit ?? 4000,
useAccessGroups: params.useAccessGroups ?? false,
nativeEnabled: params.nativeEnabled ?? true,
nativeSkillsEnabled: params.nativeSkillsEnabled ?? false,
nativeDisabledExplicit: params.nativeDisabledExplicit ?? false,
resolveGroupPolicy:
params.resolveGroupPolicy ??
(() =>
({
allowlistEnabled: false,
allowed: true,
}) as ReturnType<RegisterTelegramNativeCommandsParams["resolveGroupPolicy"]>),
resolveTelegramGroupConfig:
params.resolveTelegramGroupConfig ??
(() => ({ groupConfig: undefined, topicConfig: undefined })),
shouldSkipUpdate: params.shouldSkipUpdate ?? (() => false),
opts: params.opts ?? { token: "token" },
};
}
export function createNativeCommandsHarness(params?: {
cfg?: OpenClawConfig;
runtime?: RuntimeEnv;

View File

@@ -6,7 +6,6 @@ import { TELEGRAM_COMMAND_NAME_PATTERN } from "../config/telegram-custom-command
import type { TelegramAccountConfig } from "../config/types.js";
import type { RuntimeEnv } from "../runtime.js";
import { registerTelegramNativeCommands } from "./bot-native-commands.js";
import { createNativeCommandTestParams } from "./bot-native-commands.test-helpers.js";
const { listSkillCommandsForAgents } = vi.hoisted(() => ({
listSkillCommandsForAgents: vi.fn(() => []),
@@ -65,7 +64,7 @@ describe("registerTelegramNativeCommands", () => {
});
const buildParams = (cfg: OpenClawConfig, accountId = "default") =>
createNativeCommandTestParams({
({
bot: {
api: {
setMyCommands: vi.fn().mockResolvedValue(undefined),
@@ -77,7 +76,28 @@ describe("registerTelegramNativeCommands", () => {
runtime: {} as RuntimeEnv,
accountId,
telegramCfg: {} as TelegramAccountConfig,
});
allowFrom: [],
groupAllowFrom: [],
replyToMode: "off",
textLimit: 4000,
useAccessGroups: false,
nativeEnabled: true,
nativeSkillsEnabled: true,
nativeDisabledExplicit: false,
resolveGroupPolicy: () =>
({
allowlistEnabled: false,
allowed: true,
}) as ReturnType<
Parameters<typeof registerTelegramNativeCommands>[0]["resolveGroupPolicy"]
>,
resolveTelegramGroupConfig: () => ({
groupConfig: undefined,
topicConfig: undefined,
}),
shouldSkipUpdate: () => false,
opts: { token: "token" },
}) satisfies Parameters<typeof registerTelegramNativeCommands>[0];
it("scopes skill commands when account binding exists", () => {
const cfg: OpenClawConfig = {