refactor: simplify extension conversions

This commit is contained in:
Peter Steinberger
2026-04-11 01:37:23 +01:00
parent 780e0898b0
commit 3e80bd33e4
19 changed files with 32 additions and 37 deletions

View File

@@ -495,7 +495,7 @@ function normalizePluginConfig(pluginConfig: unknown): ResolvedActiveRecallPlugi
return {
enabled: raw.enabled !== false,
agents: Array.isArray(raw.agents)
? raw.agents.map((agentId) => String(agentId).trim()).filter(Boolean)
? raw.agents.map((agentId) => agentId.trim()).filter(Boolean)
: [],
model: typeof raw.model === "string" && raw.model.trim() ? raw.model.trim() : undefined,
modelFallbackPolicy:

View File

@@ -575,7 +575,7 @@ export function installBrowserControlServerHooks() {
vi.stubGlobal(
"fetch",
vi.fn(async (url: string, init?: RequestInit) => {
const u = String(url);
const u = url;
if (u.includes("/json/list")) {
if (!state.reachable) {
return makeResponse([]);

View File

@@ -53,7 +53,7 @@ describe("profile CRUD endpoints", () => {
vi.stubGlobal(
"fetch",
vi.fn(async (url: string) => {
const u = String(url);
const u = url;
if (u.includes("/json/list")) {
return makeResponse([]);
}

View File

@@ -61,7 +61,7 @@ describe("codex command", () => {
const deps = createDeps({
codexControlRequest: vi.fn(
async (_pluginConfig: unknown, method: string, requestParams: unknown) => {
requests.push({ method: String(method), params: requestParams });
requests.push({ method, params: requestParams });
return {
thread: { id: "thread-123", cwd: "/repo" },
model: "gpt-5.4",

View File

@@ -262,13 +262,13 @@ describe("extractGeminiCliCredentials", () => {
});
mockRealpathSync.mockReturnValue(resolvedPath);
mockReaddirSync.mockImplementation((p: string) => {
if (normalizePath(String(p)) === normalizePath(bundleDir)) {
if (normalizePath(p) === normalizePath(bundleDir)) {
return [dirent("chunk-ABC123.js", false)];
}
return [];
});
mockReadFileSync.mockImplementation((p: string) => {
if (normalizePath(String(p)) === normalizePath(chunkPath)) {
if (normalizePath(p) === normalizePath(chunkPath)) {
return params.bundleContent;
}
throw new Error(`Unexpected read for ${p}`);

View File

@@ -2925,7 +2925,7 @@ describe("QmdMemoryManager", () => {
return [
{
collection: "sessions-main",
path: `${String(arg)}.md`,
path: `${arg}.md`,
},
];
default:

View File

@@ -92,7 +92,7 @@ describe("minimax provider hooks", () => {
let resolvedApiModelId = "";
const captureApiModel: StreamFn = (model) => {
resolvedApiModelId = String(model.id ?? "");
resolvedApiModelId = model.id ?? "";
return {} as ReturnType<StreamFn>;
};
const wrappedApiStream = apiProvider.wrapStreamFn?.({
@@ -114,7 +114,7 @@ describe("minimax provider hooks", () => {
let resolvedPortalModelId = "";
const capturePortalModel: StreamFn = (model) => {
resolvedPortalModelId = String(model.id ?? "");
resolvedPortalModelId = model.id ?? "";
return {} as ReturnType<StreamFn>;
};
const wrappedPortalStream = portalProvider.wrapStreamFn?.({

View File

@@ -326,7 +326,7 @@ describe("msteams graph attachments", () => {
);
expectAttachmentMediaLength(media.media, 0);
const calledUrls = fetchMock.mock.calls.map((call) => String(call[0]));
const calledUrls = fetchMock.mock.calls.map((call) => call[0]);
expect(calledUrls.some((url) => url.startsWith(GRAPH_SHARES_URL_PREFIX))).toBe(true);
expect(calledUrls).not.toContain(escapedUrl);
});

View File

@@ -445,7 +445,7 @@ describe("msteams attachments", () => {
expectAttachmentMediaLength(media, 1);
expect(tokenProvider.getAccessToken).toHaveBeenCalledOnce();
expect(fetchMock.mock.calls.map(([calledUrl]) => String(calledUrl))).toContain(redirectedUrl);
expect(fetchMock.mock.calls.map(([calledUrl]) => calledUrl)).toContain(redirectedUrl);
});
it("continues scope fallback after non-auth failure and succeeds on later scope", async () => {

View File

@@ -240,7 +240,7 @@ describeLive("openai plugin live", () => {
timeoutMs: 30_000,
});
const text = String(transcription?.text ?? "").toLowerCase();
const text = (transcription?.text ?? "").toLowerCase();
expect(text.length).toBeGreaterThan(0);
expect(text).toContain("openclaw");
expect(text).toMatch(/\bok\b/);
@@ -330,7 +330,7 @@ describeLive("openai plugin live", () => {
provider: "openai",
});
expect(String(description?.text ?? "").toLowerCase()).toContain("orange");
expect((description?.text ?? "").toLowerCase()).toContain("orange");
} finally {
await fs.rm(agentDir, { recursive: true, force: true });
}

View File

@@ -58,7 +58,7 @@ function createMockQaRuntime(): PluginRuntime {
dispatcherOptions: { deliver: (payload: { text: string }) => Promise<void> };
}) {
await dispatcherOptions.deliver({
text: `qa-echo: ${String(ctx.BodyForAgent ?? ctx.Body ?? "")}`,
text: `qa-echo: ${ctx.BodyForAgent ?? ctx.Body ?? ""}`,
});
},
},

View File

@@ -268,9 +268,7 @@ describe("monitorSlackProvider tool results", () => {
}
function expectReactionNames(names: string[]) {
expect(reactMock.mock.calls.map(([args]) => String((args as { name: string }).name))).toEqual(
names,
);
expect(reactMock.mock.calls.map(([args]) => (args as { name: string }).name)).toEqual(names);
}
async function runDefaultMessageAndExpectSentText(expectedText: string) {

View File

@@ -1991,7 +1991,7 @@ describe("dispatchTelegramMessage draft streaming", () => {
);
expect(answerDraftStream.update).toHaveBeenCalledWith("3");
expect(
answerDraftStream.update.mock.calls.some((call) => String(call[0] ?? "").includes("<think>")),
answerDraftStream.update.mock.calls.some((call) => (call[0] ?? "").includes("<think>")),
).toBe(false);
expect(editMessageTelegram).toHaveBeenCalledWith(123, 999, "3", expect.any(Object));
});
@@ -2021,9 +2021,9 @@ describe("dispatchTelegramMessage draft streaming", () => {
expect(reasoningDraftStream.update).toHaveBeenCalledWith(
"Reasoning:\n_Counting letters in strawberry_",
);
expect(
answerDraftStream.update.mock.calls.some((call) => String(call[0] ?? "").includes("<")),
).toBe(false);
expect(answerDraftStream.update.mock.calls.some((call) => (call[0] ?? "").includes("<"))).toBe(
false,
);
expect(editMessageTelegram).toHaveBeenCalledWith(
123,
999,

View File

@@ -31,8 +31,8 @@ function cleanExpiredMentions(): void {
function resolveOwnershipAgent(config: OpenClawConfig): { id: string; name: string } {
const list = Array.isArray(config.agents?.list)
? config.agents.list.filter((entry): entry is AgentEntry =>
Boolean(entry && typeof entry === "object"),
? config.agents.list.filter(
(entry): entry is AgentEntry => entry !== null && typeof entry === "object",
)
: [];
const selected = list.find((entry) => entry.default === true) ?? list[0];

View File

@@ -369,7 +369,7 @@ describe("verifyPlivoWebhook", () => {
describe("verifyTelnyxWebhook", () => {
it("marks replayed valid requests as replay without failing auth", () => {
const { publicKey, privateKey } = crypto.generateKeyPairSync("ed25519");
const pemPublicKey = publicKey.export({ format: "pem", type: "spki" }).toString();
const pemPublicKey = publicKey.export({ format: "pem", type: "spki" });
const timestamp = String(Math.floor(Date.now() / 1000));
const rawBody = JSON.stringify({
data: { event_type: "call.initiated", payload: { call_control_id: "call-1" } },
@@ -395,7 +395,7 @@ describe("verifyTelnyxWebhook", () => {
it("treats Base64 and Base64URL signatures as the same replayed request", () => {
const { publicKey, privateKey } = crypto.generateKeyPairSync("ed25519");
const pemPublicKey = publicKey.export({ format: "pem", type: "spki" }).toString();
const pemPublicKey = publicKey.export({ format: "pem", type: "spki" });
const timestamp = String(Math.floor(Date.now() / 1000));
const rawBody = JSON.stringify({
data: { event_type: "call.initiated", payload: { call_control_id: "call-1" } },

View File

@@ -202,14 +202,11 @@ export function expectPairingPromptSent(sock: MockSock, jid: string, senderE164:
expect(sock.sendMessage).toHaveBeenCalledTimes(1);
const sendCall = sock.sendMessage.mock.calls[0];
expect(sendCall?.[0]).toBe(jid);
expectInboxPairingReplyText(
String((sendCall?.[1] as { text?: string } | undefined)?.text ?? ""),
{
channel: "whatsapp",
idLine: `Your WhatsApp phone number: ${senderE164}`,
code: "PAIRCODE",
},
);
expectInboxPairingReplyText((sendCall?.[1] as { text?: string } | undefined)?.text ?? "", {
channel: "whatsapp",
idLine: `Your WhatsApp phone number: ${senderE164}`,
code: "PAIRCODE",
});
}
let authDir: string | undefined;

View File

@@ -319,7 +319,7 @@ vi.mock("./auto-reply/monitor/runtime-api.js", () => ({
},
logVerbose: (_msg: string) => undefined,
normalizeE164: (value: string) => {
const digits = String(value).replace(/\D+/g, "");
const digits = value.replace(/\D+/g, "");
return digits ? `+${digits}` : null;
},
readStoreAllowFromForDmPolicy: async () => [] as string[],
@@ -363,7 +363,7 @@ vi.mock("./auto-reply/monitor/group-gating.runtime.js", () => ({
hasControlCommand: (body: string) => body.trim().startsWith("/"),
implicitMentionKindWhen: (kind: string, enabled: boolean) => (enabled ? [kind] : []),
normalizeE164: (value: string) => {
const digits = String(value).replace(/\D+/g, "");
const digits = value.replace(/\D+/g, "");
return digits ? `+${digits}` : null;
},
parseActivationCommand: (body: string) => ({

View File

@@ -42,7 +42,7 @@ describe("xai provider plugin", () => {
let capturedModelId = "";
let capturedPayload: Record<string, unknown> | undefined;
const baseStreamFn: StreamFn = (model, _context, options) => {
capturedModelId = String(model.id);
capturedModelId = model.id;
const payload: Record<string, unknown> = {
reasoning: { effort: "high" },
tools: [

View File

@@ -97,7 +97,7 @@ describe("xai stream wrappers", () => {
let capturedModelId = "";
let capturedPayload: XaiTestPayload | undefined;
const baseStreamFn: StreamFn = (model, _context, options) => {
capturedModelId = String(model.id);
capturedModelId = model.id;
const payload: XaiTestPayload = {
reasoning: { effort: "high" },
tools: [