mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
fix(ci): restore Telegram and SDK guard checks (#99355)
This commit is contained in:
@@ -1,29 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildInboundUserContextPrefix } from "../../../src/auto-reply/reply/inbound-meta.js";
|
||||
import { buildReplyPromptEnvelopeBase } from "../../../src/auto-reply/reply/prompt-prelude.js";
|
||||
import { buildTelegramMessageContextForTest } from "./bot-message-context.test-harness.js";
|
||||
import type { TelegramPromptContextEntry } from "./bot-message-context.types.js";
|
||||
|
||||
type RoomEventPromptContext = Parameters<typeof buildInboundUserContextPrefix>[0] &
|
||||
Parameters<typeof buildReplyPromptEnvelopeBase>[0]["ctx"];
|
||||
|
||||
function renderRoomEventPromptText(ctx: RoomEventPromptContext): string {
|
||||
const inboundUserContext = buildInboundUserContextPrefix(ctx);
|
||||
return (
|
||||
buildReplyPromptEnvelopeBase({
|
||||
ctx,
|
||||
sessionCtx: ctx,
|
||||
baseBody: ctx.BodyForAgent ?? ctx.Body ?? ctx.RawBody ?? "",
|
||||
hasUserBody: true,
|
||||
inboundUserContext,
|
||||
isBareSessionReset: false,
|
||||
startupAction: "new",
|
||||
inboundEventKind: "room_event",
|
||||
sourceReplyDeliveryMode: "message_tool_only",
|
||||
}).currentInboundContext?.text ?? ""
|
||||
);
|
||||
}
|
||||
|
||||
const telegramChatWindowContext: TelegramPromptContextEntry = {
|
||||
label: "Conversation context",
|
||||
source: "telegram",
|
||||
@@ -228,6 +206,49 @@ describe("buildTelegramMessageContext prompt context", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("applies the ambient watermark before truncating the history window", async () => {
|
||||
const ctx = await buildTelegramMessageContextForTest({
|
||||
message: {
|
||||
message_id: 13,
|
||||
chat: { id: -1001234567890, type: "supergroup", title: "Forum" },
|
||||
from: { id: 1234, first_name: "Pat" },
|
||||
text: "@bot what happened?",
|
||||
entities: [{ type: "mention", offset: 0, length: 4 }],
|
||||
},
|
||||
historyLimit: 1,
|
||||
groupHistories: new Map([
|
||||
[
|
||||
"-1001234567890",
|
||||
[
|
||||
{
|
||||
messageId: "12",
|
||||
sender: "Mira",
|
||||
timestamp: 1_700_000_002_000,
|
||||
body: "unpersisted gap",
|
||||
},
|
||||
{
|
||||
messageId: "11",
|
||||
sender: "Lee",
|
||||
timestamp: 1_700_000_001_000,
|
||||
body: "late persisted ambient",
|
||||
},
|
||||
],
|
||||
],
|
||||
]),
|
||||
sessionRuntime: {
|
||||
readAmbientTranscriptWatermark: () => ({
|
||||
messageId: "11",
|
||||
timestampMs: 1_700_000_001_000,
|
||||
updatedAt: 1_700_000_003_000,
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
expect(ctx?.ctxPayload.InboundHistory).toEqual([
|
||||
expect.objectContaining({ messageId: "12", body: "unpersisted gap" }),
|
||||
]);
|
||||
});
|
||||
|
||||
it("omits transcript-owned ambient rows from steady-state room-event prompt text", async () => {
|
||||
const ctx = await buildTelegramMessageContextForTest({
|
||||
message: {
|
||||
@@ -276,11 +297,13 @@ describe("buildTelegramMessageContext prompt context", () => {
|
||||
if (!ctx) {
|
||||
throw new Error("Expected room-event context");
|
||||
}
|
||||
const promptText = renderRoomEventPromptText(ctx.ctxPayload as RoomEventPromptContext);
|
||||
expect(promptText).toContain("[OpenClaw room event]");
|
||||
expect(promptText).toContain("Current event:\n#12 Pat: current ambient");
|
||||
expect(promptText).not.toContain("persisted ambient");
|
||||
expect(promptText).not.toContain("Chat history since last reply");
|
||||
expect(ctx.ctxPayload).toMatchObject({
|
||||
BodyForAgent: "current ambient",
|
||||
InboundEventKind: "room_event",
|
||||
MessageSid: "12",
|
||||
SenderName: "Pat",
|
||||
});
|
||||
expect(ctx.ctxPayload.InboundHistory).toBeUndefined();
|
||||
expect(ctx.ctxPayload.UntrustedStructuredContext).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ import type {
|
||||
} from "openclaw/plugin-sdk/config-contracts";
|
||||
import { resolveChannelContextVisibilityMode } from "openclaw/plugin-sdk/context-visibility-runtime";
|
||||
import { timestampMsToIsoString } from "openclaw/plugin-sdk/number-runtime";
|
||||
import type { HistoryEntry } from "openclaw/plugin-sdk/reply-history";
|
||||
import { createChannelHistoryWindow, type HistoryEntry } from "openclaw/plugin-sdk/reply-history";
|
||||
import type { ResolvedAgentRoute } from "openclaw/plugin-sdk/routing";
|
||||
import { logVerbose, shouldLogVerbose } from "openclaw/plugin-sdk/runtime-env";
|
||||
import { evaluateSupplementalContextVisibility } from "openclaw/plugin-sdk/security-runtime";
|
||||
@@ -447,7 +447,13 @@ export async function buildTelegramInboundContextPayload(params: {
|
||||
let watermarkedGroupHistoryEntries: HistoryEntry[] | undefined;
|
||||
let groupHistoryPromptEntries: HistoryEntry[] = [];
|
||||
if (hasGroupHistoryContext && historyKey && historyLimit > 0) {
|
||||
const fullGroupHistoryEntries = (groupHistories.get(historyKey) ?? [])
|
||||
const bufferedHistoryCount = groupHistories.get(historyKey)?.length ?? 0;
|
||||
const fullGroupHistoryEntries = (
|
||||
createChannelHistoryWindow({ historyMap: groupHistories }).buildInboundHistory({
|
||||
historyKey,
|
||||
limit: bufferedHistoryCount,
|
||||
}) ?? []
|
||||
)
|
||||
.filter((entry) =>
|
||||
isTelegramHistoryEntryAfterAmbientWatermark(entry, ambientTranscriptWatermark),
|
||||
)
|
||||
|
||||
@@ -7,8 +7,6 @@ import {
|
||||
} from "openclaw/plugin-sdk/plugin-state-test-runtime";
|
||||
import { setReplyPayloadMetadata } from "openclaw/plugin-sdk/reply-payload-testing";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { buildInboundUserContextPrefix } from "../../../src/auto-reply/reply/inbound-meta.js";
|
||||
import { buildReplyPromptEnvelopeBase } from "../../../src/auto-reply/reply/prompt-prelude.js";
|
||||
import { resolveAutoTopicLabelConfig as resolveAutoTopicLabelConfigRuntime } from "./auto-topic-label-config.js";
|
||||
import type { TelegramBotDeps } from "./bot-deps.js";
|
||||
import {
|
||||
@@ -28,8 +26,6 @@ import type { TelegramRuntime } from "./runtime.types.js";
|
||||
type DispatchReplyWithBufferedBlockDispatcherArgs = Parameters<
|
||||
TelegramBotDeps["dispatchReplyWithBufferedBlockDispatcher"]
|
||||
>[0];
|
||||
type RoomEventPromptContext = Parameters<typeof buildInboundUserContextPrefix>[0] &
|
||||
Parameters<typeof buildReplyPromptEnvelopeBase>[0]["ctx"];
|
||||
|
||||
const createTelegramDraftStream = vi.hoisted(() => vi.fn());
|
||||
const dispatchReplyWithBufferedBlockDispatcher = vi.hoisted(() =>
|
||||
@@ -427,23 +423,6 @@ describe("dispatchTelegramMessage draft streaming", () => {
|
||||
expect(preview.text).toBe(barText);
|
||||
}
|
||||
|
||||
function renderRoomEventPromptText(ctx: RoomEventPromptContext): string {
|
||||
const inboundUserContext = buildInboundUserContextPrefix(ctx);
|
||||
return (
|
||||
buildReplyPromptEnvelopeBase({
|
||||
ctx,
|
||||
sessionCtx: ctx,
|
||||
baseBody: ctx.BodyForAgent ?? ctx.Body ?? ctx.RawBody ?? "",
|
||||
hasUserBody: true,
|
||||
inboundUserContext,
|
||||
isBareSessionReset: false,
|
||||
startupAction: "new",
|
||||
inboundEventKind: "room_event",
|
||||
sourceReplyDeliveryMode: "message_tool_only",
|
||||
}).currentInboundContext?.text ?? ""
|
||||
);
|
||||
}
|
||||
|
||||
function createContext(overrides?: Partial<TelegramMessageContext>): TelegramMessageContext {
|
||||
const base = {
|
||||
ctxPayload: {},
|
||||
@@ -1275,12 +1254,14 @@ describe("dispatchTelegramMessage draft streaming", () => {
|
||||
const dispatchParams = mockCallArg(
|
||||
dispatchReplyWithBufferedBlockDispatcher,
|
||||
) as DispatchReplyWithBufferedBlockDispatcherArgs;
|
||||
const promptText = renderRoomEventPromptText(dispatchParams.ctx as RoomEventPromptContext);
|
||||
expect(promptText).toContain("[OpenClaw room event]");
|
||||
expect(promptText).toContain("Current event:\n#27787 Cara: ambient current");
|
||||
expect(promptText).not.toContain("persisted recovered ambient");
|
||||
expect(promptText).not.toContain("Chat history since last reply");
|
||||
expect(dispatchParams.ctx).toMatchObject({
|
||||
BodyForAgent: "ambient current",
|
||||
InboundEventKind: "room_event",
|
||||
MessageSid: "27787",
|
||||
SenderName: "Cara",
|
||||
});
|
||||
expect(dispatchParams.ctx.InboundHistory).toBeUndefined();
|
||||
expect(dispatchParams.ctx.UntrustedStructuredContext).toBeUndefined();
|
||||
});
|
||||
|
||||
it("moves recovered user-request history out of the original topic", async () => {
|
||||
|
||||
@@ -202,8 +202,8 @@ let publicDeprecatedExportsByEntrypointBudget;
|
||||
try {
|
||||
budgets = {
|
||||
publicEntrypoints: readBudgetEnv("OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_ENTRYPOINTS", 323),
|
||||
publicExports: readBudgetEnv("OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_EXPORTS", 10408),
|
||||
publicFunctionExports: readBudgetEnv("OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_FUNCTION_EXPORTS", 5224),
|
||||
publicExports: readBudgetEnv("OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_EXPORTS", 10412),
|
||||
publicFunctionExports: readBudgetEnv("OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_FUNCTION_EXPORTS", 5227),
|
||||
publicDeprecatedExports: readBudgetEnv(
|
||||
"OPENCLAW_PLUGIN_SDK_MAX_PUBLIC_DEPRECATED_EXPORTS",
|
||||
3261,
|
||||
|
||||
Reference in New Issue
Block a user