mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
fix(config): keep env-derived default skills paths on save (#662)
A pathless deepseek-harness or gitlab-duo target resolves its skills path from DSH_HOME, GLAB_CONFIG_DIR, or XDG_CONFIG_HOME, and the docs promise it keeps following those overrides. decodeConfig filled the omitted path in, though, and the next save (editing filters, changing mode) wrote it back as an explicit path, so later environment changes were ignored. Mark a default that came from targetConfigHome as derived, reusing the mechanism that already keeps config_dir paths out of the saved file. Closes #661 Release-As: 0.27.1
This commit is contained in:
@@ -185,8 +185,8 @@ func (c *Config) AddAgentConfigDirTarget(name, agent, dir, cli string) (string,
|
||||
return target.SkillsConfig().Path, nil
|
||||
}
|
||||
|
||||
// withoutDerivedPaths drops the paths expandAgentConfigDirs filled in, so they keep
|
||||
// following config_dir instead of being saved as written ones.
|
||||
// withoutDerivedPaths drops the paths filled in from config_dir or the environment, so
|
||||
// they keep following it instead of being saved as written ones.
|
||||
func (tc TargetConfig) withoutDerivedPaths() TargetConfig {
|
||||
strip := func(rc *ResourceTargetConfig, derived string) *ResourceTargetConfig {
|
||||
if rc == nil || derived == "" || rc.Path != derived {
|
||||
|
||||
@@ -168,7 +168,7 @@ type TargetConfig struct {
|
||||
Files []string `yaml:"files,omitempty"`
|
||||
|
||||
defaultTargetNaming string `yaml:"-"`
|
||||
// derivedSkills and derivedAgents are the paths expandAgentConfigDirs filled in.
|
||||
// derivedSkills and derivedAgents are the paths filled in from config_dir or the environment.
|
||||
derivedSkills, derivedAgents string `yaml:"-"`
|
||||
// projectRoot marks a target expanded from projects; see expandProjects.
|
||||
projectRoot string `yaml:"-"`
|
||||
@@ -838,6 +838,10 @@ func decodeConfig(path string, data []byte, persist bool) (*Config, error) {
|
||||
if target.SkillsConfig().Path == "" {
|
||||
if def, ok := defaults[name]; ok {
|
||||
target.EnsureSkills().Path = expandPath(def.Path)
|
||||
// A default from the environment keeps following it instead of being saved.
|
||||
if targetConfigHome(name, runtime.GOOS) != "" {
|
||||
target.derivedSkills = target.SkillsConfig().Path
|
||||
}
|
||||
}
|
||||
}
|
||||
cfg.Targets[name] = target
|
||||
|
||||
@@ -100,6 +100,23 @@ func TestTargets_ConfigHomeOverrides(t *testing.T) {
|
||||
if got := filepath.Clean(target.SkillsConfig().Path); got != filepath.Join(root, "pinned", "skills") {
|
||||
t.Errorf("explicit path = %q, want pinned path", got)
|
||||
}
|
||||
|
||||
// A pathless entry keeps following the override after a save.
|
||||
cfg, _, err = loadWithTargets(t, " "+tt.name+": {}\n")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := cfg.Save(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv(tt.env, filepath.Join(base, "moved"))
|
||||
if cfg, err = Load(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
target = cfg.Targets[tt.name]
|
||||
if got := target.SkillsConfig().Path; got != DefaultTargets()[tt.name].Path {
|
||||
t.Errorf("path after save = %q, want %q", got, DefaultTargets()[tt.name].Path)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user