feat: finalize HTTP direct dispatch refactor and pending milestone updates
Switch API execution to direct daemon request handling, add regression coverage for non-socket HTTP dispatch, and include the remaining pending local updates across CLI/daemon/docs from the current worktree.
This commit is contained in:
+26
-1
@@ -7,6 +7,7 @@ use std::{
|
||||
use anyhow::bail;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::fs;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
/// The complete daemon configuration loaded from TOML.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||
@@ -93,7 +94,10 @@ impl TvctlConfig {
|
||||
"daemon.http_enabled" => self.daemon.http_enabled = parse_bool(key, value)?,
|
||||
"daemon.http_port" => self.daemon.http_port = parse_value(key, value)?,
|
||||
"daemon.http_host" => self.daemon.http_host = value.to_string(),
|
||||
"daemon.log_level" => self.daemon.log_level = value.to_string(),
|
||||
"daemon.log_level" => {
|
||||
validate_log_level(value)?;
|
||||
self.daemon.log_level = value.to_string();
|
||||
}
|
||||
"discovery.auto_discover" => self.discovery.auto_discover = parse_bool(key, value)?,
|
||||
"discovery.interval_secs" => self.discovery.interval_secs = parse_value(key, value)?,
|
||||
"discovery.timeout_secs" => self.discovery.timeout_secs = parse_value(key, value)?,
|
||||
@@ -311,6 +315,13 @@ where
|
||||
.map_err(|error| anyhow::anyhow!("invalid value '{value}' for {key}: {error}"))
|
||||
}
|
||||
|
||||
fn validate_log_level(value: &str) -> anyhow::Result<()> {
|
||||
EnvFilter::try_new(value).map_err(|error| {
|
||||
anyhow::anyhow!("invalid value '{value}' for daemon.log_level: {error}")
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -348,4 +359,18 @@ mod tests {
|
||||
.expect("config should load");
|
||||
assert_eq!(loaded, config);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_invalid_log_level_values() {
|
||||
let mut config = TvctlConfig::default();
|
||||
let error = config
|
||||
.set_value("daemon.log_level", "[")
|
||||
.expect_err("invalid log level should fail");
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.contains("invalid value '[' for daemon.log_level"),
|
||||
"unexpected error: {error}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user