diff --git a/extensions/telegram/src/api-fetch.test.ts b/extensions/telegram/src/api-fetch.test.ts index 5de45f6ee75..a5cafdc60b1 100644 --- a/extensions/telegram/src/api-fetch.test.ts +++ b/extensions/telegram/src/api-fetch.test.ts @@ -1,6 +1,31 @@ -import { describe, expect, it, vi } from "vitest"; +import { createRequire } from "node:module"; +import { afterEach, describe, expect, it, vi } from "vitest"; import { fetchTelegramChatId } from "./api-fetch.js"; +const require = createRequire(import.meta.url); +const EnvHttpProxyAgent = require("undici/lib/dispatcher/env-http-proxy-agent.js") as { + new (opts?: Record): Record; +}; +const { kHttpsProxyAgent, kNoProxyAgent } = require("undici/lib/core/symbols.js") as { + kHttpsProxyAgent: symbol; + kNoProxyAgent: symbol; +}; + +function getOwnSymbolValue( + target: Record, + description: string, +): Record | undefined { + const symbol = Object.getOwnPropertySymbols(target).find( + (entry) => entry.description === description, + ); + const value = symbol ? target[symbol] : undefined; + return value && typeof value === "object" ? (value as Record) : undefined; +} + +afterEach(() => { + vi.unstubAllEnvs(); +}); + describe("fetchTelegramChatId", () => { const cases = [ { @@ -79,3 +104,35 @@ describe("fetchTelegramChatId", () => { ); }); }); + +describe("undici env proxy semantics", () => { + it("uses proxyTls rather than connect for proxied HTTPS transport settings", () => { + vi.stubEnv("HTTPS_PROXY", "http://127.0.0.1:7890"); + const connect = { + family: 4, + autoSelectFamily: false, + }; + + const withoutProxyTls = new EnvHttpProxyAgent({ connect }); + const noProxyAgent = withoutProxyTls[kNoProxyAgent] as Record; + const httpsProxyAgent = withoutProxyTls[kHttpsProxyAgent] as Record; + + expect(getOwnSymbolValue(noProxyAgent, "options")?.connect).toEqual( + expect.objectContaining(connect), + ); + expect(getOwnSymbolValue(httpsProxyAgent, "proxy tls settings")).toBeUndefined(); + + const withProxyTls = new EnvHttpProxyAgent({ + connect, + proxyTls: connect, + }); + const httpsProxyAgentWithProxyTls = withProxyTls[kHttpsProxyAgent] as Record< + PropertyKey, + unknown + >; + + expect(getOwnSymbolValue(httpsProxyAgentWithProxyTls, "proxy tls settings")).toEqual( + expect.objectContaining(connect), + ); + }); +}); diff --git a/extensions/telegram/src/bot-message-context.sender-prefix.test.ts b/extensions/telegram/src/bot-message-context.sender-prefix.test.ts index f49dd283796..104eb64d5d9 100644 --- a/extensions/telegram/src/bot-message-context.sender-prefix.test.ts +++ b/extensions/telegram/src/bot-message-context.sender-prefix.test.ts @@ -1,5 +1,23 @@ import { describe, expect, it } from "vitest"; import { buildTelegramMessageContextForTest } from "./bot-message-context.test-harness.js"; +import { + isTelegramForumServiceMessage, + TELEGRAM_FORUM_SERVICE_FIELDS, +} from "./forum-service-message.js"; + +describe("isTelegramForumServiceMessage", () => { + it("returns true for any Telegram forum service field", () => { + for (const field of TELEGRAM_FORUM_SERVICE_FIELDS) { + expect(isTelegramForumServiceMessage({ [field]: {} })).toBe(true); + } + }); + + it("returns false for normal messages and non-objects", () => { + expect(isTelegramForumServiceMessage({ text: "hello" })).toBe(false); + expect(isTelegramForumServiceMessage(null)).toBe(false); + expect(isTelegramForumServiceMessage("topic created")).toBe(false); + }); +}); describe("buildTelegramMessageContext sender prefix", () => { async function buildCtx(params: { messageId: number; options?: Record }) { diff --git a/extensions/telegram/src/fetch.env-proxy-runtime.test.ts b/extensions/telegram/src/fetch.env-proxy-runtime.test.ts deleted file mode 100644 index 0292f465747..00000000000 --- a/extensions/telegram/src/fetch.env-proxy-runtime.test.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { createRequire } from "node:module"; -import { afterEach, describe, expect, it, vi } from "vitest"; - -const require = createRequire(import.meta.url); -const EnvHttpProxyAgent = require("undici/lib/dispatcher/env-http-proxy-agent.js") as { - new (opts?: Record): Record; -}; -const { kHttpsProxyAgent, kNoProxyAgent } = require("undici/lib/core/symbols.js") as { - kHttpsProxyAgent: symbol; - kNoProxyAgent: symbol; -}; - -function getOwnSymbolValue( - target: Record, - description: string, -): Record | undefined { - const symbol = Object.getOwnPropertySymbols(target).find( - (entry) => entry.description === description, - ); - const value = symbol ? target[symbol] : undefined; - return value && typeof value === "object" ? (value as Record) : undefined; -} - -afterEach(() => { - vi.unstubAllEnvs(); -}); - -describe("undici env proxy semantics", () => { - it("uses proxyTls rather than connect for proxied HTTPS transport settings", () => { - vi.stubEnv("HTTPS_PROXY", "http://127.0.0.1:7890"); - const connect = { - family: 4, - autoSelectFamily: false, - }; - - const withoutProxyTls = new EnvHttpProxyAgent({ connect }); - const noProxyAgent = withoutProxyTls[kNoProxyAgent] as Record; - const httpsProxyAgent = withoutProxyTls[kHttpsProxyAgent] as Record; - - expect(getOwnSymbolValue(noProxyAgent, "options")?.connect).toEqual( - expect.objectContaining(connect), - ); - expect(getOwnSymbolValue(httpsProxyAgent, "proxy tls settings")).toBeUndefined(); - - const withProxyTls = new EnvHttpProxyAgent({ - connect, - proxyTls: connect, - }); - const httpsProxyAgentWithProxyTls = withProxyTls[kHttpsProxyAgent] as Record< - PropertyKey, - unknown - >; - - expect(getOwnSymbolValue(httpsProxyAgentWithProxyTls, "proxy tls settings")).toEqual( - expect.objectContaining(connect), - ); - }); -}); diff --git a/extensions/telegram/src/forum-service-message.test.ts b/extensions/telegram/src/forum-service-message.test.ts deleted file mode 100644 index 6fcd9564ef1..00000000000 --- a/extensions/telegram/src/forum-service-message.test.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { - isTelegramForumServiceMessage, - TELEGRAM_FORUM_SERVICE_FIELDS, -} from "./forum-service-message.js"; - -describe("isTelegramForumServiceMessage", () => { - it("returns true for any Telegram forum service field", () => { - for (const field of TELEGRAM_FORUM_SERVICE_FIELDS) { - expect(isTelegramForumServiceMessage({ [field]: {} })).toBe(true); - } - }); - - it("returns false for normal messages and non-objects", () => { - expect(isTelegramForumServiceMessage({ text: "hello" })).toBe(false); - expect(isTelegramForumServiceMessage(null)).toBe(false); - expect(isTelegramForumServiceMessage("topic created")).toBe(false); - }); -});