feat(config): TOML configuration loading with defaults #27
Labels
No labels
area:config
area:contracts
area:engine
area:eventsourcing
area:frontend
area:git
area:ipc
area:persistence
area:provider
area:scaffold
area:terminal
type:user-story
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
charles/peon!27
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "dev/3"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
AppConfig,GeneralConfig,ProvidersConfig,TerminalConfig,EmbeddedTerminalConfig,GitConfigstructs with#[serde(default)]on every field/sectionTerminalModeenum (auto|embedded|kitty|foot) withAutoas defaultConfigError(NoConfigDir,Io,Parse) usingthiserrorload_config(): reads~/.config/forge-agent/config.toml, writes the bundled default on first runconfig_path()helper returning the canonical pathcrates/backend/default_config.tomlviainclude_str!Closes #3
Two acceptance criteria from issue #3 are not met, plus a minor correctness issue in the loading logic.
Blocking:
data_dirtilde expansion is missing (explicit AC item)Non-blocking:
3. TOCTOU race in
load_config()— see inline commentThe struct definitions, defaults, TOML bundling, and the other 6 tests all look correct."
@ -2,0 +34,4 @@impl Default for GeneralConfig {fn default() -> Self {Self {data_dir: "~/.local/share/forge-agent".to_string(),Missing acceptance criterion:
data_dirtilde expansion.The issue explicitly requires: "
data_dirpath with~is expanded to actual home directory". Right nowdata_diris stored as the raw string"~/.local/share/forge-agent"and nothing ever expands it. Any caller passing this tostd::fswill get aNo such file or directoryerror because~is a shell convention, not an OS one.Fix: either expand eagerly in
load_config()after parsing, or expose a method onGeneralConfig:The eager-expansion approach (rewriting
data_dirto the expanded path inload_config()before returning) is also fine and keeps the type simple.@ -2,0 +160,4 @@#[test]fn default_providers_config() {let cfg = ProvidersConfig::default();TOCTOU race:
path.exists()thenread_to_string.The file could be deleted between the
exists()check and theread_to_stringcall, turning a handledNotFoundinto a spuriousIoerror. The idiomatic fix is to attempt the read and branch on the error kind:This also removes the redundant
path.exists()call.@ -2,0 +250,4 @@assert_eq!(cfg.git.commit_name, "forge-agent");assert!(cfg.git.auto_checkpoint);}}Missing acceptance criterion: test for invalid TOML producing a clear error.
The issue lists: "Test: invalid TOML produces a clear error message". There is no such test in this PR.
Add one:
This directly covers the AC item and confirms
ConfigError::Parsecarries a useful message.Pull request closed