Files
boxmaker/docs/plans/M4b/files/crates/gatewayd/tests/config_approvals.rs
T
kyleandClaude Opus 5.5 2d415fc1be Plan M4b: approvals over Mattermost in 15 tasks
Skeletons for new files only; existing files change by exact edits, so no task overwrites an
earlier one's work. Each task's tests were run against a reference built in order from master,
with the gate at each step and mutations checked; each skeleton compiles and fails its tests, and
every todo!() comment was read beside its signature. The reference is kept off this machine.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 03:34:21 -07:00

69 lines
2.0 KiB
Rust

//! `[approvals]` in `gatewayd.toml`: who may answer, the first approver, and `gateway.sock`
//! (M4b spec, section 3). Do not edit.
use std::path::PathBuf;
use gatewayd::config::Config;
const KYLE: &str = "k0000000000000000000000000";
const HERMES: &str = "h0000000000000000000000000";
const OTHER: &str = "o0000000000000000000000000";
fn text(approvals: &str) -> String {
format!(
"[mattermost]\nurl = \"https://chat.example\"\n[secrets.mattermost_token]\nenv = \"T\"\n[allow]\nusers = [\"{KYLE}\", \"{HERMES}\"]\n[paths]\nhome = \"/srv/bx\"\n{approvals}"
)
}
fn config(approvals: &str) -> Config {
let c = Config::parse(&text(approvals)).unwrap();
assert_eq!(c.problem(), None);
c
}
#[test]
fn without_the_section_everyone_allowed_may_answer() {
let c = config("");
assert_eq!(c.approvers(), [KYLE, HERMES]);
assert_eq!(c.first_approver(), Some(KYLE));
assert_eq!(
c.gateway_socket(),
PathBuf::from("/srv/bx/run/gateway/gateway.sock")
);
assert_eq!(
config("[approvals]\nusers = []\n").approvers(),
[KYLE, HERMES]
);
}
#[test]
fn a_list_narrows_who_may_answer() {
let c = config(&format!(
"[approvals]\nusers = [\"{HERMES}\"]\nsocket = \"/run/gw.sock\"\n"
));
assert_eq!(c.approvers(), [HERMES]);
assert_eq!(c.first_approver(), Some(HERMES));
assert_eq!(c.gateway_socket(), PathBuf::from("/run/gw.sock"));
}
#[test]
fn an_approver_must_be_heard() {
let c = Config::parse(&text(&format!(
"[approvals]\nusers = [\"{KYLE}\", \"{OTHER}\"]\n"
)))
.unwrap();
let why = c.problem().expect("refused");
assert_eq!(
why,
format!(
"[approvals] \"{OTHER}\" is not in [allow] users: an approver who is not heard could never answer"
)
);
}
#[test]
fn unknown_keys_are_errors() {
assert!(Config::parse(&text("[approvals]\napprovers = []\n")).is_err());
assert!(Config::parse(&text("[approvals]\nusers = []\nttl = 5\n")).is_err());
}