test: trim smoke duplicates and reuse telegram bot setup

This commit is contained in:
Peter Steinberger
2026-02-22 12:55:27 +00:00
parent 27053826e5
commit 5e62d0105b
2 changed files with 16 additions and 60 deletions

View File

@@ -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();

View File

@@ -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<string, unknown>) => Promise<void>;
let replySpy: ReturnType<typeof vi.fn>;
beforeAll(async () => {
const { createTelegramBot } = await import("./bot.js");
const replyModule = await import("../auto-reply/reply.js");
const replySpy = (replyModule as unknown as { __replySpy: ReturnType<typeof vi.fn> }).__replySpy;
replySpy = (replyModule as unknown as { __replySpy: ReturnType<typeof vi.fn> }).__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<string, unknown>,
) => Promise<void>;
expect(handler).toBeDefined();
return { handler, replySpy };
}
expect(registeredHandler).toBeDefined();
handler = registeredHandler;
});
beforeEach(() => {
replySpy.mockClear();
});
function expectSingleReplyPayload(replySpy: ReturnType<typeof vi.fn>) {
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" },