fix: Failing tests due to import sorting.
This commit is contained in:
@@ -368,10 +368,10 @@ sender as `Member (PK:System)` to avoid accidental Discord pings.
|
|||||||
discord: {
|
discord: {
|
||||||
pluralkit: {
|
pluralkit: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
token: "pk_live_..." // optional; required for private systems
|
token: "pk_live_...", // optional; required for private systems
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,12 @@ const normalizeText = (value?: string) =>
|
|||||||
.replace(/\r/g, "\n")
|
.replace(/\r/g, "\n")
|
||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
|
const normalizePathEntries = (value?: string) =>
|
||||||
|
normalizeText(value)
|
||||||
|
.split(/[:\s]+/)
|
||||||
|
.map((entry) => entry.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
describe("exec PATH login shell merge", () => {
|
describe("exec PATH login shell merge", () => {
|
||||||
const originalPath = process.env.PATH;
|
const originalPath = process.env.PATH;
|
||||||
|
|
||||||
@@ -74,9 +80,9 @@ describe("exec PATH login shell merge", () => {
|
|||||||
|
|
||||||
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
|
const tool = createExecTool({ host: "gateway", security: "full", ask: "off" });
|
||||||
const result = await tool.execute("call1", { command: "echo $PATH" });
|
const result = await tool.execute("call1", { command: "echo $PATH" });
|
||||||
const text = normalizeText(result.content.find((c) => c.type === "text")?.text);
|
const entries = normalizePathEntries(result.content.find((c) => c.type === "text")?.text);
|
||||||
|
|
||||||
expect(text).toBe("/custom/bin:/opt/bin:/usr/bin");
|
expect(entries).toEqual(["/custom/bin", "/opt/bin", "/usr/bin"]);
|
||||||
expect(shellPathMock).toHaveBeenCalledTimes(1);
|
expect(shellPathMock).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -96,9 +102,9 @@ describe("exec PATH login shell merge", () => {
|
|||||||
command: "echo $PATH",
|
command: "echo $PATH",
|
||||||
env: { PATH: "/explicit/bin" },
|
env: { PATH: "/explicit/bin" },
|
||||||
});
|
});
|
||||||
const text = normalizeText(result.content.find((c) => c.type === "text")?.text);
|
const entries = normalizePathEntries(result.content.find((c) => c.type === "text")?.text);
|
||||||
|
|
||||||
expect(text).toBe("/explicit/bin");
|
expect(entries).toEqual(["/explicit/bin"]);
|
||||||
expect(shellPathMock).not.toHaveBeenCalled();
|
expect(shellPathMock).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -33,32 +33,35 @@ import { handleSubagentsCommand } from "./commands-subagents.js";
|
|||||||
import { handleTtsCommands } from "./commands-tts.js";
|
import { handleTtsCommands } from "./commands-tts.js";
|
||||||
import { routeReply } from "./route-reply.js";
|
import { routeReply } from "./route-reply.js";
|
||||||
|
|
||||||
const HANDLERS: CommandHandler[] = [
|
let HANDLERS: CommandHandler[] | null = null;
|
||||||
// Plugin commands are processed first, before built-in commands
|
|
||||||
handlePluginCommand,
|
|
||||||
handleBashCommand,
|
|
||||||
handleActivationCommand,
|
|
||||||
handleSendPolicyCommand,
|
|
||||||
handleUsageCommand,
|
|
||||||
handleRestartCommand,
|
|
||||||
handleTtsCommands,
|
|
||||||
handleHelpCommand,
|
|
||||||
handleCommandsListCommand,
|
|
||||||
handleStatusCommand,
|
|
||||||
handleAllowlistCommand,
|
|
||||||
handleApproveCommand,
|
|
||||||
handleContextCommand,
|
|
||||||
handleWhoamiCommand,
|
|
||||||
handleSubagentsCommand,
|
|
||||||
handleConfigCommand,
|
|
||||||
handleDebugCommand,
|
|
||||||
handleModelsCommand,
|
|
||||||
handleStopCommand,
|
|
||||||
handleCompactCommand,
|
|
||||||
handleAbortTrigger,
|
|
||||||
];
|
|
||||||
|
|
||||||
export async function handleCommands(params: HandleCommandsParams): Promise<CommandHandlerResult> {
|
export async function handleCommands(params: HandleCommandsParams): Promise<CommandHandlerResult> {
|
||||||
|
if (HANDLERS === null) {
|
||||||
|
HANDLERS = [
|
||||||
|
// Plugin commands are processed first, before built-in commands
|
||||||
|
handlePluginCommand,
|
||||||
|
handleBashCommand,
|
||||||
|
handleActivationCommand,
|
||||||
|
handleSendPolicyCommand,
|
||||||
|
handleUsageCommand,
|
||||||
|
handleRestartCommand,
|
||||||
|
handleTtsCommands,
|
||||||
|
handleHelpCommand,
|
||||||
|
handleCommandsListCommand,
|
||||||
|
handleStatusCommand,
|
||||||
|
handleAllowlistCommand,
|
||||||
|
handleApproveCommand,
|
||||||
|
handleContextCommand,
|
||||||
|
handleWhoamiCommand,
|
||||||
|
handleSubagentsCommand,
|
||||||
|
handleConfigCommand,
|
||||||
|
handleDebugCommand,
|
||||||
|
handleModelsCommand,
|
||||||
|
handleStopCommand,
|
||||||
|
handleCompactCommand,
|
||||||
|
handleAbortTrigger,
|
||||||
|
];
|
||||||
|
}
|
||||||
const resetMatch = params.command.commandBodyNormalized.match(/^\/(new|reset)(?:\s|$)/);
|
const resetMatch = params.command.commandBodyNormalized.match(/^\/(new|reset)(?:\s|$)/);
|
||||||
const resetRequested = Boolean(resetMatch);
|
const resetRequested = Boolean(resetMatch);
|
||||||
if (resetRequested && !params.command.isAuthorizedSender) {
|
if (resetRequested && !params.command.isAuthorizedSender) {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { DiscordPluralKitConfig } from "../discord/pluralkit.js";
|
||||||
import type {
|
import type {
|
||||||
BlockStreamingCoalesceConfig,
|
BlockStreamingCoalesceConfig,
|
||||||
DmPolicy,
|
DmPolicy,
|
||||||
@@ -6,7 +7,6 @@ import type {
|
|||||||
OutboundRetryConfig,
|
OutboundRetryConfig,
|
||||||
ReplyToMode,
|
ReplyToMode,
|
||||||
} from "./types.base.js";
|
} from "./types.base.js";
|
||||||
import type { DiscordPluralKitConfig } from "../discord/pluralkit.js";
|
|
||||||
import type { ChannelHeartbeatVisibilityConfig } from "./types.channels.js";
|
import type { ChannelHeartbeatVisibilityConfig } from "./types.channels.js";
|
||||||
import type { DmConfig, ProviderCommandsConfig } from "./types.messages.js";
|
import type { DmConfig, ProviderCommandsConfig } from "./types.messages.js";
|
||||||
import type { GroupToolPolicyBySenderConfig, GroupToolPolicyConfig } from "./types.tools.js";
|
import type { GroupToolPolicyBySenderConfig, GroupToolPolicyConfig } from "./types.tools.js";
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ describe("discord processDiscordMessage inbound contract", () => {
|
|||||||
historyLimit: 0,
|
historyLimit: 0,
|
||||||
mediaMaxBytes: 1024,
|
mediaMaxBytes: 1024,
|
||||||
textLimit: 4000,
|
textLimit: 4000,
|
||||||
|
sender: { label: "user" },
|
||||||
replyToMode: "off",
|
replyToMode: "off",
|
||||||
ackReactionScope: "direct",
|
ackReactionScope: "direct",
|
||||||
groupPolicy: "open",
|
groupPolicy: "open",
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
import { ChannelType, MessageType, type User } from "@buape/carbon";
|
import { ChannelType, MessageType, type User } from "@buape/carbon";
|
||||||
|
import type {
|
||||||
|
DiscordMessagePreflightContext,
|
||||||
|
DiscordMessagePreflightParams,
|
||||||
|
} from "./message-handler.preflight.types.js";
|
||||||
import { hasControlCommand } from "../../auto-reply/command-detection.js";
|
import { hasControlCommand } from "../../auto-reply/command-detection.js";
|
||||||
import { shouldHandleTextCommands } from "../../auto-reply/commands-registry.js";
|
import { shouldHandleTextCommands } from "../../auto-reply/commands-registry.js";
|
||||||
import {
|
import {
|
||||||
@@ -43,10 +46,6 @@ import {
|
|||||||
resolveDiscordSystemLocation,
|
resolveDiscordSystemLocation,
|
||||||
resolveTimestampMs,
|
resolveTimestampMs,
|
||||||
} from "./format.js";
|
} from "./format.js";
|
||||||
import type {
|
|
||||||
DiscordMessagePreflightContext,
|
|
||||||
DiscordMessagePreflightParams,
|
|
||||||
} from "./message-handler.preflight.types.js";
|
|
||||||
import { resolveDiscordChannelInfo, resolveDiscordMessageText } from "./message-utils.js";
|
import { resolveDiscordChannelInfo, resolveDiscordMessageText } from "./message-utils.js";
|
||||||
import { resolveDiscordSenderIdentity, resolveDiscordWebhookId } from "./sender-identity.js";
|
import { resolveDiscordSenderIdentity, resolveDiscordWebhookId } from "./sender-identity.js";
|
||||||
import { resolveDiscordSystemEvent } from "./system-events.js";
|
import { resolveDiscordSystemEvent } from "./system-events.js";
|
||||||
@@ -55,7 +54,6 @@ import { resolveDiscordThreadChannel, resolveDiscordThreadParentInfo } from "./t
|
|||||||
export type {
|
export type {
|
||||||
DiscordMessagePreflightContext,
|
DiscordMessagePreflightContext,
|
||||||
DiscordMessagePreflightParams,
|
DiscordMessagePreflightParams,
|
||||||
DiscordSenderIdentity,
|
|
||||||
} from "./message-handler.preflight.types.js";
|
} from "./message-handler.preflight.types.js";
|
||||||
|
|
||||||
export async function preflightDiscordMessage(
|
export async function preflightDiscordMessage(
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ vi.mock("../../auto-reply/reply/reply-dispatcher.js", () => ({
|
|||||||
})),
|
})),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
import { processDiscordMessage } from "./message-handler.process.js";
|
const { processDiscordMessage } = await import("./message-handler.process.js");
|
||||||
|
|
||||||
async function createBaseContext(overrides: Record<string, unknown> = {}) {
|
async function createBaseContext(overrides: Record<string, unknown> = {}) {
|
||||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-discord-"));
|
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-discord-"));
|
||||||
@@ -102,6 +102,7 @@ describe("processDiscordMessage ack reactions", () => {
|
|||||||
const ctx = await createBaseContext({
|
const ctx = await createBaseContext({
|
||||||
shouldRequireMention: false,
|
shouldRequireMention: false,
|
||||||
effectiveWasMentioned: false,
|
effectiveWasMentioned: false,
|
||||||
|
sender: { label: "user" },
|
||||||
});
|
});
|
||||||
|
|
||||||
await processDiscordMessage(ctx as any);
|
await processDiscordMessage(ctx as any);
|
||||||
@@ -113,6 +114,7 @@ describe("processDiscordMessage ack reactions", () => {
|
|||||||
const ctx = await createBaseContext({
|
const ctx = await createBaseContext({
|
||||||
shouldRequireMention: true,
|
shouldRequireMention: true,
|
||||||
effectiveWasMentioned: true,
|
effectiveWasMentioned: true,
|
||||||
|
sender: { label: "user" },
|
||||||
});
|
});
|
||||||
|
|
||||||
await processDiscordMessage(ctx as any);
|
await processDiscordMessage(ctx as any);
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ import {
|
|||||||
resolveDiscordGuildEntry,
|
resolveDiscordGuildEntry,
|
||||||
resolveDiscordUserAllowed,
|
resolveDiscordUserAllowed,
|
||||||
} from "./allow-list.js";
|
} from "./allow-list.js";
|
||||||
import { resolveDiscordSenderIdentity } from "./sender-identity.js";
|
|
||||||
import { resolveDiscordChannelInfo } from "./message-utils.js";
|
import { resolveDiscordChannelInfo } from "./message-utils.js";
|
||||||
|
import { resolveDiscordSenderIdentity } from "./sender-identity.js";
|
||||||
import { resolveDiscordThreadParentInfo } from "./threading.js";
|
import { resolveDiscordThreadParentInfo } from "./threading.js";
|
||||||
|
|
||||||
type DiscordConfig = NonNullable<OpenClawConfig["channels"]>["discord"];
|
type DiscordConfig = NonNullable<OpenClawConfig["channels"]>["discord"];
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import type { User } from "@buape/carbon";
|
import type { User } from "@buape/carbon";
|
||||||
|
|
||||||
import { formatDiscordUserTag } from "./format.js";
|
|
||||||
import type { DiscordMessageEvent } from "./listeners.js";
|
|
||||||
import type { PluralKitMessageInfo } from "../pluralkit.js";
|
import type { PluralKitMessageInfo } from "../pluralkit.js";
|
||||||
|
import { formatDiscordUserTag } from "./format.js";
|
||||||
|
|
||||||
export type DiscordSenderIdentity = {
|
export type DiscordSenderIdentity = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -30,7 +28,7 @@ export function resolveDiscordWebhookId(message: DiscordWebhookMessageLike): str
|
|||||||
|
|
||||||
export function resolveDiscordSenderIdentity(params: {
|
export function resolveDiscordSenderIdentity(params: {
|
||||||
author: User;
|
author: User;
|
||||||
member?: DiscordMessageEvent["member"] | null;
|
member?: any;
|
||||||
pluralkitInfo?: PluralKitMessageInfo | null;
|
pluralkitInfo?: PluralKitMessageInfo | null;
|
||||||
}): DiscordSenderIdentity {
|
}): DiscordSenderIdentity {
|
||||||
const pkInfo = params.pluralkitInfo ?? null;
|
const pkInfo = params.pluralkitInfo ?? null;
|
||||||
@@ -75,7 +73,7 @@ export function resolveDiscordSenderIdentity(params: {
|
|||||||
|
|
||||||
export function resolveDiscordSenderLabel(params: {
|
export function resolveDiscordSenderLabel(params: {
|
||||||
author: User;
|
author: User;
|
||||||
member?: DiscordMessageEvent["member"] | null;
|
member?: any;
|
||||||
pluralkitInfo?: PluralKitMessageInfo | null;
|
pluralkitInfo?: PluralKitMessageInfo | null;
|
||||||
}): string {
|
}): string {
|
||||||
return resolveDiscordSenderIdentity(params).label;
|
return resolveDiscordSenderIdentity(params).label;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { resetInboundDedupe } from "../auto-reply/reply/inbound-dedupe.js";
|
import { resetInboundDedupe } from "../auto-reply/reply/inbound-dedupe.js";
|
||||||
import { monitorSlackProvider } from "./monitor.js";
|
|
||||||
|
const { monitorSlackProvider } = await import("./monitor.js");
|
||||||
|
|
||||||
const sendMock = vi.fn();
|
const sendMock = vi.fn();
|
||||||
const replyMock = vi.fn();
|
const replyMock = vi.fn();
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { resetInboundDedupe } from "../auto-reply/reply/inbound-dedupe.js";
|
import { resetInboundDedupe } from "../auto-reply/reply/inbound-dedupe.js";
|
||||||
import { monitorSlackProvider } from "./monitor.js";
|
|
||||||
import {
|
import {
|
||||||
defaultSlackTestConfig,
|
defaultSlackTestConfig,
|
||||||
flush,
|
flush,
|
||||||
@@ -11,6 +10,8 @@ import {
|
|||||||
waitForSlackEvent,
|
waitForSlackEvent,
|
||||||
} from "./monitor.test-helpers.js";
|
} from "./monitor.test-helpers.js";
|
||||||
|
|
||||||
|
const { monitorSlackProvider } = await import("./monitor.js");
|
||||||
|
|
||||||
const slackTestState = getSlackTestState();
|
const slackTestState = getSlackTestState();
|
||||||
const { sendMock, replyMock, reactMock, upsertPairingRequestMock } = slackTestState;
|
const { sendMock, replyMock, reactMock, upsertPairingRequestMock } = slackTestState;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
|||||||
import { HISTORY_CONTEXT_MARKER } from "../auto-reply/reply/history.js";
|
import { HISTORY_CONTEXT_MARKER } from "../auto-reply/reply/history.js";
|
||||||
import { resetInboundDedupe } from "../auto-reply/reply/inbound-dedupe.js";
|
import { resetInboundDedupe } from "../auto-reply/reply/inbound-dedupe.js";
|
||||||
import { CURRENT_MESSAGE_MARKER } from "../auto-reply/reply/mentions.js";
|
import { CURRENT_MESSAGE_MARKER } from "../auto-reply/reply/mentions.js";
|
||||||
import { monitorSlackProvider } from "./monitor.js";
|
|
||||||
import {
|
import {
|
||||||
defaultSlackTestConfig,
|
defaultSlackTestConfig,
|
||||||
flush,
|
flush,
|
||||||
@@ -13,6 +12,8 @@ import {
|
|||||||
waitForSlackEvent,
|
waitForSlackEvent,
|
||||||
} from "./monitor.test-helpers.js";
|
} from "./monitor.test-helpers.js";
|
||||||
|
|
||||||
|
const { monitorSlackProvider } = await import("./monitor.js");
|
||||||
|
|
||||||
const slackTestState = getSlackTestState();
|
const slackTestState = getSlackTestState();
|
||||||
const { sendMock, replyMock } = slackTestState;
|
const { sendMock, replyMock } = slackTestState;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { beforeEach, describe, expect, it } from "vitest";
|
import { beforeEach, describe, expect, it } from "vitest";
|
||||||
import { resetInboundDedupe } from "../auto-reply/reply/inbound-dedupe.js";
|
import { resetInboundDedupe } from "../auto-reply/reply/inbound-dedupe.js";
|
||||||
import { monitorSlackProvider } from "./monitor.js";
|
|
||||||
import {
|
import {
|
||||||
defaultSlackTestConfig,
|
defaultSlackTestConfig,
|
||||||
flush,
|
flush,
|
||||||
@@ -11,6 +10,8 @@ import {
|
|||||||
waitForSlackEvent,
|
waitForSlackEvent,
|
||||||
} from "./monitor.test-helpers.js";
|
} from "./monitor.test-helpers.js";
|
||||||
|
|
||||||
|
const { monitorSlackProvider } = await import("./monitor.js");
|
||||||
|
|
||||||
const slackTestState = getSlackTestState();
|
const slackTestState = getSlackTestState();
|
||||||
const { sendMock, replyMock } = slackTestState;
|
const { sendMock, replyMock } = slackTestState;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user