fix(scripts): reject flag device-pair Telegram values

This commit is contained in:
Vincent Koc
2026-06-21 22:56:54 +02:00
parent 3e1d3c5feb
commit 6823f56d8e
2 changed files with 23 additions and 1 deletions
+5 -1
View File
@@ -43,6 +43,10 @@ type DevicePairTelegramArgs = {
const BOOLEAN_FLAGS = new Set(["--help", "-h"]);
const VALUE_FLAGS = new Set(["--account", "-a", "--chat", "-c"]);
function isMissingOptionValue(value: string | undefined): boolean {
return !value || BOOLEAN_FLAGS.has(value) || VALUE_FLAGS.has(value) || value.startsWith("--");
}
function writeStdoutLine(...parts: string[]): void {
process.stdout.write(`${parts.join(" ")}\n`);
}
@@ -84,7 +88,7 @@ function validateArgs(args: readonly string[]): void {
}
if (VALUE_FLAGS.has(arg)) {
const value = args[index + 1];
if (!value || value.startsWith("--")) {
if (isMissingOptionValue(value)) {
throw new CliArgumentError(`${arg} requires a value`);
}
index += 1;
@@ -21,6 +21,24 @@ describe("scripts/dev/test-device-pair-telegram.ts", () => {
});
});
it("rejects option tokens as device-pair Telegram values", () => {
for (const flag of ["--chat", "-c", "--account", "-a"]) {
expect(() => parseDevicePairTelegramArgs([flag, "-h"])).toThrow(
`${flag} requires a value`,
);
}
expect(() => parseDevicePairTelegramArgs(["--chat", "--help"])).toThrow(
"--chat requires a value",
);
});
it("allows negative Telegram chat ids", () => {
expect(parseDevicePairTelegramArgs(["--chat", "-100123"])).toMatchObject({
chatId: "-100123",
help: false,
});
});
it("rejects unknown args before loading OpenClaw plugins", async () => {
const cfg = { channels: { telegram: { enabled: true } } };
const loadOpenClawPlugins = vi.fn();