brokerd: consult config, secrets, loopback URL
Co-Authored-By: ornith-1.5-35b-a3b <agent@wntrmute.dev>
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
//! `[consult]` in `brokerd.toml`. Do not edit.
|
||||
|
||||
#[path = "support/tmp.rs"]
|
||||
mod tmp;
|
||||
|
||||
use brokerd::config::{Config, ConfigError};
|
||||
use brokerd::consult::{DEFAULT_TEMPERATURE_MILLI, DEFAULT_TIMEOUT_MS};
|
||||
use tmp::TempDir;
|
||||
|
||||
fn load(text: &str) -> Result<Config, ConfigError> {
|
||||
let dir = TempDir::new("cfg-consult");
|
||||
let path = dir.write("brokerd.toml", text);
|
||||
Config::load(&path)
|
||||
}
|
||||
|
||||
const TABLE: &str = r#"
|
||||
[consult]
|
||||
url = "http://127.0.0.1:9/v1/chat/completions"
|
||||
model = "test-model"
|
||||
secret = "consult"
|
||||
"#;
|
||||
|
||||
#[test]
|
||||
fn no_consult_table_means_none() {
|
||||
let c = load("").unwrap();
|
||||
assert!(c.consult.is_none());
|
||||
assert!(c.secrets.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_consult_table_loads_defaults() {
|
||||
let c = load(TABLE).unwrap();
|
||||
let consult = c.consult.expect("consult");
|
||||
assert_eq!(consult.url, "http://127.0.0.1:9/v1/chat/completions");
|
||||
assert_eq!(consult.model, "test-model");
|
||||
assert_eq!(consult.secret, "consult");
|
||||
assert_eq!(consult.temperature_milli, DEFAULT_TEMPERATURE_MILLI);
|
||||
assert_eq!(consult.timeout_ms, DEFAULT_TIMEOUT_MS);
|
||||
assert!((consult.temperature() - 0.6).abs() < 1e-9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn temperature_above_zero_point_six_is_invalid() {
|
||||
let text = format!("{TABLE}temperature = 0.7\n");
|
||||
match load(&text) {
|
||||
Err(ConfigError::Parse(_, err)) => {
|
||||
let msg = err.to_string();
|
||||
assert!(msg.contains("0.6"), "{msg}");
|
||||
}
|
||||
other => panic!("{other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_non_loopback_url_is_invalid() {
|
||||
let text = r#"
|
||||
[consult]
|
||||
url = "https://example.com/v1/chat/completions"
|
||||
model = "x"
|
||||
secret = "consult"
|
||||
"#;
|
||||
match load(text) {
|
||||
Err(ConfigError::Invalid(_, why)) => {
|
||||
assert!(
|
||||
why.contains("http://127.0.0.1") || why.contains("localhost"),
|
||||
"{why}"
|
||||
);
|
||||
}
|
||||
other => panic!("{other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_consult_keys_are_errors() {
|
||||
let text = format!("{TABLE}vendor = \"x\"\n");
|
||||
assert!(matches!(load(&text), Err(ConfigError::Parse(_, _))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_secret_spec_loads_under_secrets() {
|
||||
let text = format!("{TABLE}\n[secrets.consult]\nenv = \"CONSULT_TOKEN\"\n");
|
||||
let c = load(&text).unwrap();
|
||||
assert!(c.secrets.contains_key("consult"));
|
||||
}
|
||||
Reference in New Issue
Block a user