diff --git a/src/auto-reply/reply/commands-subagents.ts b/src/auto-reply/reply/commands-subagents.ts index f57c34f95..a1e33c642 100644 --- a/src/auto-reply/reply/commands-subagents.ts +++ b/src/auto-reply/reply/commands-subagents.ts @@ -45,7 +45,7 @@ function formatTimestampWithAge(valueMs?: number) { } function resolveRequesterSessionKey(params: Parameters[0]): string | undefined { - const raw = params.ctx.CommandTargetSessionKey?.trim() || params.sessionKey; + const raw = params.sessionKey?.trim() || params.ctx.CommandTargetSessionKey?.trim(); if (!raw) return undefined; const { mainKey, alias } = resolveMainSessionAlias(params.cfg); return resolveInternalSessionKey({ key: raw, alias, mainKey }); diff --git a/src/auto-reply/reply/commands.test.ts b/src/auto-reply/reply/commands.test.ts index fa104de03..cf383ed86 100644 --- a/src/auto-reply/reply/commands.test.ts +++ b/src/auto-reply/reply/commands.test.ts @@ -215,6 +215,33 @@ describe("handleCommands subagents", () => { expect(result.reply?.text).toContain("Subagents: none"); }); + it("lists subagents for the current command session over the target session", async () => { + resetSubagentRegistryForTests(); + addSubagentRunForTests({ + runId: "run-1", + childSessionKey: "agent:main:subagent:abc", + requesterSessionKey: "agent:main:slack:slash:U1", + requesterDisplayKey: "agent:main:slack:slash:U1", + task: "do thing", + cleanup: "keep", + createdAt: 1000, + startedAt: 1000, + }); + const cfg = { + commands: { text: true }, + channels: { whatsapp: { allowFrom: ["*"] } }, + } as ClawdbotConfig; + const params = buildParams("/subagents list", cfg, { + CommandSource: "native", + CommandTargetSessionKey: "agent:main:main", + }); + params.sessionKey = "agent:main:slack:slash:U1"; + const result = await handleCommands(params); + expect(result.shouldContinue).toBe(false); + expect(result.reply?.text).toContain("Subagents (current session)"); + expect(result.reply?.text).toContain("agent:main:subagent:abc"); + }); + it("omits subagent status line when none exist", async () => { resetSubagentRegistryForTests(); const cfg = { diff --git a/src/telegram/bot.create-telegram-bot.accepts-group-messages-mentionpatterns-match-without-botusername.test.ts b/src/telegram/bot.create-telegram-bot.accepts-group-messages-mentionpatterns-match-without-botusername.test.ts index 1d40a6ac5..3d27526fb 100644 --- a/src/telegram/bot.create-telegram-bot.accepts-group-messages-mentionpatterns-match-without-botusername.test.ts +++ b/src/telegram/bot.create-telegram-bot.accepts-group-messages-mentionpatterns-match-without-botusername.test.ts @@ -89,7 +89,6 @@ vi.mock("grammy", () => ({ const sequentializeMiddleware = vi.fn(); const sequentializeSpy = vi.fn(() => sequentializeMiddleware); let _sequentializeKey: ((ctx: unknown) => string) | undefined; -let originalTz: string | undefined; vi.mock("@grammyjs/runner", () => ({ sequentialize: (keyFn: (ctx: unknown) => string) => { _sequentializeKey = keyFn; @@ -119,9 +118,10 @@ const getOnHandler = (event: string) => { return handler as (ctx: Record) => Promise; }; +const ORIGINAL_TZ = process.env.TZ; + describe("createTelegramBot", () => { beforeEach(() => { - originalTz = process.env.TZ; process.env.TZ = "UTC"; resetInboundDedupe(); loadConfig.mockReturnValue({ @@ -140,9 +140,8 @@ describe("createTelegramBot", () => { botCtorSpy.mockReset(); _sequentializeKey = undefined; }); - afterEach(() => { - process.env.TZ = originalTz; + process.env.TZ = ORIGINAL_TZ; }); // groupPolicy tests diff --git a/src/telegram/bot.create-telegram-bot.installs-grammy-throttler.test.ts b/src/telegram/bot.create-telegram-bot.installs-grammy-throttler.test.ts index cabdfeae7..b11ecb058 100644 --- a/src/telegram/bot.create-telegram-bot.installs-grammy-throttler.test.ts +++ b/src/telegram/bot.create-telegram-bot.installs-grammy-throttler.test.ts @@ -1,4 +1,4 @@ -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { resetInboundDedupe } from "../auto-reply/reply/inbound-dedupe.js"; import { createTelegramBot, getTelegramSequentialKey } from "./bot.js"; import { resolveTelegramFetch } from "./fetch.js"; @@ -121,8 +121,11 @@ const getOnHandler = (event: string) => { return handler as (ctx: Record) => Promise; }; +const ORIGINAL_TZ = process.env.TZ; + describe("createTelegramBot", () => { beforeEach(() => { + process.env.TZ = "UTC"; resetInboundDedupe(); loadConfig.mockReturnValue({ channels: { @@ -140,6 +143,9 @@ describe("createTelegramBot", () => { botCtorSpy.mockReset(); sequentializeKey = undefined; }); + afterEach(() => { + process.env.TZ = ORIGINAL_TZ; + }); // groupPolicy tests diff --git a/src/telegram/bot.test.ts b/src/telegram/bot.test.ts index 2e7c86cf8..6c965932d 100644 --- a/src/telegram/bot.test.ts +++ b/src/telegram/bot.test.ts @@ -1,7 +1,7 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { listNativeCommandSpecs, listNativeCommandSpecsForConfig, @@ -147,8 +147,11 @@ const getOnHandler = (event: string) => { return handler as (ctx: Record) => Promise; }; +const ORIGINAL_TZ = process.env.TZ; + describe("createTelegramBot", () => { beforeEach(() => { + process.env.TZ = "UTC"; resetInboundDedupe(); loadConfig.mockReturnValue({ channels: { @@ -167,6 +170,9 @@ describe("createTelegramBot", () => { botCtorSpy.mockReset(); sequentializeKey = undefined; }); + afterEach(() => { + process.env.TZ = ORIGINAL_TZ; + }); it("installs grammY throttler", () => { createTelegramBot({ token: "tok" });