test: share messaging plugin fixtures

This commit is contained in:
Peter Steinberger
2026-04-20 20:52:16 +01:00
parent 553cc80027
commit aa0957c4dd
6 changed files with 59 additions and 102 deletions

View File

@@ -1,4 +1,5 @@
import { vi, type Mock } from "vitest";
import { finalizeTelegramInboundContextForTest } from "./bot-message-context.session-runtime-test-support.js";
type AsyncUnknownMock = Mock<(...args: unknown[]) => Promise<unknown>>;
type BuildTelegramMessageContextForTest =
@@ -13,27 +14,9 @@ const hoisted = vi.hoisted((): { recordInboundSessionMock: AsyncUnknownMock } =>
}));
export const recordInboundSessionMock: AsyncUnknownMock = hoisted.recordInboundSessionMock;
const finalizeInboundContextForTest = ((ctx) => {
const next = ctx as Record<string, unknown>;
const body = typeof next.Body === "string" ? next.Body : "";
next.Body = body;
next.BodyForAgent =
typeof next.BodyForAgent === "string"
? next.BodyForAgent
: typeof next.RawBody === "string"
? next.RawBody
: body;
next.BodyForCommands =
typeof next.BodyForCommands === "string"
? next.BodyForCommands
: typeof next.CommandBody === "string"
? next.CommandBody
: typeof next.RawBody === "string"
? next.RawBody
: body;
next.CommandAuthorized = Boolean(next.CommandAuthorized);
return next;
}) as NonNullable<TelegramTestSessionRuntime["finalizeInboundContext"]>;
const finalizeInboundContextForTest = finalizeTelegramInboundContextForTest as NonNullable<
TelegramTestSessionRuntime["finalizeInboundContext"]
>;
const recordInboundSessionForTest: NonNullable<
TelegramTestSessionRuntime["recordInboundSession"]
> = async (params) => {

View File

@@ -0,0 +1,21 @@
export function finalizeTelegramInboundContextForTest(ctx: unknown): Record<string, unknown> {
const next = ctx as Record<string, unknown>;
const body = typeof next.Body === "string" ? next.Body : "";
next.Body = body;
next.BodyForAgent =
typeof next.BodyForAgent === "string"
? next.BodyForAgent
: typeof next.RawBody === "string"
? next.RawBody
: body;
next.BodyForCommands =
typeof next.BodyForCommands === "string"
? next.BodyForCommands
: typeof next.CommandBody === "string"
? next.CommandBody
: typeof next.RawBody === "string"
? next.RawBody
: body;
next.CommandAuthorized = Boolean(next.CommandAuthorized);
return next;
}

View File

@@ -1,4 +1,5 @@
import type { BuildTelegramMessageContextParams, TelegramMediaRef } from "./bot-message-context.js";
import { finalizeTelegramInboundContextForTest } from "./bot-message-context.session-runtime-test-support.js";
export const baseTelegramMessageContextConfig = {
agents: { defaults: { model: "anthropic/claude-opus-4-5", workspace: "/tmp/openclaw" } },
@@ -7,27 +8,9 @@ export const baseTelegramMessageContextConfig = {
} as never;
type TelegramTestSessionRuntime = NonNullable<BuildTelegramMessageContextParams["sessionRuntime"]>;
const finalizeInboundContextForTest = ((ctx) => {
const next = ctx as Record<string, unknown>;
const body = typeof next.Body === "string" ? next.Body : "";
next.Body = body;
next.BodyForAgent =
typeof next.BodyForAgent === "string"
? next.BodyForAgent
: typeof next.RawBody === "string"
? next.RawBody
: body;
next.BodyForCommands =
typeof next.BodyForCommands === "string"
? next.BodyForCommands
: typeof next.CommandBody === "string"
? next.CommandBody
: typeof next.RawBody === "string"
? next.RawBody
: body;
next.CommandAuthorized = Boolean(next.CommandAuthorized);
return next;
}) as NonNullable<TelegramTestSessionRuntime["finalizeInboundContext"]>;
const finalizeInboundContextForTest = finalizeTelegramInboundContextForTest as NonNullable<
TelegramTestSessionRuntime["finalizeInboundContext"]
>;
type BuildTelegramMessageContextForTestParams = {
message: Record<string, unknown>;