chore: Fix types in tests 28/N.

This commit is contained in:
cpojer
2026-02-17 14:32:18 +09:00
parent 97c8f4999e
commit 03e6acd051
14 changed files with 104 additions and 55 deletions

View File

@@ -45,9 +45,10 @@ describe("signal createSignalEventHandler inbound contract", () => {
expect(capturedCtx).toBeTruthy();
expectInboundContextContract(capturedCtx!);
const contextWithBody = capturedCtx as unknown as { Body?: string };
// Sender should appear as prefix in group messages (no redundant [from:] suffix)
expect(String(capturedCtx?.Body ?? "")).toContain("Alice");
expect(String(capturedCtx?.Body ?? "")).toMatch(/Alice.*:/);
expect(String(capturedCtx?.Body ?? "")).not.toContain("[from:");
expect(String(contextWithBody.Body ?? "")).toContain("Alice");
expect(String(contextWithBody.Body ?? "")).toMatch(/Alice.*:/);
expect(String(contextWithBody.Body ?? "")).not.toContain("[from:");
});
});

View File

@@ -4,13 +4,17 @@ import type { MsgContext } from "../../auto-reply/templating.js";
import type { OpenClawConfig } from "../../config/types.js";
import { createBaseSignalEventHandlerDeps } from "./event-handler.test-harness.js";
type SignalMsgContext = MsgContext & {
type SignalMsgContext = Pick<MsgContext, "Body" | "WasMentioned"> & {
Body?: string;
WasMentioned?: boolean;
};
let capturedCtx: SignalMsgContext | undefined;
function getCapturedCtx() {
return capturedCtx as SignalMsgContext;
}
vi.mock("../../auto-reply/dispatch.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../../auto-reply/dispatch.js")>();
return buildDispatchInboundCaptureMock(actual, (ctx) => {
@@ -113,7 +117,7 @@ describe("signal mention gating", () => {
await handler(makeGroupEvent({ message: "hey @bot what's up" }));
expect(capturedCtx).toBeTruthy();
expect(capturedCtx?.WasMentioned).toBe(true);
expect(getCapturedCtx()?.WasMentioned).toBe(true);
});
it("sets WasMentioned=false for group messages without mention when requireMention is off", async () => {
@@ -126,7 +130,7 @@ describe("signal mention gating", () => {
await handler(makeGroupEvent({ message: "hello everyone" }));
expect(capturedCtx).toBeTruthy();
expect(capturedCtx?.WasMentioned).toBe(false);
expect(getCapturedCtx()?.WasMentioned).toBe(false);
});
it("records pending history for skipped group messages", async () => {
@@ -187,7 +191,7 @@ describe("signal mention gating", () => {
);
expect(capturedCtx).toBeTruthy();
const body = String(capturedCtx?.Body ?? "");
const body = String(getCapturedCtx()?.Body ?? "");
expect(body).toContain("@123e4567 hi @+15550002222");
expect(body).not.toContain(placeholder);
});
@@ -212,8 +216,8 @@ describe("signal mention gating", () => {
);
expect(capturedCtx).toBeTruthy();
expect(String(capturedCtx?.Body ?? "")).toContain("@123e4567");
expect(capturedCtx?.WasMentioned).toBe(true);
expect(String(getCapturedCtx()?.Body ?? "")).toContain("@123e4567");
expect(getCapturedCtx()?.WasMentioned).toBe(true);
});
});