refactor: dedupe remaining lowercase helpers

This commit is contained in:
Peter Steinberger
2026-04-07 15:05:41 +01:00
parent 9314bb7180
commit 1f48ee8f9c
6 changed files with 23 additions and 8 deletions

View File

@@ -13,6 +13,7 @@ import type {
IngestResult,
} from "../../../context-engine/types.js";
import { formatErrorMessage } from "../../../infra/errors.js";
import { normalizeLowercaseStringOrEmpty } from "../../../shared/string-coerce.js";
import type { EmbeddedContextFile } from "../../pi-embedded-helpers.js";
import type { MessagingToolSend } from "../../pi-embedded-messaging.js";
import type { WorkspaceBootstrapFile } from "../../workspace.js";
@@ -391,7 +392,7 @@ vi.mock("../../../image-generation/runtime.js", () => ({
}));
vi.mock("../../model-selection.js", () => ({
normalizeProviderId: (providerId?: string) => providerId?.trim().toLowerCase() ?? "",
normalizeProviderId: (providerId?: string) => normalizeLowercaseStringOrEmpty(providerId),
resolveDefaultModelForAgent: () => ({ provider: "openai", model: "gpt-test" }),
}));

View File

@@ -1,4 +1,5 @@
import { vi } from "vitest";
import { normalizeOptionalLowercaseString } from "../../shared/string-coerce.js";
import { stubTool } from "./fast-tool-stubs.js";
// Sessions-tool tests only exercise sessions/subagent registrations.
@@ -45,7 +46,7 @@ vi.mock("../tools/update-plan-tool.js", () => ({
vi.mock("../../channels/plugins/index.js", () => ({
getChannelPlugin: () => null,
normalizeChannelId: (channel?: string) => channel?.trim().toLowerCase() || undefined,
normalizeChannelId: (channel?: string) => normalizeOptionalLowercaseString(channel),
listChannelPlugins: () => [],
}));

View File

@@ -9,6 +9,7 @@ import { createEmptyPluginRegistry } from "../plugins/registry-empty.js";
import type { PluginProviderRegistration } from "../plugins/registry.js";
import { resetPluginRuntimeStateForTest, setActivePluginRegistry } from "../plugins/runtime.js";
import type { ProviderPlugin } from "../plugins/types.js";
import { normalizeLowercaseStringOrEmpty } from "../shared/string-coerce.js";
import {
loadModelCatalogMock,
runEmbeddedPiAgentMock,
@@ -61,7 +62,8 @@ function createThinkingPolicyProvider(
id: providerId,
label: providerId,
auth: [],
supportsXHighThinking: ({ modelId }) => xhighModelIds.includes(modelId.trim().toLowerCase()),
supportsXHighThinking: ({ modelId }) =>
xhighModelIds.includes(normalizeLowercaseStringOrEmpty(modelId)),
};
}

View File

@@ -6,9 +6,13 @@
<title>OpenClaw Canvas</title>
<script>
(() => {
const normalizeLower = (value) => {
const trimmed = String(value || "").trim();
return trimmed.toLowerCase();
};
try {
const params = new URLSearchParams(window.location.search);
const platform = (params.get("platform") || "").trim().toLowerCase();
const platform = normalizeLower(params.get("platform"));
if (platform) {
document.documentElement.dataset.platform = platform;
return;
@@ -246,7 +250,7 @@
const params = new URLSearchParams(window.location.search);
const raw = params.get("debugStatus") ?? params.get("debug");
if (!raw) return false;
const normalized = String(raw).trim().toLowerCase();
const normalized = normalizeLower(raw);
return normalized === "1" || normalized === "true" || normalized === "yes";
} catch (_) {
return false;

View File

@@ -3,6 +3,7 @@ import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, vi } from "vitest";
import { createEmptyPluginRegistry } from "../plugins/registry-empty.js";
import { normalizeLowercaseStringOrEmpty } from "../shared/string-coerce.js";
import type { MockFn } from "../test-utils/vitest-mock-fn.js";
import {
readEmbeddedGatewayTokenForTest,
@@ -307,7 +308,7 @@ vi.mock("openclaw/plugin-sdk/provider-auth", () => ({
vi.mock("openclaw/plugin-sdk/provider-model-shared", () => ({
DEFAULT_CONTEXT_TOKENS: 32768,
normalizeProviderId: (value: string) => value.trim().toLowerCase(),
normalizeProviderId: (value: string) => normalizeLowercaseStringOrEmpty(value),
}));
vi.mock("openclaw/plugin-sdk/provider-stream-shared", () => ({

View File

@@ -13,6 +13,10 @@ import {
type RoutePeer,
} from "../../plugin-sdk/routing.js";
import { setActivePluginRegistry } from "../../plugins/runtime.js";
import {
normalizeLowercaseStringOrEmpty,
normalizeOptionalLowercaseString,
} from "../../shared/string-coerce.js";
import {
createChannelTestPluginBase,
createTestRegistry,
@@ -180,7 +184,7 @@ function resolveSlackOutboundSessionRouteForTest(params: ChannelOutboundSessionR
const isGroupChannel =
/^g/i.test(rawId) &&
params.cfg.channels?.slack?.dm?.groupChannels?.some(
(candidate) => String(candidate).trim().toLowerCase() === normalizedId,
(candidate) => normalizeLowercaseStringOrEmpty(String(candidate)) === normalizedId,
) === true;
const peerKind: RoutePeer["kind"] = isDm ? "direct" : isGroupChannel ? "group" : "channel";
return buildThreadedChannelRoute({
@@ -266,7 +270,9 @@ function resolveMattermostOutboundSessionRouteForTest(params: ChannelOutboundSes
}
function resolveWhatsAppOutboundSessionRouteForTest(params: ChannelOutboundSessionRouteParams) {
const normalized = stripChannelTargetPrefix(params.target, "whatsapp").trim().toLowerCase();
const normalized = normalizeOptionalLowercaseString(
stripChannelTargetPrefix(params.target, "whatsapp"),
);
if (!normalized) {
return null;
}