fix(config): expand plugin, module and skills dirs like every other operator path

applyGeneralDefaults home-expanded secret_engine_dir, work_dir, state_dir and
chat.workspace but not plugin_dir, module_dir or skills_dir, while
config.example.toml tells operators to write all four as
~/.local/share/archie/<dir>. A literal "~" is not a directory: plugin.LoadDir
returns an empty set for it, loadModules finds no kind file, and skill
discovery falls back to the built-ins, all without an error naming the
mistake. Expand the three in the same place as the rest, so a value the
example advertises resolves to the directory the operator meant.

Test first: TestLoadExpandsConfiguredHomePaths gains the three fields (and
pins HOME to a temp dir instead of the runner's real one); it failed on the
three new assertions before this change.

No validator is added alongside: see the plugin-settings decision record for
why these four directories stay free-form.

Refs #1143
This commit is contained in:
sam committed 2026-09-30 11:37:00 +10:00
1 parent 9f6eaccd71
commit abb5b747df
2 files changed
+16 -4

No files matched your search

@@ -223,6 +223,9 @@ func DefaultConfigPath() string {
// section.
func (l *Loader) applyGeneralDefaults(cfg *config.Config) {
cfg.SecretEngineDir = expandHomePath(cfg.SecretEngineDir)
cfg.PluginDir = expandHomePath(cfg.PluginDir)
cfg.ModuleDir = expandHomePath(cfg.ModuleDir)
cfg.SkillsDir = expandHomePath(cfg.SkillsDir)
cfg.WorkDir = expandHomePath(cfg.WorkDir)
cfg.StateDir = expandHomePath(cfg.StateDir)
cfg.Chat.Workspace = expandHomePath(cfg.Chat.Workspace)
@@ -42,16 +42,17 @@ func TestLoadDispatchAckReaction(t *testing.T) {
}
func TestLoadExpandsConfiguredHomePaths(t *testing.T) {
home, err := os.UserHomeDir()
if err != nil {
t.Fatal(err)
}
home := t.TempDir()
t.Setenv("HOME", home)
path := filepath.Join(t.TempDir(), "config.toml")
contents := `
bot_user = "widget"
work_dir = "~/archie/work"
state_dir = "~/archie/state"
plugin_dir = "~/archie/plugins"
module_dir = "~/archie/modules"
skills_dir = "~/archie/skills"
[chat]
workspace = "~/archie/workspace"
@@ -75,6 +76,14 @@ name = "app"
"work_dir": {got: cfg.WorkDir, want: filepath.Join(home, "archie", "work")},
"state_dir": {got: cfg.StateDir, want: filepath.Join(home, "archie", "state")},
"chat.workspace": {got: cfg.Chat.Workspace, want: filepath.Join(home, "archie", "workspace")},
// The operator-facing plugin, module and skills directories take the
// same ~ as every other path in the file: config.example.toml tells
// operators to write them that way, and a value that stays literal is
// a directory that silently does not exist (no plugins load, no
// modules load, no skills beyond the built-ins).
"plugin_dir": {got: cfg.PluginDir, want: filepath.Join(home, "archie", "plugins")},
"module_dir": {got: cfg.ModuleDir, want: filepath.Join(home, "archie", "modules")},
"skills_dir": {got: cfg.SkillsDir, want: filepath.Join(home, "archie", "skills")},
}
for name, tt := range wants {
t.Run(name, func(t *testing.T) {