diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-11 08:49:20 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-11 08:49:20 +0300 |
| commit | a5bd7dd1eb63a2be332ecda50fbeccfe5d5de0a8 (patch) | |
| tree | de9986add3f31b6af8b00c1cf99c5237416d8ed1 /internal/appconfig/app_feature_sections_test.go | |
| parent | 133ef49de26ae251c2c86417f9c673ebc7166f76 (diff) | |
appconfig: split FeatureConfig into cohesive per-subsystem structs
The FeatureConfig section was a grab-bag mixing five unrelated non-LLM
subsystems (ignore filtering, stats, tmux popup editor, tmux action menu,
MCP server). Decompose it into named per-subsystem structs
(IgnoreConfig, StatsConfig, TmuxEditConfig, TmuxActionConfig, MCPConfig)
embedded into FeatureConfig so the subsystem boundaries are explicit.
Embedding keeps Go field promotion intact, so existing flat read access
(e.g. cfg.MCPPromptsDir) and the JSON/TOML on-disk shape are unchanged;
only composite literals that set these leaf fields directly were updated
to the nested form.
Add fine-grained, defensive-copy section accessors on App
(IgnoreSection, StatsSection, TmuxEditSection, TmuxActionSection,
MCPSection) so consumers can depend on a single subsystem's config
instead of the whole App God-struct. Decouple slashcommands.NewSyncer
to accept appconfig.MCPConfig rather than appconfig.App.
All tests pass with -race; appconfig coverage 91.5%, total 86.2%.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'internal/appconfig/app_feature_sections_test.go')
| -rw-r--r-- | internal/appconfig/app_feature_sections_test.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/internal/appconfig/app_feature_sections_test.go b/internal/appconfig/app_feature_sections_test.go new file mode 100644 index 0000000..1f9ac2d --- /dev/null +++ b/internal/appconfig/app_feature_sections_test.go @@ -0,0 +1,68 @@ +package appconfig + +import ( + "reflect" + "testing" +) + +// buildFeatureApp returns an App whose FeatureConfig subsystems are all +// populated, used to verify the fine-grained section accessors. +func buildFeatureApp() App { + cfg := App{} + cfg.ApplyFeatureSection(testFeatureConfig()) + return cfg +} + +func TestIgnoreSectionCopiesAndReads(t *testing.T) { + cfg := buildFeatureApp() + got := cfg.IgnoreSection() + if !reflect.DeepEqual(got.IgnoreExtraPatterns, []string{"vendor/**", "tmp/**"}) { + t.Fatalf("IgnoreExtraPatterns = %v", got.IgnoreExtraPatterns) + } + // Mutating the returned copy must not affect the source App. + got.IgnoreExtraPatterns[0] = "mutated" + if cfg.IgnoreExtraPatterns[0] == "mutated" { + t.Fatal("IgnoreSection did not return a defensive copy") + } +} + +func TestStatsSectionReads(t *testing.T) { + cfg := buildFeatureApp() + if got := cfg.StatsSection(); got.StatsWindowMinutes != 15 { + t.Fatalf("StatsWindowMinutes = %d, want 15", got.StatsWindowMinutes) + } +} + +func TestTmuxEditSectionCopies(t *testing.T) { + cfg := buildFeatureApp() + got := cfg.TmuxEditSection() + if got.TmuxEditDefaultAgent != "codex" || len(got.TmuxEditAgents) != 1 { + t.Fatalf("unexpected tmux edit section: %+v", got) + } + got.TmuxEditAgents[0].Name = "mutated" + if cfg.TmuxEditAgents[0].Name == "mutated" { + t.Fatal("TmuxEditSection did not return a defensive copy") + } +} + +func TestTmuxActionSectionCopies(t *testing.T) { + cfg := App{} + cfg.TmuxActionMenu = []TmuxActionMenuEntry{{Kind: "rewrite"}} + got := cfg.TmuxActionSection() + if len(got.TmuxActionMenu) != 1 || got.TmuxActionMenu[0].Kind != "rewrite" { + t.Fatalf("unexpected tmux action section: %+v", got) + } + got.TmuxActionMenu[0].Kind = "mutated" + if cfg.TmuxActionMenu[0].Kind == "mutated" { + t.Fatal("TmuxActionSection did not return a defensive copy") + } +} + +func TestMCPSectionReads(t *testing.T) { + cfg := buildFeatureApp() + got := cfg.MCPSection() + if got.MCPPromptsDir != ".hexai/prompts" || !got.MCPSlashCommandSync || + got.MCPSlashCommandDir != ".hexai/slash" { + t.Fatalf("unexpected MCP section: %+v", got) + } +} |
