test: normalize command context text safely

This commit is contained in:
Peter Steinberger
2026-04-11 00:44:33 +01:00
parent 2b45a90f71
commit 9469ffc095

View File

@@ -21,6 +21,16 @@ function firstText(values: Array<string | undefined>): string | undefined {
return values.map((value) => value?.trim() ?? "").find(Boolean) || undefined;
}
function normalizeCommandContextText(value: unknown): string {
if (typeof value === "string") {
return value.trim().toLowerCase();
}
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
return String(value).trim().toLowerCase();
}
return "";
}
function resolveThreadTargetId(raw?: string): string | undefined {
const trimmed = raw?.trim() ?? "";
if (!trimmed) {
@@ -289,17 +299,13 @@ function buildSessionCommandParams(
SenderId: "user-1",
...ctxOverrides,
} as HandleCommandsParams["ctx"];
const channel = String(ctx.Provider ?? ctx.Surface ?? "")
.trim()
.toLowerCase();
const channel = normalizeCommandContextText(ctx.Provider ?? ctx.Surface);
const senderId = typeof ctx.SenderId === "string" ? ctx.SenderId : undefined;
return {
ctx,
cfg: baseCfg,
command: {
surface: String(ctx.Surface ?? ctx.Provider ?? "")
.trim()
.toLowerCase(),
surface: normalizeCommandContextText(ctx.Surface ?? ctx.Provider),
channel,
channelId: channel,
ownerList: [],