From 5e62d0105b75befb3dfaf74c1b499bb1d4ca3fb0 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 22 Feb 2026 12:55:27 +0000 Subject: [PATCH] test: trim smoke duplicates and reuse telegram bot setup --- src/cli/program.smoke.test.ts | 49 +------------------ ...udes-location-text-ctx-fields-pins.test.ts | 27 +++++----- 2 files changed, 16 insertions(+), 60 deletions(-) diff --git a/src/cli/program.smoke.test.ts b/src/cli/program.smoke.test.ts index ea65a1c7a..405d23c7c 100644 --- a/src/cli/program.smoke.test.ts +++ b/src/cli/program.smoke.test.ts @@ -7,11 +7,9 @@ import { messageCommand, onboardCommand, runChannelLogin, - runChannelLogout, runTui, runtime, setupCommand, - statusCommand, } from "./program.test-mocks.js"; installBaseProgramMocks(); @@ -62,15 +60,11 @@ describe("cli program (smoke)", () => { expect(messageCommand).toHaveBeenCalled(); }); - it("runs status command", async () => { - await runProgram(["status"]); - expect(statusCommand).toHaveBeenCalled(); - }); - - it("registers memory command", () => { + it("registers memory + status commands", () => { const program = createProgram(); const names = program.commands.map((command) => command.name()); expect(names).toContain("memory"); + expect(names).toContain("status"); }); it.each([ @@ -126,48 +120,18 @@ describe("cli program (smoke)", () => { it("passes auth api keys to onboard", async () => { const cases = [ - { - authChoice: "opencode-zen", - flag: "--opencode-zen-api-key", - key: "sk-opencode-zen-test", - field: "opencodeZenApiKey", - }, { authChoice: "openrouter-api-key", flag: "--openrouter-api-key", key: "sk-openrouter-test", field: "openrouterApiKey", }, - { - authChoice: "moonshot-api-key", - flag: "--moonshot-api-key", - key: "sk-moonshot-test", - field: "moonshotApiKey", - }, - { - authChoice: "together-api-key", - flag: "--together-api-key", - key: "sk-together-test", - field: "togetherApiKey", - }, { authChoice: "moonshot-api-key-cn", flag: "--moonshot-api-key", key: "sk-moonshot-cn-test", field: "moonshotApiKey", }, - { - authChoice: "kimi-code-api-key", - flag: "--kimi-code-api-key", - key: "sk-kimi-code-test", - field: "kimiCodeApiKey", - }, - { - authChoice: "synthetic-api-key", - flag: "--synthetic-api-key", - key: "sk-synthetic-test", - field: "syntheticApiKey", - }, { authChoice: "zai-api-key", flag: "--zai-api-key", @@ -239,15 +203,6 @@ describe("cli program (smoke)", () => { runtime, ), }, - { - label: "runs channels logout", - argv: ["channels", "logout", "--account", "work"], - expectCall: () => - expect(runChannelLogout).toHaveBeenCalledWith( - { channel: undefined, account: "work" }, - runtime, - ), - }, ])("channels command: $label", async ({ argv, expectCall }) => { await runProgram(argv); expectCall(); diff --git a/src/telegram/bot.media.includes-location-text-ctx-fields-pins.test.ts b/src/telegram/bot.media.includes-location-text-ctx-fields-pins.test.ts index 96b93358b..2bc104fba 100644 --- a/src/telegram/bot.media.includes-location-text-ctx-fields-pins.test.ts +++ b/src/telegram/bot.media.includes-location-text-ctx-fields-pins.test.ts @@ -1,21 +1,26 @@ -import { describe, expect, it, vi } from "vitest"; +import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import { onSpy } from "./bot.media.e2e-harness.js"; -async function createMessageHandlerAndReplySpy() { +let handler: (ctx: Record) => Promise; +let replySpy: ReturnType; + +beforeAll(async () => { const { createTelegramBot } = await import("./bot.js"); const replyModule = await import("../auto-reply/reply.js"); - const replySpy = (replyModule as unknown as { __replySpy: ReturnType }).__replySpy; + replySpy = (replyModule as unknown as { __replySpy: ReturnType }).__replySpy; onSpy.mockClear(); - replySpy.mockClear(); - createTelegramBot({ token: "tok" }); - const handler = onSpy.mock.calls.find((call) => call[0] === "message")?.[1] as ( + const registeredHandler = onSpy.mock.calls.find((call) => call[0] === "message")?.[1] as ( ctx: Record, ) => Promise; - expect(handler).toBeDefined(); - return { handler, replySpy }; -} + expect(registeredHandler).toBeDefined(); + handler = registeredHandler; +}); + +beforeEach(() => { + replySpy.mockClear(); +}); function expectSingleReplyPayload(replySpy: ReturnType) { expect(replySpy).toHaveBeenCalledTimes(1); @@ -27,8 +32,6 @@ describe("telegram inbound media", () => { it( "includes location text and ctx fields for pins", async () => { - const { handler, replySpy } = await createMessageHandlerAndReplySpy(); - await handler({ message: { chat: { id: 42, type: "private" }, @@ -59,8 +62,6 @@ describe("telegram inbound media", () => { it( "captures venue fields for named places", async () => { - const { handler, replySpy } = await createMessageHandlerAndReplySpy(); - await handler({ message: { chat: { id: 42, type: "private" },