Files
boxmaker/docs/plans/M6b/files/crates/brokerd/tests/consult_secret.rs
T
kyleandGrok 4.6 50e9cc2037 docs: M6b implementation plan
Six closed tasks for consult: registry, CONSULT_WAIT, [consult]/[secrets],
ToolName and grants, Decision body, loopback HTTP. Reference is the git bundle
~/boxmaker-refs/m6b-ref.bundle at 5fb05f0. Gate after task 06 is 1611.

Co-Authored-By: Grok 4.6 <noreply@x.ai>
2026-10-03 21:39:31 -07:00

83 lines
2.0 KiB
Rust

//! `[consult]` without a readable secret: `brokerd` does not start. Do not edit.
#[path = "support/tmp.rs"]
mod tmp;
use std::ffi::OsString;
use brokerd::config::Config;
use brokerd::consult::{self, SECRET_POINTER};
use tmp::TempDir;
#[test]
fn a_missing_secrets_entry_is_consult_secret_unreadable() {
let dir = TempDir::new("consult-secret-missing");
let path = dir.write(
"brokerd.toml",
r#"
[consult]
url = "http://127.0.0.1:9/v1/chat/completions"
model = "test-model"
secret = "consult"
"#,
);
let cfg = Config::load(&path).unwrap();
let err = consult::load_secret(&cfg, &|_| None).unwrap_err();
let text = err.to_string();
assert!(text.contains(SECRET_POINTER), "{text}");
assert!(text.contains("consult"), "{text}");
}
#[test]
fn an_unreadable_env_secret_names_both_pointers() {
let dir = TempDir::new("consult-secret-env");
let path = dir.write(
"brokerd.toml",
r#"
[consult]
url = "http://127.0.0.1:9/v1/chat/completions"
model = "test-model"
secret = "consult"
[secrets.consult]
env = "CONSULT_TOKEN_FOR_THIS_TEST_UNSET"
"#,
);
let cfg = Config::load(&path).unwrap();
let err = consult::load_secret(&cfg, &|_| None).unwrap_err();
let text = err.to_string();
assert!(text.contains(SECRET_POINTER), "{text}");
assert!(
text.contains("docs/runbook.md#secret-unavailable"),
"{text}"
);
}
#[test]
fn a_present_env_secret_loads() {
let dir = TempDir::new("consult-secret-ok");
let path = dir.write(
"brokerd.toml",
r#"
[consult]
url = "http://127.0.0.1:9/v1/chat/completions"
model = "test-model"
secret = "consult"
[secrets.consult]
env = "CONSULT_TOKEN_FOR_THIS_TEST_SET"
"#,
);
let cfg = Config::load(&path).unwrap();
let loaded = consult::load_secret(&cfg, &|k| {
if k == "CONSULT_TOKEN_FOR_THIS_TEST_SET" {
Some(OsString::from("bearer-value"))
} else {
None
}
})
.unwrap()
.expect("loaded");
assert_eq!(loaded.secret.expose(), "bearer-value");
}