test: remove test-only env vars

This commit is contained in:
Keisuke Hirata 2026-05-31 19:00:16 +09:00
parent 44ff1411a3
commit e64a559595
No known key found for this signature in database
2 changed files with 30 additions and 35 deletions

View File

@ -234,6 +234,17 @@ async fn brave_search(
))); )));
} }
brave_search_with_api_key(client, cfg, &api_key, query, limit, offset).await
}
async fn brave_search_with_api_key(
client: &Client,
cfg: &WebSearchConfig,
api_key: &str,
query: &str,
limit: usize,
offset: usize,
) -> Result<ToolOutput, ToolError> {
let endpoint = cfg.base_url.as_deref().unwrap_or(BRAVE_SEARCH_ENDPOINT); let endpoint = cfg.base_url.as_deref().unwrap_or(BRAVE_SEARCH_ENDPOINT);
let mut url = Url::parse(endpoint).map_err(|err| { let mut url = Url::parse(endpoint).map_err(|err| {
ToolError::InvalidArgument(format!("invalid Brave search endpoint: {err}")) ToolError::InvalidArgument(format!("invalid Brave search endpoint: {err}"))
@ -1694,6 +1705,17 @@ mod tests {
})) }))
} }
fn brave_search_config(base_url: String) -> WebSearchConfig {
WebSearchConfig {
enabled: Some(true),
provider: Some(WebSearchProvider::Brave),
api_key_env: None,
timeout_secs: Some(2),
base_url: Some(base_url),
..Default::default()
}
}
#[test] #[test]
fn validates_brave_query_limits() { fn validates_brave_query_limits() {
validate_brave_query("hello world").unwrap(); validate_brave_query("hello world").unwrap();
@ -2019,30 +2041,16 @@ mod tests {
async fn searches_brave_with_bounded_output() { async fn searches_brave_with_bounded_output() {
let response = "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"web\":{\"results\":[{\"title\":\"Example\",\"url\":\"https://example.com\",\"description\":\"Snippet\",\"extra_snippets\":[\"Extra\"],\"language\":\"en\"}]}}"; let response = "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{\"web\":{\"results\":[{\"title\":\"Example\",\"url\":\"https://example.com\",\"description\":\"Snippet\",\"extra_snippets\":[\"Extra\"],\"language\":\"en\"}]}}";
let (addr, captured) = serve_once_capture(response).await; let (addr, captured) = serve_once_capture(response).await;
let env_name = format!("INSOMNIA_TEST_BRAVE_KEY_{}", std::process::id());
unsafe { std::env::set_var(&env_name, "test-key") };
let tools = WebTools::new(Some(WebConfig { let tools = WebTools::new(Some(WebConfig {
enabled: Some(true), enabled: Some(true),
allow_private_addresses: Some(true), allow_private_addresses: Some(true),
search: Some(WebSearchConfig { search: None,
enabled: Some(true),
provider: Some(WebSearchProvider::Brave),
api_key_env: Some(env_name.clone()),
timeout_secs: Some(2),
base_url: Some(format!("http://{addr}/search")),
..Default::default()
}),
fetch: None, fetch: None,
})); }));
let result = tools let cfg = brave_search_config(format!("http://{addr}/search"));
.run_search(WebSearchInput { let result = brave_search_with_api_key(&tools.client, &cfg, "test-key", "insomnia", 1, 0)
query: "insomnia".into(),
limit: Some(1),
offset: Some(0),
})
.await .await
.unwrap(); .unwrap();
unsafe { std::env::remove_var(&env_name) };
let value: Value = serde_json::from_str(result.content.as_deref().unwrap()).unwrap(); let value: Value = serde_json::from_str(result.content.as_deref().unwrap()).unwrap();
let request = captured.lock().await.clone().unwrap(); let request = captured.lock().await.clone().unwrap();
assert!(request.starts_with("GET /search?q=insomnia&count=1&offset=0 ")); assert!(request.starts_with("GET /search?q=insomnia&count=1&offset=0 "));
@ -2065,29 +2073,16 @@ mod tests {
); );
let response: &'static str = Box::leak(response.into_boxed_str()); let response: &'static str = Box::leak(response.into_boxed_str());
let addr = serve_once(response).await; let addr = serve_once(response).await;
let env_name = format!("INSOMNIA_TEST_BRAVE_OVERSIZED_KEY_{}", std::process::id());
unsafe { std::env::set_var(&env_name, "test-key") };
let tools = WebTools::new(Some(WebConfig { let tools = WebTools::new(Some(WebConfig {
enabled: Some(true), enabled: Some(true),
allow_private_addresses: Some(true), allow_private_addresses: Some(true),
search: Some(WebSearchConfig { search: None,
enabled: Some(true),
provider: Some(WebSearchProvider::Brave),
api_key_env: Some(env_name.clone()),
base_url: Some(format!("http://{addr}/search")),
..Default::default()
}),
fetch: None, fetch: None,
})); }));
let err = tools let cfg = brave_search_config(format!("http://{addr}/search"));
.run_search(WebSearchInput { let err = brave_search_with_api_key(&tools.client, &cfg, "test-key", "insomnia", 1, 0)
query: "insomnia".into(),
limit: Some(1),
offset: Some(0),
})
.await .await
.unwrap_err(); .unwrap_err();
unsafe { std::env::remove_var(&env_name) };
assert!(err.to_string().contains("Content-Length")); assert!(err.to_string().contains("Content-Length"));
} }
} }

View File

@ -63,7 +63,7 @@ Credential env var は interoperability のために現時点では残ってい
## Build / example / test 変数 ## Build / example / test 変数
これらは通常の application configuration ではない。test-only の user-facing env var は supported surface として立てず、既存の `INSOMNIA_TEST_*`削除する。test が public env behavior を検証する必要がある場合だけ、shared guard / test-support crate で process environment mutation を閉じ込める。 これらは通常の application configuration ではない。test-only の user-facing env var は supported surface として立てず、既存のものも active code/tests から削除する。test が public env behavior を検証する必要がある場合だけ、shared guard / test-support crate で process environment mutation を閉じ込める。
| 変数 | Context | 備考 | | 変数 | Context | 備考 |
| --- | --- | --- | | --- | --- | --- |
@ -78,7 +78,7 @@ Credential env var は interoperability のために現時点では残ってい
- `INSOMNIA_USER_MANIFEST` は通常の profile-based Pod/TUI startup の一部ではない。one-file manifest の debug / compatibility path には `insomnia pod --manifest <PATH>` を使う。 - `INSOMNIA_USER_MANIFEST` は通常の profile-based Pod/TUI startup の一部ではない。one-file manifest の debug / compatibility path には `insomnia pod --manifest <PATH>` を使う。
- ambient `.insomnia/manifest.toml` discovery は通常の fresh startup の一部ではない。 - ambient `.insomnia/manifest.toml` discovery は通常の fresh startup の一部ではない。
- `INSOMNIA_POD_COMMAND` は single-binary 化に伴って削除する。Pod runtime は `insomnia pod ...` の typed command として起動する。 - `INSOMNIA_POD_COMMAND` は single-binary 化に伴って削除する。Pod runtime は `insomnia pod ...` の typed command として起動する。
- `INSOMNIA_TEST_*` のような test-only 環境変数は supported surface にしない。既存利用も削除する。 - 開発・テスト専用の環境変数は supported surface にしない。既存利用も削除する。
- `insomnia-pod` は installed command ではない。Pod runtime は `insomnia pod ...` から起動する。 - `insomnia-pod` は installed command ではない。Pod runtime は `insomnia pod ...` から起動する。
- 通常 runtime は `.env` ファイルを load しない。 - 通常 runtime は `.env` ファイルを load しない。