Skip to main content

jevia_core/
config.rs

1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4use thiserror::Error;
5
6/// Current version of the project configuration format.
7pub const CONFIG_VERSION: u32 = 1;
8
9/// Project-level Jevia configuration.
10#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11#[serde(deny_unknown_fields)]
12pub struct Config {
13    pub version: u32,
14    pub router: RouterConfig,
15    pub jev: JevConfig,
16    pub privacy: PrivacyConfig,
17    #[serde(default, skip_serializing_if = "StorageConfig::is_jsonl")]
18    pub storage: StorageConfig,
19    #[serde(default)]
20    pub cache: CacheConfig,
21    pub tiers: BTreeMap<String, TierConfig>,
22    #[serde(default)]
23    pub harnesses: BTreeMap<String, HarnessConfig>,
24}
25
26impl Config {
27    /// Parse and validate a TOML configuration document.
28    pub fn from_toml(input: &str) -> Result<Self, ConfigError> {
29        let config: Self = toml::from_str(input)?;
30        config.validate()?;
31        Ok(config)
32    }
33
34    /// Render this configuration as a stable, human-readable TOML document.
35    pub fn to_toml(&self) -> Result<String, ConfigError> {
36        self.validate()?;
37        Ok(toml::to_string_pretty(self)?)
38    }
39
40    /// Validate cross-field policy invariants.
41    pub fn validate(&self) -> Result<(), ConfigError> {
42        if self.version != CONFIG_VERSION {
43            return Err(ConfigError::UnsupportedVersion(self.version));
44        }
45        self.storage.validate()?;
46        if !(0.0..=1.0).contains(&self.router.confidence_floor) {
47            return Err(ConfigError::InvalidConfidenceFloor(
48                self.router.confidence_floor,
49            ));
50        }
51        if self.router.history_limit > 100 {
52            return Err(ConfigError::HistoryLimitTooLarge(self.router.history_limit));
53        }
54        if self.tiers.len() < 2 {
55            return Err(ConfigError::TooFewTiers);
56        }
57        if !self.tiers.contains_key(&self.router.fallback_tier) {
58            return Err(ConfigError::UnknownFallbackTier(
59                self.router.fallback_tier.clone(),
60            ));
61        }
62        if self
63            .tiers
64            .iter()
65            .any(|(name, tier)| name.trim().is_empty() || tier.description.trim().is_empty())
66        {
67            return Err(ConfigError::EmptyTier);
68        }
69        if self.jev.base_url.trim().is_empty() {
70            return Err(ConfigError::EmptyBaseUrl);
71        }
72        if self.jev.model.trim().is_empty() {
73            return Err(ConfigError::EmptyModel);
74        }
75        if self.jev.timeout_ms == 0 {
76            return Err(ConfigError::ZeroTimeout);
77        }
78        if self.cache.ttl_seconds == 0 {
79            return Err(ConfigError::ZeroCacheTtl);
80        }
81        if self.cache.ttl_seconds > 604_800 {
82            return Err(ConfigError::CacheTtlTooLarge(self.cache.ttl_seconds));
83        }
84        if self.cache.max_entries == 0 {
85            return Err(ConfigError::ZeroCacheEntries);
86        }
87        if self.cache.max_entries > 10_000 {
88            return Err(ConfigError::CacheEntriesTooLarge(self.cache.max_entries));
89        }
90        for (name, harness) in &self.harnesses {
91            harness.validate(name, self.tiers.keys())?;
92        }
93        Ok(())
94    }
95}
96
97impl Default for Config {
98    fn default() -> Self {
99        let tiers = [
100            (
101                "fast".to_owned(),
102                TierConfig {
103                    description: "Routine, mechanical, or narrowly scoped work with low ambiguity"
104                        .to_owned(),
105                },
106            ),
107            (
108                "balanced".to_owned(),
109                TierConfig {
110                    description:
111                        "Ordinary engineering work requiring moderate reasoning or repository context"
112                            .to_owned(),
113                },
114            ),
115            (
116                "strong".to_owned(),
117                TierConfig {
118                    description: "Ambiguous, high-risk, architectural, or deeply multi-step work"
119                        .to_owned(),
120                },
121            ),
122        ]
123        .into_iter()
124        .collect();
125
126        Self {
127            version: CONFIG_VERSION,
128            router: RouterConfig::default(),
129            jev: JevConfig::default(),
130            privacy: PrivacyConfig::default(),
131            storage: StorageConfig::default(),
132            cache: CacheConfig::default(),
133            tiers,
134            harnesses: BTreeMap::new(),
135        }
136    }
137}
138
139/// Opt-in persistence. Credentials are only resolved by the CLI at runtime.
140#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
141#[serde(tag = "backend", rename_all = "snake_case", deny_unknown_fields)]
142pub enum StorageConfig {
143    #[default]
144    Jsonl,
145    Sqlite {
146        url: String,
147    },
148    Postgres {
149        url_env: String,
150        project: String,
151        /// Development only: permit plaintext connections to a loopback host.
152        #[serde(default)]
153        allow_insecure_localhost: bool,
154    },
155}
156
157impl StorageConfig {
158    pub fn is_jsonl(&self) -> bool {
159        matches!(self, Self::Jsonl)
160    }
161
162    fn validate(&self) -> Result<(), ConfigError> {
163        match self {
164            Self::Jsonl => Ok(()),
165            Self::Sqlite { url } => {
166                let path = url.strip_prefix("sqlite://").filter(|s| !s.is_empty());
167                if path.is_none_or(|s| s.contains(['?', '#', '\0']) || s.contains(":memory:")) {
168                    return Err(ConfigError::InvalidStorage(
169                        "SQLite requires a persistent sqlite:// file URL without query parameters",
170                    ));
171                }
172                Ok(())
173            }
174            Self::Postgres {
175                url_env, project, ..
176            } => {
177                if url_env.is_empty()
178                    || !url_env.bytes().enumerate().all(|(i, c)| {
179                        c == b'_' || c.is_ascii_alphabetic() || (i > 0 && c.is_ascii_digit())
180                    })
181                {
182                    return Err(ConfigError::InvalidStorage(
183                        "url_env must name an environment variable, not contain a connection string",
184                    ));
185                }
186                if project.is_empty()
187                    || project.len() > 128
188                    || !project
189                        .bytes()
190                        .all(|c| c.is_ascii_alphanumeric() || b"-_.".contains(&c))
191                {
192                    return Err(ConfigError::InvalidStorage(
193                        "project must contain 1–128 letters, digits, dots, hyphens, or underscores",
194                    ));
195                }
196                Ok(())
197            }
198        }
199    }
200}
201
202/// Deterministic policy applied after Jev responds.
203#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
204#[serde(deny_unknown_fields)]
205pub struct RouterConfig {
206    /// Use the fallback tier below this confidence.
207    pub confidence_floor: f64,
208    /// Safe tier selected when Jev is uncertain.
209    pub fallback_tier: String,
210    /// Maximum number of recent completed outcomes supplied to Jev.
211    pub history_limit: usize,
212}
213
214impl Default for RouterConfig {
215    fn default() -> Self {
216        Self {
217            confidence_floor: 0.65,
218            fallback_tier: "strong".to_owned(),
219            history_limit: 20,
220        }
221    }
222}
223
224/// Connection settings for the Jev decision API.
225#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
226#[serde(deny_unknown_fields)]
227pub struct JevConfig {
228    /// API root without the `/v1/systemone` path.
229    pub base_url: String,
230    /// Jev model alias or pinned version.
231    pub model: String,
232    /// Request timeout in milliseconds.
233    pub timeout_ms: u64,
234}
235
236impl Default for JevConfig {
237    fn default() -> Self {
238        Self {
239            base_url: "https://api.typesafe.ai".to_owned(),
240            model: "jev-latest".to_owned(),
241            timeout_ms: 10_000,
242        }
243    }
244}
245
246/// Persistence controls for every history backend.
247#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
248#[serde(deny_unknown_fields)]
249pub struct PrivacyConfig {
250    /// Persist raw task text in the configured run history.
251    pub store_task_text: bool,
252}
253
254impl Default for PrivacyConfig {
255    fn default() -> Self {
256        Self {
257            store_task_text: true,
258        }
259    }
260}
261
262/// Local routing-decision cache controls.
263#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
264#[serde(deny_unknown_fields)]
265pub struct CacheConfig {
266    /// Reuse equivalent, unexpired Jev decisions.
267    pub enabled: bool,
268    /// Maximum age of a cached decision.
269    pub ttl_seconds: u64,
270    /// Maximum number of decisions retained locally.
271    pub max_entries: usize,
272}
273
274impl Default for CacheConfig {
275    fn default() -> Self {
276        Self {
277            enabled: true,
278            ttl_seconds: 900,
279            max_entries: 256,
280        }
281    }
282}
283
284/// A stable capability lane. Model names are deliberately kept out of this
285/// layer so harness adapters can map tiers independently.
286#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
287#[serde(deny_unknown_fields)]
288pub struct TierConfig {
289    pub description: String,
290}
291
292/// Process template and tier-to-model mapping for a coding-agent harness.
293/// Arguments are executed directly, never through a shell.
294#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
295#[serde(deny_unknown_fields)]
296pub struct HarnessConfig {
297    pub command: String,
298    pub args: Vec<String>,
299    pub models: BTreeMap<String, String>,
300    /// Opt in to root project tests when no explicit verifier is configured.
301    #[serde(default = "default_auto_verify")]
302    pub auto_verify: bool,
303    /// Passive event recording is enabled for supported harnesses by default.
304    #[serde(default)]
305    pub observations: crate::ObservationMode,
306    #[serde(default)]
307    pub verification: Option<VerificationConfig>,
308}
309
310fn default_auto_verify() -> bool {
311    false
312}
313
314/// Optional process that verifies a successful harness run.
315#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
316#[serde(deny_unknown_fields)]
317pub struct VerificationConfig {
318    pub command: String,
319    pub args: Vec<String>,
320}
321
322impl HarnessConfig {
323    fn validate<'a>(
324        &self,
325        name: &str,
326        tier_names: impl Iterator<Item = &'a String>,
327    ) -> Result<(), ConfigError> {
328        if name.trim().is_empty() {
329            return Err(ConfigError::EmptyHarnessName);
330        }
331        if self.command.trim().is_empty() {
332            return Err(ConfigError::EmptyHarnessCommand(name.to_owned()));
333        }
334        if !self.args.iter().any(|argument| argument.contains("{task}")) {
335            return Err(ConfigError::MissingHarnessPlaceholder {
336                harness: name.to_owned(),
337                placeholder: "{task}",
338            });
339        }
340        if !self
341            .args
342            .iter()
343            .any(|argument| argument.contains("{model}"))
344        {
345            return Err(ConfigError::MissingHarnessPlaceholder {
346                harness: name.to_owned(),
347                placeholder: "{model}",
348            });
349        }
350        for argument in &self.args {
351            validate_template(argument, name)?;
352        }
353        for tier in tier_names {
354            match self.models.get(tier) {
355                Some(model) if !model.trim().is_empty() => {}
356                _ => {
357                    return Err(ConfigError::MissingHarnessModel {
358                        harness: name.to_owned(),
359                        tier: tier.clone(),
360                    });
361                }
362            }
363        }
364        if let Some(verification) = &self.verification {
365            if verification.command.trim().is_empty() {
366                return Err(ConfigError::EmptyVerificationCommand(name.to_owned()));
367            }
368            for argument in &verification.args {
369                validate_template(argument, name)?;
370            }
371        }
372        Ok(())
373    }
374
375    /// Render a direct process invocation for a selected tier.
376    pub fn invocation(
377        &self,
378        harness_name: &str,
379        tier: &str,
380        task: &str,
381        run_id: &str,
382        extra_args: &[String],
383    ) -> Result<HarnessInvocation, ConfigError> {
384        let model = self
385            .models
386            .get(tier)
387            .filter(|model| !model.trim().is_empty())
388            .ok_or_else(|| ConfigError::MissingHarnessModel {
389                harness: harness_name.to_owned(),
390                tier: tier.to_owned(),
391            })?;
392        let mut args: Vec<_> = self
393            .args
394            .iter()
395            .map(|argument| render_argument(argument, harness_name, task, model, tier, run_id))
396            .collect::<Result<_, _>>()?;
397        args.extend_from_slice(extra_args);
398        let verification = match &self.verification {
399            Some(verification) => Some(VerificationInvocation {
400                program: verification.command.clone(),
401                args: verification
402                    .args
403                    .iter()
404                    .map(|argument| {
405                        render_argument(argument, harness_name, task, model, tier, run_id)
406                    })
407                    .collect::<Result<_, _>>()?,
408            }),
409            None => None,
410        };
411
412        Ok(HarnessInvocation {
413            program: self.command.clone(),
414            args,
415            model: model.clone(),
416            verification,
417        })
418    }
419}
420
421fn validate_template(argument: &str, harness_name: &str) -> Result<(), ConfigError> {
422    let remainder = argument
423        .replace("{task}", "")
424        .replace("{model}", "")
425        .replace("{tier}", "")
426        .replace("{run_id}", "");
427    if remainder.contains('{') || remainder.contains('}') {
428        return Err(ConfigError::UnknownHarnessPlaceholder {
429            harness: harness_name.to_owned(),
430            argument: argument.to_owned(),
431        });
432    }
433    Ok(())
434}
435
436fn render_argument(
437    template: &str,
438    harness_name: &str,
439    task: &str,
440    model: &str,
441    tier: &str,
442    run_id: &str,
443) -> Result<String, ConfigError> {
444    let mut rendered = String::with_capacity(template.len());
445    let mut cursor = 0;
446
447    while let Some(relative_start) = template[cursor..].find('{') {
448        let start = cursor + relative_start;
449        if template[cursor..start].contains('}') {
450            return Err(ConfigError::UnknownHarnessPlaceholder {
451                harness: harness_name.to_owned(),
452                argument: template.to_owned(),
453            });
454        }
455        rendered.push_str(&template[cursor..start]);
456        let relative_end =
457            template[start..]
458                .find('}')
459                .ok_or_else(|| ConfigError::UnknownHarnessPlaceholder {
460                    harness: harness_name.to_owned(),
461                    argument: template.to_owned(),
462                })?;
463        let end = start + relative_end + 1;
464        let value = match &template[start..end] {
465            "{task}" => task,
466            "{model}" => model,
467            "{tier}" => tier,
468            "{run_id}" => run_id,
469            _ => {
470                return Err(ConfigError::UnknownHarnessPlaceholder {
471                    harness: harness_name.to_owned(),
472                    argument: template.to_owned(),
473                });
474            }
475        };
476        rendered.push_str(value);
477        cursor = end;
478    }
479
480    if template[cursor..].contains('}') {
481        return Err(ConfigError::UnknownHarnessPlaceholder {
482            harness: harness_name.to_owned(),
483            argument: template.to_owned(),
484        });
485    }
486    rendered.push_str(&template[cursor..]);
487    Ok(rendered)
488}
489
490/// A shell-free process invocation rendered from a harness template.
491#[derive(Debug, Clone, PartialEq, Eq)]
492pub struct HarnessInvocation {
493    pub program: String,
494    pub args: Vec<String>,
495    /// Concrete model selected for this harness execution.
496    pub model: String,
497    pub verification: Option<VerificationInvocation>,
498}
499
500/// A shell-free verification process rendered from a harness template.
501#[derive(Debug, Clone, PartialEq, Eq)]
502pub struct VerificationInvocation {
503    pub program: String,
504    pub args: Vec<String>,
505}
506
507#[derive(Debug, Error)]
508pub enum ConfigError {
509    #[error("invalid storage configuration: {0}")]
510    InvalidStorage(&'static str),
511    #[error("could not parse configuration: {0}")]
512    Parse(#[from] toml::de::Error),
513    #[error("could not serialize configuration: {0}")]
514    Serialize(#[from] toml::ser::Error),
515    #[error("configuration version {0} is not supported")]
516    UnsupportedVersion(u32),
517    #[error("confidence_floor must be between 0 and 1, got {0}")]
518    InvalidConfidenceFloor(f64),
519    #[error("history_limit cannot exceed 100, got {0}")]
520    HistoryLimitTooLarge(usize),
521    #[error("at least two tiers are required")]
522    TooFewTiers,
523    #[error("fallback tier `{0}` is not defined")]
524    UnknownFallbackTier(String),
525    #[error("tier names and descriptions cannot be empty")]
526    EmptyTier,
527    #[error("Jev base_url cannot be empty")]
528    EmptyBaseUrl,
529    #[error("Jev model cannot be empty")]
530    EmptyModel,
531    #[error("Jev timeout_ms must be greater than zero")]
532    ZeroTimeout,
533    #[error("cache ttl_seconds must be greater than zero")]
534    ZeroCacheTtl,
535    #[error("cache ttl_seconds cannot exceed 604800, got {0}")]
536    CacheTtlTooLarge(u64),
537    #[error("cache max_entries must be greater than zero")]
538    ZeroCacheEntries,
539    #[error("cache max_entries cannot exceed 10000, got {0}")]
540    CacheEntriesTooLarge(usize),
541    #[error("harness names cannot be empty")]
542    EmptyHarnessName,
543    #[error("harness `{0}` command cannot be empty")]
544    EmptyHarnessCommand(String),
545    #[error("harness `{0}` verification command cannot be empty")]
546    EmptyVerificationCommand(String),
547    #[error("harness `{harness}` args must contain {placeholder}")]
548    MissingHarnessPlaceholder {
549        harness: String,
550        placeholder: &'static str,
551    },
552    #[error("harness `{harness}` argument contains an unknown placeholder: {argument}")]
553    UnknownHarnessPlaceholder { harness: String, argument: String },
554    #[error("harness `{harness}` does not map tier `{tier}` to a model")]
555    MissingHarnessModel { harness: String, tier: String },
556}
557
558#[cfg(test)]
559mod tests {
560    use super::*;
561
562    #[test]
563    fn storage_is_opt_in_and_round_trips_without_credentials() {
564        let old = Config::default().to_toml().unwrap();
565        assert!(!old.contains("[storage]"));
566        assert!(Config::from_toml(&old).unwrap().storage.is_jsonl());
567        for section in [
568            "\n[storage]\nbackend = 'sqlite'\nurl = 'sqlite://.jevia/jevia.db'\n",
569            "\n[storage]\nbackend = 'postgres'\nurl_env = 'JEVIA_DATABASE_URL'\nproject = 'my-project'\n",
570        ] {
571            let parsed = Config::from_toml(&format!("{old}{section}")).unwrap();
572            assert_eq!(
573                Config::from_toml(&parsed.to_toml().unwrap()).unwrap(),
574                parsed
575            );
576        }
577        for section in [
578            "\n[storage]\nbackend = 'mysql'\n",
579            "\n[storage]\nbackend = 'sqlite'\nurl = 'sqlite::memory:'\n",
580            "\n[storage]\nbackend = 'sqlite'\nurl = 'sqlite://file?mode=memory'\n",
581            "\n[storage]\nbackend = 'postgres'\nurl = 'postgres://user:password@localhost/db'\nproject = 'test'\n",
582            "\n[storage]\nbackend = 'postgres'\nurl_env = 'postgres://user:password@localhost/db'\nproject = 'test'\n",
583            "\n[storage]\nbackend = 'postgres'\nurl_env = 'JEVIA_DATABASE_URL'\nproject = ''\n",
584        ] {
585            assert!(Config::from_toml(&format!("{old}{section}")).is_err());
586        }
587    }
588
589    #[test]
590    fn default_config_round_trips() {
591        let expected = Config::default();
592        let rendered = expected.to_toml().expect("default config serializes");
593        let actual = Config::from_toml(&rendered).expect("rendered config parses");
594
595        assert_eq!(actual, expected);
596    }
597
598    #[test]
599    fn rejects_an_unknown_fallback_tier() {
600        let mut config = Config::default();
601        config.router.fallback_tier = "missing".to_owned();
602
603        assert!(matches!(
604            config.validate(),
605            Err(ConfigError::UnknownFallbackTier(tier)) if tier == "missing"
606        ));
607    }
608
609    #[test]
610    fn rejects_an_invalid_confidence_floor() {
611        let mut config = Config::default();
612        config.router.confidence_floor = 1.1;
613
614        assert!(matches!(
615            config.validate(),
616            Err(ConfigError::InvalidConfidenceFloor(value)) if value == 1.1
617        ));
618    }
619
620    #[test]
621    fn rejects_invalid_cache_limits() {
622        let mut config = Config::default();
623        config.cache.ttl_seconds = 0;
624        assert!(matches!(config.validate(), Err(ConfigError::ZeroCacheTtl)));
625
626        config.cache.ttl_seconds = 900;
627        config.cache.max_entries = 0;
628        assert!(matches!(
629            config.validate(),
630            Err(ConfigError::ZeroCacheEntries)
631        ));
632    }
633
634    #[test]
635    fn harness_invocation_substitutes_without_a_shell() {
636        let harness = HarnessConfig {
637            auto_verify: true,
638            observations: Default::default(),
639            command: "agent".to_owned(),
640            args: vec![
641                "run".to_owned(),
642                "--model={model}".to_owned(),
643                "{task}".to_owned(),
644                "--trace={run_id}".to_owned(),
645            ],
646            models: [("balanced".to_owned(), "provider/model".to_owned())]
647                .into_iter()
648                .collect(),
649            verification: Some(VerificationConfig {
650                command: "cargo".to_owned(),
651                args: vec![
652                    "test".to_owned(),
653                    "--package={tier}".to_owned(),
654                    "--trace={run_id}".to_owned(),
655                ],
656            }),
657        };
658        let extra = vec!["--verbose".to_owned()];
659
660        let invocation = harness
661            .invocation(
662                "agent",
663                "balanced",
664                "fix {model}; echo unsafe",
665                "run-1",
666                &extra,
667            )
668            .expect("invocation renders");
669
670        assert_eq!(invocation.program, "agent");
671        assert_eq!(invocation.model, "provider/model");
672        assert_eq!(
673            invocation.args,
674            [
675                "run",
676                "--model=provider/model",
677                "fix {model}; echo unsafe",
678                "--trace=run-1",
679                "--verbose",
680            ]
681        );
682        assert_eq!(
683            invocation.verification,
684            Some(VerificationInvocation {
685                program: "cargo".to_owned(),
686                args: vec![
687                    "test".to_owned(),
688                    "--package=balanced".to_owned(),
689                    "--trace=run-1".to_owned(),
690                ],
691            })
692        );
693    }
694
695    #[test]
696    fn additional_verification_is_opt_in() {
697        let raw = "command='agent'\nargs=['{model}', '{task}']\nmodels={fast='test'}\n";
698        let harness: HarnessConfig = toml::from_str(raw).unwrap();
699        assert!(!harness.auto_verify);
700        let enabled: HarnessConfig = toml::from_str(&format!("{raw}auto_verify=true\n")).unwrap();
701        assert!(enabled.auto_verify);
702        let disabled: HarnessConfig = toml::from_str(&format!("{raw}auto_verify=false\n")).unwrap();
703        assert!(!disabled.auto_verify);
704        assert!(toml::from_str::<HarnessConfig>(&format!("{raw}auto_verify='false'\n")).is_err());
705    }
706
707    #[test]
708    fn config_rejects_incomplete_harness_model_mappings() {
709        let mut config = Config::default();
710        config.harnesses.insert(
711            "agent".to_owned(),
712            HarnessConfig {
713                auto_verify: true,
714                observations: Default::default(),
715                command: "agent".to_owned(),
716                args: vec![
717                    "--model".to_owned(),
718                    "{model}".to_owned(),
719                    "{task}".to_owned(),
720                ],
721                models: [("fast".to_owned(), "small".to_owned())]
722                    .into_iter()
723                    .collect(),
724                verification: None,
725            },
726        );
727
728        assert!(matches!(
729            config.validate(),
730            Err(ConfigError::MissingHarnessModel { harness, tier })
731                if harness == "agent" && tier == "balanced"
732        ));
733    }
734
735    #[test]
736    fn invocation_rejects_unknown_placeholders_without_panicking() {
737        let harness = HarnessConfig {
738            auto_verify: true,
739            observations: Default::default(),
740            command: "agent".to_owned(),
741            args: vec!["{unknown}".to_owned()],
742            models: [("balanced".to_owned(), "provider/model".to_owned())]
743                .into_iter()
744                .collect(),
745            verification: None,
746        };
747
748        assert!(matches!(
749            harness.invocation("agent", "balanced", "task", "run-1", &[]),
750            Err(ConfigError::UnknownHarnessPlaceholder { harness, argument })
751                if harness == "agent" && argument == "{unknown}"
752        ));
753    }
754
755    #[test]
756    fn config_rejects_an_empty_verification_command() {
757        let mut config = Config::default();
758        config.harnesses.insert(
759            "agent".to_owned(),
760            HarnessConfig {
761                auto_verify: true,
762                observations: Default::default(),
763                command: "agent".to_owned(),
764                args: vec!["{model}".to_owned(), "{task}".to_owned()],
765                models: config
766                    .tiers
767                    .keys()
768                    .map(|tier| (tier.clone(), format!("provider/{tier}")))
769                    .collect(),
770                verification: Some(VerificationConfig {
771                    command: " ".to_owned(),
772                    args: vec![],
773                }),
774            },
775        );
776
777        assert!(matches!(
778            config.validate(),
779            Err(ConfigError::EmptyVerificationCommand(harness)) if harness == "agent"
780        ));
781    }
782
783    #[test]
784    fn config_rejects_unknown_verification_placeholders() {
785        let mut config = Config::default();
786        config.harnesses.insert(
787            "agent".to_owned(),
788            HarnessConfig {
789                auto_verify: true,
790                observations: Default::default(),
791                command: "agent".to_owned(),
792                args: vec!["{model}".to_owned(), "{task}".to_owned()],
793                models: config
794                    .tiers
795                    .keys()
796                    .map(|tier| (tier.clone(), format!("provider/{tier}")))
797                    .collect(),
798                verification: Some(VerificationConfig {
799                    command: "cargo".to_owned(),
800                    args: vec!["test".to_owned(), "{unknown}".to_owned()],
801                }),
802            },
803        );
804
805        assert!(matches!(
806            config.validate(),
807            Err(ConfigError::UnknownHarnessPlaceholder { harness, argument })
808                if harness == "agent" && argument == "{unknown}"
809        ));
810    }
811}