From 238718c1d8bd59e68a8b3adc1ab12474cca3c064 Mon Sep 17 00:00:00 2001 From: cpojer Date: Tue, 17 Feb 2026 15:47:14 +0900 Subject: [PATCH] chore: Fix types in tests 37/N. --- .../bootstrap-extra-files/handler.test.ts | 4 ++-- .../bundled/session-memory/handler.test.ts | 2 +- src/hooks/install.test.ts | 23 +++++++++++++++---- src/line/auto-reply-delivery.test.ts | 7 +++--- src/line/bot-message-context.test.ts | 4 ++++ src/line/rich-menu.test.ts | 4 ++-- src/media-understanding/apply.e2e.test.ts | 4 ++-- .../media-understanding-misc.test.ts | 2 +- src/media/fetch.test.ts | 10 ++++++-- 9 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/hooks/bundled/bootstrap-extra-files/handler.test.ts b/src/hooks/bundled/bootstrap-extra-files/handler.test.ts index f810e009593..866c808dbf0 100644 --- a/src/hooks/bundled/bootstrap-extra-files/handler.test.ts +++ b/src/hooks/bundled/bootstrap-extra-files/handler.test.ts @@ -28,7 +28,7 @@ async function createBootstrapContext(params: { sessionKey: string; rootFiles: Array<{ name: string; content: string }>; }): Promise { - const bootstrapFiles = await Promise.all( + const bootstrapFiles = (await Promise.all( params.rootFiles.map(async (file) => ({ name: file.name, path: await writeWorkspaceFile({ @@ -39,7 +39,7 @@ async function createBootstrapContext(params: { content: file.content, missing: false, })), - ); + )) as AgentBootstrapHookContext["bootstrapFiles"]; return { workspaceDir: params.workspaceDir, bootstrapFiles, diff --git a/src/hooks/bundled/session-memory/handler.test.ts b/src/hooks/bundled/session-memory/handler.test.ts index 5a611162c71..af0e021544c 100644 --- a/src/hooks/bundled/session-memory/handler.test.ts +++ b/src/hooks/bundled/session-memory/handler.test.ts @@ -21,7 +21,7 @@ beforeAll(async () => { * Create a mock session JSONL file with various entry types */ function createMockSessionContent( - entries: Array<{ role: string; content: string } | { type: string }>, + entries: Array<{ role: string; content: string } | ({ type: string } & Record)>, ): string { return entries .map((entry) => { diff --git a/src/hooks/install.test.ts b/src/hooks/install.test.ts index 11b9456e79f..1944b83f908 100644 --- a/src/hooks/install.test.ts +++ b/src/hooks/install.test.ts @@ -180,7 +180,14 @@ describe("installHooksFromPath", () => { ); const run = vi.mocked(runCommandWithTimeout); - run.mockResolvedValue({ code: 0, stdout: "", stderr: "" }); + run.mockResolvedValue({ + code: 0, + stdout: "", + stderr: "", + signal: null, + killed: false, + termination: "exit", + }); const res = await installHooksFromPath({ path: pkgDir, @@ -239,9 +246,16 @@ describe("installHooksFromNpmSpec", () => { const packedName = "test-hooks-0.0.1.tgz"; run.mockImplementation(async (argv, opts) => { if (argv[0] === "npm" && argv[1] === "pack") { - packTmpDir = String(opts?.cwd ?? ""); + packTmpDir = String(typeof opts === "number" ? "" : (opts.cwd ?? "")); fs.writeFileSync(path.join(packTmpDir, packedName), npmPackHooksBuffer); - return { code: 0, stdout: `${packedName}\n`, stderr: "", signal: null, killed: false }; + return { + code: 0, + stdout: `${packedName}\n`, + stderr: "", + signal: null, + killed: false, + termination: "exit", + }; } throw new Error(`unexpected command: ${argv.join(" ")}`); }); @@ -269,7 +283,8 @@ describe("installHooksFromNpmSpec", () => { } const [argv, options] = packCall; expect(argv).toEqual(["npm", "pack", "@openclaw/test-hooks@0.0.1", "--ignore-scripts"]); - expect(options?.env).toMatchObject({ NPM_CONFIG_IGNORE_SCRIPTS: "true" }); + const commandOptions = typeof options === "number" ? undefined : options; + expect(commandOptions?.env).toMatchObject({ NPM_CONFIG_IGNORE_SCRIPTS: "true" }); expect(packTmpDir).not.toBe(""); expect(fs.existsSync(packTmpDir)).toBe(false); diff --git a/src/line/auto-reply-delivery.test.ts b/src/line/auto-reply-delivery.test.ts index 640d436ba9b..a75d5f42756 100644 --- a/src/line/auto-reply-delivery.test.ts +++ b/src/line/auto-reply-delivery.test.ts @@ -46,9 +46,9 @@ describe("deliverLineAutoReply", () => { pushMessageLine, pushTextMessageWithQuickReplies, createTextMessageWithQuickReplies, - createQuickReplyItems, + createQuickReplyItems: createQuickReplyItems as LineAutoReplyDeps["createQuickReplyItems"], pushMessagesLine, - createFlexMessage, + createFlexMessage: createFlexMessage as LineAutoReplyDeps["createFlexMessage"], createImageMessage, createLocationMessage, ...overrides, @@ -146,7 +146,8 @@ describe("deliverLineAutoReply", () => { quickReplies: ["A"], }; const { deps, pushMessagesLine, replyMessageLine } = createDeps({ - createTextMessageWithQuickReplies, + createTextMessageWithQuickReplies: + createTextMessageWithQuickReplies as LineAutoReplyDeps["createTextMessageWithQuickReplies"], }); await deliverLineAutoReply({ diff --git a/src/line/bot-message-context.test.ts b/src/line/bot-message-context.test.ts index b888c43bd5c..52baa0f4da0 100644 --- a/src/line/bot-message-context.test.ts +++ b/src/line/bot-message-context.test.ts @@ -53,6 +53,10 @@ describe("buildLineMessageContext", () => { cfg, account, }); + expect(context).not.toBeNull(); + if (!context) { + throw new Error("context missing"); + } expect(context.ctxPayload.OriginatingTo).toBe("line:group:group-1"); expect(context.ctxPayload.To).toBe("line:group:group-1"); diff --git a/src/line/rich-menu.test.ts b/src/line/rich-menu.test.ts index 6e98ee2aa15..95de2fe67e4 100644 --- a/src/line/rich-menu.test.ts +++ b/src/line/rich-menu.test.ts @@ -26,7 +26,7 @@ describe("messageAction", () => { it("truncates label to 20 characters", () => { const action = messageAction("This is a very long label text"); - expect(action.label.length).toBe(20); + expect((action.label ?? "").length).toBe(20); expect(action.label).toBe("This is a very long "); }); }); @@ -43,7 +43,7 @@ describe("uriAction", () => { it("truncates label to 20 characters", () => { const action = uriAction("Click here to visit our website", "https://example.com"); - expect(action.label.length).toBe(20); + expect((action.label ?? "").length).toBe(20); }); }); diff --git a/src/media-understanding/apply.e2e.test.ts b/src/media-understanding/apply.e2e.test.ts index adc7d76d48f..240c65853a0 100644 --- a/src/media-understanding/apply.e2e.test.ts +++ b/src/media-understanding/apply.e2e.test.ts @@ -154,7 +154,7 @@ describe("applyMediaUnderstanding", () => { body: "[Audio]\nTranscript:\ntranscribed text", commandBody: "transcribed text", }); - expect(ctx.BodyForAgent).toBe(ctx.Body); + expect((ctx as unknown as { BodyForAgent?: string }).BodyForAgent).toBe(ctx.Body); }); it("skips file blocks for text-like audio when transcription succeeds", async () => { @@ -308,7 +308,7 @@ describe("applyMediaUnderstanding", () => { }); expect(result.appliedAudio).toBe(true); - expect(ctx.Transcript).toBe("cli transcript"); + expect((ctx as unknown as { Transcript?: string }).Transcript).toBe("cli transcript"); expect(ctx.Body).toBe("[Audio]\nTranscript:\ncli transcript"); }); diff --git a/src/media-understanding/media-understanding-misc.test.ts b/src/media-understanding/media-understanding-misc.test.ts index f33a9ebbeb9..97cd139014d 100644 --- a/src/media-understanding/media-understanding-misc.test.ts +++ b/src/media-understanding/media-understanding-misc.test.ts @@ -12,7 +12,7 @@ describe("media understanding scope", () => { it("matches channel chatType explicitly", () => { const scope = { rules: [{ action: "deny", match: { chatType: "channel" } }], - } as const; + } as Parameters[0]["scope"]; expect(resolveMediaUnderstandingScope({ scope, chatType: "channel" })).toBe("deny"); }); diff --git a/src/media/fetch.test.ts b/src/media/fetch.test.ts index d08f67dc9fb..4802d6b3019 100644 --- a/src/media/fetch.test.ts +++ b/src/media/fetch.test.ts @@ -13,8 +13,12 @@ function makeStream(chunks: Uint8Array[]) { } describe("fetchRemoteMedia", () => { + type LookupFn = NonNullable[0]["lookupFn"]>; + it("rejects when content-length exceeds maxBytes", async () => { - const lookupFn = vi.fn(async () => [{ address: "93.184.216.34", family: 4 }]); + const lookupFn = vi.fn(async () => [ + { address: "93.184.216.34", family: 4 }, + ]) as unknown as LookupFn; const fetchImpl = async () => new Response(makeStream([new Uint8Array([1, 2, 3, 4, 5])]), { status: 200, @@ -32,7 +36,9 @@ describe("fetchRemoteMedia", () => { }); it("rejects when streamed payload exceeds maxBytes", async () => { - const lookupFn = vi.fn(async () => [{ address: "93.184.216.34", family: 4 }]); + const lookupFn = vi.fn(async () => [ + { address: "93.184.216.34", family: 4 }, + ]) as unknown as LookupFn; const fetchImpl = async () => new Response(makeStream([new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])]), { status: 200,