fix(line): narrow plugin-sdk seams after refactor

This commit is contained in:
Vincent Koc
2026-03-22 19:44:13 -07:00
parent a9f4cb7544
commit ac7b7f5536
7 changed files with 32 additions and 21 deletions

View File

@@ -1,10 +1,11 @@
import { type OpenClawConfig, tryReadSecretFileSync } from "openclaw/plugin-sdk/core";
import {
DEFAULT_ACCOUNT_ID,
normalizeAccountId as normalizeSharedAccountId,
normalizeOptionalAccountId,
} from "openclaw/plugin-sdk/account-id";
import type { OpenClawConfig } from "openclaw/plugin-sdk/account-resolution";
import { resolveAccountEntry } from "openclaw/plugin-sdk/account-resolution";
import { tryReadSecretFileSync } from "../../../src/infra/secret-file.js";
import type {
LineAccountConfig,
LineConfig,

View File

@@ -5,11 +5,15 @@ import type { LineAccountConfig } from "./types.js";
// Avoid pulling in globals/pairing/media dependencies; this suite only asserts
// allowlist/groupPolicy gating and message-context wiring.
vi.mock("openclaw/plugin-sdk/runtime-env", () => ({
danger: (text: string) => text,
logVerbose: () => {},
shouldLogVerbose: () => false,
}));
vi.mock("openclaw/plugin-sdk/runtime-env", async (importOriginal) => {
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/runtime-env")>();
return {
...actual,
danger: (text: string) => text,
logVerbose: () => {},
shouldLogVerbose: () => false,
};
});
const { readAllowFromStoreMock, upsertPairingRequestMock } = vi.hoisted(() => ({
readAllowFromStoreMock: vi.fn(async () => [] as string[]),
@@ -700,10 +704,7 @@ describe("handleLineWebhookEvents", () => {
it("records unmentioned group messages as pending history", async () => {
const processMessage = vi.fn();
const groupHistories = new Map<
string,
HistoryEntry[]
>();
const groupHistories = new Map<string, HistoryEntry[]>();
const event = createTestMessageEvent({
message: { id: "m-hist-1", type: "text", text: "hello history", quoteToken: "q-hist-1" },
timestamp: 1700000000000,

View File

@@ -1,5 +1,5 @@
import { buildChannelConfigSchema } from "openclaw/plugin-sdk/channel-config-schema";
import { z } from "zod";
import { buildChannelConfigSchema } from "openclaw/plugin-sdk/core";
const DmPolicySchema = z.enum(["open", "allowlist", "pairing", "disabled"]);
const GroupPolicySchema = z.enum(["open", "allowlist", "disabled"]);

View File

@@ -1,5 +1,5 @@
import type { OpenClawConfig } from "openclaw/plugin-sdk/core";
import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
import type { OpenClawConfig } from "openclaw/plugin-sdk/account-resolution";
import { resolveAccountEntry } from "openclaw/plugin-sdk/account-resolution";
import type { LineConfig, LineGroupConfig } from "./types.js";

View File

@@ -1,6 +1,7 @@
import type { messagingApi } from "@line/bot-sdk";
import { stripMarkdown } from "openclaw/plugin-sdk/text-runtime";
import { createReceiptCard, toFlexMessage, type FlexBubble } from "./flex-templates.js";
export { stripMarkdown } from "openclaw/plugin-sdk/text-runtime";
type FlexMessage = messagingApi.FlexMessage;
type FlexComponent = messagingApi.FlexComponent;

View File

@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";
import { beforeEach, describe, expect, it, vi } from "vitest";
const { createLineBotMock, registerPluginHttpRouteMock, unregisterHttpMock } = vi.hoisted(() => ({
createLineBotMock: vi.fn(() => ({
@@ -20,11 +20,15 @@ vi.mock("openclaw/plugin-sdk/reply-runtime", () => ({
dispatchReplyWithBufferedBlockDispatcher: vi.fn(),
}));
vi.mock("openclaw/plugin-sdk/runtime-env", () => ({
danger: (value: unknown) => String(value),
logVerbose: vi.fn(),
waitForAbortSignal: vi.fn(),
}));
vi.mock("openclaw/plugin-sdk/runtime-env", async (importOriginal) => {
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/runtime-env")>();
return {
...actual,
danger: (value: unknown) => String(value),
logVerbose: vi.fn(),
waitForAbortSignal: vi.fn(),
};
});
vi.mock("openclaw/plugin-sdk/channel-reply-pipeline", () => ({
createChannelReplyPipeline: vi.fn(() => ({})),

View File

@@ -63,9 +63,13 @@ vi.mock("openclaw/plugin-sdk/infra-runtime", () => ({
recordChannelActivity: recordChannelActivityMock,
}));
vi.mock("openclaw/plugin-sdk/runtime-env", () => ({
logVerbose: logVerboseMock,
}));
vi.mock("openclaw/plugin-sdk/runtime-env", async (importOriginal) => {
const actual = await importOriginal<typeof import("openclaw/plugin-sdk/runtime-env")>();
return {
...actual,
logVerbose: logVerboseMock,
};
});
let sendModule: typeof import("./send.js");