diff --git a/src/infra/net/proxy-env.test.ts b/src/infra/net/proxy-env.test.ts index 37b910f17..3f3031f02 100644 --- a/src/infra/net/proxy-env.test.ts +++ b/src/infra/net/proxy-env.test.ts @@ -1,5 +1,31 @@ import { describe, expect, it } from "vitest"; -import { hasEnvHttpProxyConfigured, resolveEnvHttpProxyUrl } from "./proxy-env.js"; +import { + hasEnvHttpProxyConfigured, + hasProxyEnvConfigured, + resolveEnvHttpProxyUrl, +} from "./proxy-env.js"; + +describe("hasProxyEnvConfigured", () => { + it.each([ + { + name: "detects upper-case HTTP proxy values", + env: { HTTP_PROXY: "http://upper-http.test:8080" } as NodeJS.ProcessEnv, + expected: true, + }, + { + name: "detects lower-case all_proxy values", + env: { all_proxy: "socks5://proxy.test:1080" } as NodeJS.ProcessEnv, + expected: true, + }, + { + name: "ignores blank proxy values", + env: { HTTP_PROXY: " ", all_proxy: "" } as NodeJS.ProcessEnv, + expected: false, + }, + ])("$name", ({ env, expected }) => { + expect(hasProxyEnvConfigured(env)).toBe(expected); + }); +}); describe("resolveEnvHttpProxyUrl", () => { it("uses lower-case https_proxy before upper-case HTTPS_PROXY", () => { @@ -39,4 +65,24 @@ describe("resolveEnvHttpProxyUrl", () => { expect(resolveEnvHttpProxyUrl("https", env)).toBe("http://upper-http.test:8080"); expect(hasEnvHttpProxyConfigured("https", env)).toBe(true); }); + + it("does not use ALL_PROXY for EnvHttpProxyAgent-style resolution", () => { + const env = { + ALL_PROXY: "http://all-proxy.test:8080", + all_proxy: "http://lower-all-proxy.test:8080", + } as NodeJS.ProcessEnv; + + expect(resolveEnvHttpProxyUrl("https", env)).toBeUndefined(); + expect(resolveEnvHttpProxyUrl("http", env)).toBeUndefined(); + expect(hasEnvHttpProxyConfigured("https", env)).toBe(false); + }); + + it("returns only HTTP proxies for http requests", () => { + const env = { + https_proxy: "http://lower-https.test:8080", + http_proxy: "http://lower-http.test:8080", + } as NodeJS.ProcessEnv; + + expect(resolveEnvHttpProxyUrl("http", env)).toBe("http://lower-http.test:8080"); + }); }); diff --git a/src/infra/outbound/conversation-id.test.ts b/src/infra/outbound/conversation-id.test.ts index b35c8e2e4..68865219c 100644 --- a/src/infra/outbound/conversation-id.test.ts +++ b/src/infra/outbound/conversation-id.test.ts @@ -2,39 +2,58 @@ import { describe, expect, it } from "vitest"; import { resolveConversationIdFromTargets } from "./conversation-id.js"; describe("resolveConversationIdFromTargets", () => { - it("prefers explicit thread id when present", () => { - const resolved = resolveConversationIdFromTargets({ - threadId: "123456789", - targets: ["channel:987654321"], - }); - expect(resolved).toBe("123456789"); + it.each([ + { + name: "prefers explicit thread id strings", + params: { threadId: "123456789", targets: ["channel:987654321"] }, + expected: "123456789", + }, + { + name: "normalizes numeric thread ids", + params: { threadId: 123456789, targets: ["channel:987654321"] }, + expected: "123456789", + }, + { + name: "falls back when the thread id is blank", + params: { threadId: " ", targets: ["channel:987654321"] }, + expected: "987654321", + }, + ])("$name", ({ params, expected }) => { + expect(resolveConversationIdFromTargets(params)).toBe(expected); }); - it("extracts channel ids from channel: targets", () => { - const resolved = resolveConversationIdFromTargets({ + it.each([ + { + name: "extracts channel ids from channel targets", targets: ["channel:987654321"], - }); - expect(resolved).toBe("987654321"); - }); - - it("extracts ids from Discord channel mentions", () => { - const resolved = resolveConversationIdFromTargets({ + expected: "987654321", + }, + { + name: "trims channel target ids", + targets: ["channel: 987654321 "], + expected: "987654321", + }, + { + name: "extracts ids from Discord channel mentions", targets: ["<#1475250310120214812>"], - }); - expect(resolved).toBe("1475250310120214812"); - }); - - it("accepts raw numeric ids", () => { - const resolved = resolveConversationIdFromTargets({ + expected: "1475250310120214812", + }, + { + name: "accepts raw numeric ids", targets: ["1475250310120214812"], - }); - expect(resolved).toBe("1475250310120214812"); - }); - - it("returns undefined for non-channel targets", () => { - const resolved = resolveConversationIdFromTargets({ + expected: "1475250310120214812", + }, + { + name: "returns undefined for non-channel targets", targets: ["user:alice", "general"], - }); - expect(resolved).toBeUndefined(); + expected: undefined, + }, + { + name: "skips blank and malformed targets", + targets: [undefined, null, " ", "channel: ", "<#not-a-number>"], + expected: undefined, + }, + ])("$name", ({ targets, expected }) => { + expect(resolveConversationIdFromTargets({ targets })).toBe(expected); }); });