style: apply formatter cleanups

This commit is contained in:
Shakker
2026-03-30 16:18:42 +01:00
committed by Shakker
parent ab141df4b5
commit 3ad747e25f
25 changed files with 130 additions and 112 deletions

View File

@@ -1,12 +1,7 @@
import fs from "node:fs/promises";
import path from "node:path";
import type { AgentTool, AgentToolResult } from "@mariozechner/pi-agent-core";
import {
type ExecHost,
loadExecApprovals,
maxAsk,
minSecurity,
} from "../infra/exec-approvals.js";
import { type ExecHost, loadExecApprovals, maxAsk, minSecurity } from "../infra/exec-approvals.js";
import { resolveExecSafeBinRuntimePolicy } from "../infra/exec-safe-bin-runtime-policy.js";
import { sanitizeHostExecEnvWithDiagnostics } from "../infra/host-env-security.js";
import {

View File

@@ -1,8 +1,5 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import {
setupClaudeCliRunnerTestModule,
supervisorSpawnMock,
} from "./cli-runner.test-support.js";
import { setupClaudeCliRunnerTestModule, supervisorSpawnMock } from "./cli-runner.test-support.js";
function createDeferred<T>() {
let resolve: (value: T) => void = () => {};

View File

@@ -1,7 +1,7 @@
import type { AgentEvent, AgentMessage } from "@mariozechner/pi-agent-core";
import { resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
import { isSilentReplyText, SILENT_REPLY_TOKEN } from "../auto-reply/tokens.js";
import { parseReplyDirectives } from "../auto-reply/reply/reply-directives.js";
import { isSilentReplyText, SILENT_REPLY_TOKEN } from "../auto-reply/tokens.js";
import { emitAgentEvent } from "../infra/agent-events.js";
import { createInlineCodeState } from "../markdown/code-spans.js";
import {
@@ -392,7 +392,11 @@ export function handleMessageEnd(
}
}
if (!ctx.params.silentExpected && !ctx.state.emittedAssistantUpdate && (cleanedText || hasMedia)) {
if (
!ctx.params.silentExpected &&
!ctx.state.emittedAssistantUpdate &&
(cleanedText || hasMedia)
) {
const data = buildAssistantStreamData({
text: cleanedText,
delta: cleanedText,

View File

@@ -1,8 +1,8 @@
import type { AgentMessage } from "@mariozechner/pi-agent-core";
import { parseReplyDirectives } from "../auto-reply/reply/reply-directives.js";
import { createStreamingDirectiveAccumulator } from "../auto-reply/reply/streaming-directives.js";
import { formatToolAggregate } from "../auto-reply/tool-meta.js";
import { isSilentReplyText, SILENT_REPLY_TOKEN } from "../auto-reply/tokens.js";
import { formatToolAggregate } from "../auto-reply/tool-meta.js";
import { emitAgentEvent } from "../infra/agent-events.js";
import { createSubsystemLogger } from "../logging/subsystem.js";
import type { InlineCodeState } from "../markdown/code-spans.js";

View File

@@ -3,7 +3,10 @@ import { AcpRuntimeError } from "../../acp/runtime/errors.js";
import type { OpenClawConfig } from "../../config/config.js";
import type { SessionBindingRecord } from "../../infra/outbound/session-binding-service.js";
import { setActivePluginRegistry } from "../../plugins/runtime.js";
import { createChannelTestPluginBase, createTestRegistry } from "../../test-utils/channel-plugins.js";
import {
createChannelTestPluginBase,
createTestRegistry,
} from "../../test-utils/channel-plugins.js";
import { INTERNAL_MESSAGE_CHANNEL } from "../../utils/message-channel.js";
const hoisted = vi.hoisted(() => {
@@ -123,7 +126,9 @@ function parseTelegramChatIdForTest(raw?: string | null): string | undefined {
return (topicMatch?.[1] ?? trimmed).trim() || undefined;
}
function parseDiscordConversationIdForTest(targets: Array<string | undefined | null>): string | undefined {
function parseDiscordConversationIdForTest(
targets: Array<string | undefined | null>,
): string | undefined {
for (const rawTarget of targets) {
const target = rawTarget?.trim();
if (!target) {

View File

@@ -1,6 +1,4 @@
import { beforeEach, describe, expect, it } from "vitest";
import { setActivePluginRegistry } from "../../../plugins/runtime.js";
import { createChannelTestPluginBase, createTestRegistry } from "../../../test-utils/channel-plugins.js";
import type { OpenClawConfig } from "../../../config/config.js";
import {
__testing as sessionBindingTesting,
@@ -8,6 +6,11 @@ import {
registerSessionBindingAdapter,
type SessionBindingRecord,
} from "../../../infra/outbound/session-binding-service.js";
import { setActivePluginRegistry } from "../../../plugins/runtime.js";
import {
createChannelTestPluginBase,
createTestRegistry,
} from "../../../test-utils/channel-plugins.js";
import { buildCommandTestParams } from "../commands-spawn.test-harness.js";
import {
resolveAcpCommandBindingContext,
@@ -28,7 +31,9 @@ function parseTelegramChatIdForTest(raw?: string | null): string | undefined {
return (topicMatch?.[1] ?? trimmed).trim() || undefined;
}
function parseDiscordConversationIdForTest(targets: Array<string | undefined | null>): string | undefined {
function parseDiscordConversationIdForTest(
targets: Array<string | undefined | null>,
): string | undefined {
for (const rawTarget of targets) {
const target = rawTarget?.trim();
if (!target) {
@@ -263,8 +268,7 @@ function setMinimalAcpContextRegistryForTests(): void {
});
return {
conversationId:
senderScopedConversationId ??
`${parentConversationId}:topic:${threadId}`,
senderScopedConversationId ?? `${parentConversationId}:topic:${threadId}`,
parentConversationId,
};
}

View File

@@ -2,12 +2,12 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { telegramCommandTestPlugin } from "../../../extensions/telegram/test-support.js";
import type { ChannelPlugin } from "../../channels/plugins/types.js";
import type { OpenClawConfig } from "../../config/config.js";
import { updateSessionStore, type SessionEntry } from "../../config/sessions.js";
import { setActivePluginRegistry } from "../../plugins/runtime.js";
import { loadBundledPluginPublicSurfaceSync } from "../../test-utils/bundled-plugin-public-surface.js";
import { telegramCommandTestPlugin } from "../../../extensions/telegram/test-support.js";
import { createTestRegistry } from "../../test-utils/channel-plugins.js";
import { typedCases } from "../../test-utils/typed-cases.js";
import { INTERNAL_MESSAGE_CHANNEL } from "../../utils/message-channel.js";

View File

@@ -36,7 +36,10 @@ function parseChoice(raw: string, options?: { allowStyle?: boolean }): SlackChoi
// values that need to end with one of these tokens must use a different suffix.
const styleDelimiter = value.lastIndexOf(":");
if (styleDelimiter !== -1) {
const maybeStyle = value.slice(styleDelimiter + 1).trim().toLowerCase();
const maybeStyle = value
.slice(styleDelimiter + 1)
.trim()
.toLowerCase();
if (
maybeStyle === "primary" ||
maybeStyle === "secondary" ||
@@ -54,7 +57,11 @@ function parseChoice(raw: string, options?: { allowStyle?: boolean }): SlackChoi
return style ? { label, value, style } : { label, value };
}
function parseChoices(raw: string, maxItems: number, options?: { allowStyle?: boolean }): SlackChoice[] {
function parseChoices(
raw: string,
maxItems: number,
options?: { allowStyle?: boolean },
): SlackChoice[] {
return raw
.split(",")
.map((entry) => parseChoice(entry, options))

View File

@@ -1,7 +1,5 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { ChannelPluginCatalogEntry } from "../channels/plugins/catalog.js";
import { getChannelSetupWizardAdapter } from "./channel-setup/registry.js";
import type { ChannelSetupWizardAdapter } from "./channel-setup/types.js";
import type { OpenClawConfig } from "../config/config.js";
import { createEmptyPluginRegistry } from "../plugins/registry.js";
import { setActivePluginRegistry } from "../plugins/runtime.js";
@@ -12,6 +10,8 @@ import {
loadChannelSetupPluginRegistrySnapshotForChannel,
reloadChannelSetupPluginRegistry,
} from "./channel-setup/plugin-install.js";
import { getChannelSetupWizardAdapter } from "./channel-setup/registry.js";
import type { ChannelSetupWizardAdapter } from "./channel-setup/types.js";
import { setupChannels } from "./onboard-channels.js";
import { createExitThrowingRuntime, createWizardPrompter } from "./test-wizard-helpers.js";
@@ -125,7 +125,13 @@ function setMinimalOnboardingRegistryForTests(): void {
capabilities: { chatTypes: ["direct", "group"] },
}),
setup: {
applyAccountConfig: ({ cfg, input }: { cfg: OpenClawConfig; input: { token?: string } }) =>
applyAccountConfig: ({
cfg,
input,
}: {
cfg: OpenClawConfig;
input: { token?: string };
}) =>
({
...cfg,
channels: {

View File

@@ -1,10 +1,10 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { getChannelSetupWizardAdapter } from "./channel-setup/registry.js";
import type { ChannelSetupWizardAdapter } from "./channel-setup/types.js";
import type { OpenClawConfig } from "../config/config.js";
import { setActivePluginRegistry } from "../plugins/runtime.js";
import { createChannelTestPluginBase, createTestRegistry } from "../test-utils/channel-plugins.js";
import type { OpenClawConfig } from "../config/config.js";
import type { WizardPrompter } from "../wizard/prompts.js";
import { getChannelSetupWizardAdapter } from "./channel-setup/registry.js";
import type { ChannelSetupWizardAdapter } from "./channel-setup/types.js";
import {
createChannelOnboardingPostWriteHookCollector,
runCollectedChannelOnboardingPostWriteHooks,
@@ -62,9 +62,7 @@ type PatchedSetupAdapterFields = {
getStatus?: ChannelSetupWizardAdapter["getStatus"];
};
function patchChannelOnboardingAdapterForTest(
patch: ChannelSetupWizardAdapterPatch,
): () => void {
function patchChannelOnboardingAdapterForTest(patch: ChannelSetupWizardAdapterPatch): () => void {
const adapter = getChannelSetupWizardAdapter("telegram");
if (!adapter) {
throw new Error("missing setup adapter for telegram");

View File

@@ -16,12 +16,7 @@ export const formatDuration = (ms: number | null | undefined) => {
export const formatTokensCompact = (
sess: Pick<
SessionStatus,
| "inputTokens"
| "totalTokens"
| "contextTokens"
| "percentUsed"
| "cacheRead"
| "cacheWrite"
"inputTokens" | "totalTokens" | "contextTokens" | "percentUsed" | "cacheRead" | "cacheWrite"
>,
) => {
const used = sess.totalTokens;

View File

@@ -1,7 +1,6 @@
import { randomUUID } from "node:crypto";
import { resolveDefaultAgentId } from "../agents/agent-scope.js";
import type { ModelCatalogEntry } from "../agents/model-catalog.js";
import { normalizeExecTarget } from "../infra/exec-approvals.js";
import {
resolveAllowedModelRef,
resolveDefaultModelForAgent,
@@ -20,6 +19,7 @@ import {
} from "../auto-reply/thinking.js";
import type { OpenClawConfig } from "../config/config.js";
import type { SessionEntry } from "../config/sessions.js";
import { normalizeExecTarget } from "../infra/exec-approvals.js";
import {
isAcpSessionKey,
isSubagentSessionKey,

View File

@@ -1,6 +1,5 @@
import type { ChannelPlugin } from "../../channels/plugins/types.js";
import type { OpenClawConfig } from "../../config/config.js";
import { setActivePluginRegistry } from "../../plugins/runtime.js";
import {
buildChannelOutboundSessionRoute,
stripChannelTargetPrefix,
@@ -13,12 +12,18 @@ import {
resolveThreadSessionKeys,
type RoutePeer,
} from "../../plugin-sdk/routing.js";
import { createChannelTestPluginBase, createTestRegistry } from "../../test-utils/channel-plugins.js";
import { setActivePluginRegistry } from "../../plugins/runtime.js";
import {
createChannelTestPluginBase,
createTestRegistry,
} from "../../test-utils/channel-plugins.js";
function createSessionRouteTestPlugin(params: {
id: ChannelPlugin["id"];
label: string;
resolveOutboundSessionRoute: (params: ChannelOutboundSessionRouteParams) => Awaited<
resolveOutboundSessionRoute: (
params: ChannelOutboundSessionRouteParams,
) => Awaited<
ReturnType<NonNullable<NonNullable<ChannelPlugin["messaging"]>["resolveOutboundSessionRoute"]>>
>;
}): ChannelPlugin {
@@ -95,9 +100,7 @@ function parseTelegramTargetForTest(raw: string): {
};
}
function parseTelegramThreadIdForTest(
threadId?: string | number | null,
): number | undefined {
function parseTelegramThreadIdForTest(threadId?: string | number | null): number | undefined {
const normalized = normalizeOutboundThreadId(threadId);
if (!normalized) {
return undefined;
@@ -119,15 +122,16 @@ function resolveTelegramOutboundSessionRouteForTest(params: ChannelOutboundSessi
if (!chatId) {
return null;
}
const resolvedThreadId =
parsed.messageThreadId ?? parseTelegramThreadIdForTest(params.threadId);
const resolvedThreadId = parsed.messageThreadId ?? parseTelegramThreadIdForTest(params.threadId);
const isGroup =
parsed.chatType === "group" ||
(parsed.chatType === "unknown" &&
params.resolvedTarget?.kind !== undefined &&
params.resolvedTarget.kind !== "user");
const peerId =
isGroup && resolvedThreadId ? buildTelegramGroupPeerIdForTest(chatId, resolvedThreadId) : chatId;
isGroup && resolvedThreadId
? buildTelegramGroupPeerIdForTest(chatId, resolvedThreadId)
: chatId;
const peer: RoutePeer = {
kind: isGroup ? "group" : "direct",
id: peerId,
@@ -356,7 +360,9 @@ function resolveFeishuOutboundSessionRouteForTest(params: ChannelOutboundSession
});
}
function resolveNextcloudTalkOutboundSessionRouteForTest(params: ChannelOutboundSessionRouteParams) {
function resolveNextcloudTalkOutboundSessionRouteForTest(
params: ChannelOutboundSessionRouteParams,
) {
const roomId = stripTargetKindPrefix(
stripChannelTargetPrefix(params.target, "nextcloud-talk", "nc-talk", "nc"),
);

View File

@@ -1,7 +1,7 @@
import { beforeEach, describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../../config/config.js";
import { setMinimalOutboundSessionPluginRegistryForTests } from "./outbound-session.test-helpers.js";
import { resolveOutboundSessionRoute } from "./outbound-session.js";
import { setMinimalOutboundSessionPluginRegistryForTests } from "./outbound-session.test-helpers.js";
describe("resolveOutboundSessionRoute", () => {
beforeEach(() => {