test: tighten proxy env and conversation id coverage

This commit is contained in:
Peter Steinberger
2026-03-13 19:11:03 +00:00
parent 5189ba851c
commit dfcbfcfcc9
2 changed files with 94 additions and 29 deletions

View File

@@ -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");
});
});

View File

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