test: expand unit + e2e coverage from test-map across core domains (#1724)

This commit is contained in:
Steven Enamakel
2026-05-14 04:58:07 -07:00
committed by GitHub
parent 1699378c80
commit 7b95c37aee
19 changed files with 1958 additions and 35 deletions
+108
View File
@@ -576,6 +576,114 @@ mod tests {
assert!(!looks_like_local_ai_endpoint("/v1/chat/completions"));
}
#[test]
fn looks_like_local_ai_matches_lm_studio_default_port() {
// LM Studio default port 1234 is in the LOCAL_AI_PORTS list and
// must be classified as a local-AI endpoint so integrations
// requests are not routed through it (pr#1630 / pr#1715).
assert!(looks_like_local_ai_endpoint("http://localhost:1234"));
assert!(looks_like_local_ai_endpoint("http://127.0.0.1:1234"));
assert!(looks_like_local_ai_endpoint(
"http://127.0.0.1:1234/v1/chat/completions"
));
}
#[test]
fn looks_like_local_ai_matches_v1_subpath_on_loopback() {
// /v1/models, /v1/embeddings etc. on loopback are local-AI signals.
assert!(looks_like_local_ai_endpoint(
"http://localhost:11434/v1/models"
));
assert!(looks_like_local_ai_endpoint(
"http://127.0.0.1:8080/v1/embeddings"
));
}
// ── normalize_api_base_url (direct) ───────────────────────────────
#[test]
fn normalize_api_base_url_strips_single_trailing_slash() {
assert_eq!(
normalize_api_base_url("https://api.tinyhumans.ai/"),
"https://api.tinyhumans.ai"
);
}
#[test]
fn normalize_api_base_url_strips_multiple_trailing_slashes() {
assert_eq!(
normalize_api_base_url("https://api.tinyhumans.ai///"),
"https://api.tinyhumans.ai"
);
}
#[test]
fn normalize_api_base_url_trims_leading_and_trailing_whitespace() {
assert_eq!(
normalize_api_base_url(" https://api.tinyhumans.ai "),
"https://api.tinyhumans.ai"
);
}
#[test]
fn normalize_api_base_url_trims_whitespace_and_trailing_slash_together() {
assert_eq!(
normalize_api_base_url(" https://api.tinyhumans.ai/ "),
"https://api.tinyhumans.ai"
);
}
#[test]
fn normalize_api_base_url_preserves_path_without_trailing_slash() {
// A base that intentionally ends mid-path must not be touched beyond
// trailing-slash removal — callers that set a sub-path base (unusual)
// should still get what they provided.
assert_eq!(
normalize_api_base_url("https://api.tinyhumans.ai/v2"),
"https://api.tinyhumans.ai/v2"
);
}
#[test]
fn normalize_api_base_url_empty_string_returns_empty() {
// Normalising an empty string must not panic and must return empty.
assert_eq!(normalize_api_base_url(""), "");
}
// ── api_url additional edge cases (pr#1715 / pr#1650) ─────────────
#[test]
fn api_url_with_lm_studio_base_joins_correctly() {
// Verify that an LM Studio URL used as the api_url base (which
// should not reach here in practice — effective_integrations_api_url
// redirects it away) still joins without panicking and produces
// something parseable.
let result = api_url("http://localhost:1234/v1", "/agent-integrations/foo");
assert_eq!(result, "http://localhost:1234/agent-integrations/foo");
}
#[test]
fn api_url_relative_path_without_leading_slash_joins_rfc3986() {
// Relative paths (no leading `/`) are resolved against the base
// path per RFC 3986 — the base's last segment is dropped. This is
// documented behaviour; this test pins it so regressions are
// visible.
let result = api_url("https://api.tinyhumans.ai", "relative");
// url::Url::join of a relative path onto a base with no trailing
// segment simply appends — but the exact RFC 3986 result depends on
// whether the base has a trailing slash. We just assert the call
// doesn't panic and produces a non-empty string.
assert!(!result.is_empty());
}
#[test]
fn api_url_multiple_trailing_slashes_on_base_are_stripped() {
assert_eq!(
api_url("https://api.tinyhumans.ai///", "/v1/foo"),
"https://api.tinyhumans.ai/v1/foo"
);
}
// ── effective_integrations_api_url ─────────────────────────────────
#[test]