test: narrow hook and inbound context assertions

This commit is contained in:
Peter Steinberger
2026-04-07 09:18:00 +01:00
parent eafe0a6d67
commit 58e822e712
3 changed files with 18 additions and 5 deletions

View File

@@ -78,8 +78,11 @@ describe("signal createSignalEventHandler inbound context", () => {
);
expect(capture.ctx).toBeTruthy();
expectInboundContextContract(capture.ctx!);
const contextWithBody = capture.ctx!;
const contextWithBody = capture.ctx;
if (!contextWithBody) {
throw new Error("expected inbound MsgContext");
}
expectInboundContextContract(contextWithBody);
// Sender should appear as prefix in group messages (no redundant [from:] suffix)
expect(String(contextWithBody.Body ?? "")).toContain("Alice");
expect(String(contextWithBody.Body ?? "")).toMatch(/Alice.*:/);

View File

@@ -33,7 +33,10 @@ const BASE_SLACK_SEND_CTX = {
} as const;
const sendSlackText = async (ctx: SlackSendTextCtx) => {
const sendText = slackOutbound.sendText as NonNullable<typeof slackOutbound.sendText>;
const sendText = slackOutbound.sendText;
if (!sendText) {
throw new Error("slackOutbound.sendText is unavailable");
}
return await sendText({
cfg: {} as OpenClawConfig,
...ctx,
@@ -147,7 +150,10 @@ describe("slack outbound hook wiring", () => {
};
getGlobalHookRunnerMock.mockReturnValue(mockRunner);
const sendText = slackOutbound.sendText as NonNullable<typeof slackOutbound.sendText>;
const sendText = slackOutbound.sendText;
if (!sendText) {
throw new Error("slackOutbound.sendText is unavailable");
}
await sendText({
cfg: {
channels: {

View File

@@ -47,7 +47,11 @@ describe("twitchMessageActions", () => {
configured: true,
availableAccountIds: ["default", "secondary"],
}));
vi.mocked(twitchOutbound.sendText!).mockResolvedValue({
const sendText = twitchOutbound.sendText;
if (!sendText) {
throw new Error("twitchOutbound.sendText is unavailable");
}
vi.mocked(sendText).mockResolvedValue({
channel: "twitch",
messageId: "msg-1",
timestamp: 1,