mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-09-06 08:18:58 +00:00
Add ServerConfig for arc.toml server configuration
Introduces server_config.rs with a TOML-based ServerConfig struct (version + url) following the same patterns as TaskConfig. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7f921fb82a
commit
771b70889b
2 changed files with 86 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ pub mod cli_backend;
|
|||
pub mod run;
|
||||
#[cfg(feature = "server")]
|
||||
pub mod serve;
|
||||
pub mod server_config;
|
||||
pub mod task_config;
|
||||
pub mod validate;
|
||||
|
||||
|
|
|
|||
85
crates/arc-workflows/src/cli/server_config.rs
Normal file
85
crates/arc-workflows/src/cli/server_config.rs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
use std::path::Path;
|
||||
|
||||
use anyhow::{bail, Context};
|
||||
use serde::Deserialize;
|
||||
|
||||
const SUPPORTED_VERSION: &str = "1";
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ServerConfig {
|
||||
pub version: String,
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
pub fn load_server_config(path: &Path) -> anyhow::Result<ServerConfig> {
|
||||
let contents =
|
||||
std::fs::read_to_string(path).with_context(|| format!("Failed to read {}", path.display()))?;
|
||||
parse_server_config(&contents)
|
||||
}
|
||||
|
||||
fn parse_server_config(contents: &str) -> anyhow::Result<ServerConfig> {
|
||||
let config: ServerConfig =
|
||||
toml::from_str(contents).context("Failed to parse server config TOML")?;
|
||||
|
||||
if config.version != SUPPORTED_VERSION {
|
||||
bail!(
|
||||
"Unsupported server config version {}. Only version {SUPPORTED_VERSION} is supported.",
|
||||
config.version
|
||||
);
|
||||
}
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn parse_valid_config() {
|
||||
let toml = r#"
|
||||
version = "1"
|
||||
url = "http://localhost:3000"
|
||||
"#;
|
||||
let config = parse_server_config(toml).unwrap();
|
||||
assert_eq!(config.version, "1");
|
||||
assert_eq!(config.url, "http://localhost:3000");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsupported_version_rejected() {
|
||||
let toml = r#"
|
||||
version = "2"
|
||||
url = "http://localhost:3000"
|
||||
"#;
|
||||
let err = parse_server_config(toml).unwrap_err();
|
||||
assert!(
|
||||
err.to_string().contains("Unsupported server config version 2"),
|
||||
"unexpected error: {err}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_fields_rejected() {
|
||||
let toml = r#"
|
||||
version = "1"
|
||||
url = "http://localhost:3000"
|
||||
extra = "nope"
|
||||
"#;
|
||||
assert!(parse_server_config(toml).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_fields_rejected() {
|
||||
let no_url = r#"
|
||||
version = "1"
|
||||
"#;
|
||||
assert!(parse_server_config(no_url).is_err());
|
||||
|
||||
let no_version = r#"
|
||||
url = "http://localhost:3000"
|
||||
"#;
|
||||
assert!(parse_server_config(no_version).is_err());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue