mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 12:23:22 +00:00
Add ProjectSources struct to ProjectConfig with optional skills, agents,
and extras fields. When set, project-mode commands resolve source paths
from these values instead of hardcoded .skillshare/{skills,agents,extras}/.
Config example:
sources:
skills: ./docs/skills
agents: ./docs/agents
Three EffectiveXxxSource(projectRoot) methods provide the central
resolution logic with fallback to defaults. The projectRuntime gateway
and server layer route through these methods, so most commands get
custom source support automatically.
Closes #153
96 lines
2.9 KiB
Go
96 lines
2.9 KiB
Go
package config
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestExtrasSourceDirProject(t *testing.T) {
|
|
got := ExtrasSourceDirProject("/projects/myapp/.skillshare/extras", "rules")
|
|
want := filepath.Join("/projects/myapp/.skillshare/extras", "rules")
|
|
if got != want {
|
|
t.Errorf("ExtrasSourceDirProject() = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestResolveExtrasSourceDir_PerExtraSource(t *testing.T) {
|
|
extra := ExtraConfig{Name: "rules", Source: "/custom/rules"}
|
|
got := ResolveExtrasSourceDir(extra, "/global-extras", "/skills")
|
|
if got != "/custom/rules" {
|
|
t.Errorf("expected /custom/rules, got %s", got)
|
|
}
|
|
}
|
|
|
|
func TestResolveExtrasSourceDir_GlobalExtrasSource(t *testing.T) {
|
|
extra := ExtraConfig{Name: "rules"}
|
|
got := ResolveExtrasSourceDir(extra, "/global-extras", "/skills")
|
|
want := filepath.Join("/global-extras", "rules")
|
|
if got != want {
|
|
t.Errorf("expected %s, got %s", want, got)
|
|
}
|
|
}
|
|
|
|
func TestResolveExtrasSourceDir_Default(t *testing.T) {
|
|
extra := ExtraConfig{Name: "rules"}
|
|
got := ResolveExtrasSourceDir(extra, "", "/home/user/.config/skillshare/skills")
|
|
want := filepath.Join("/home/user/.config/skillshare", "extras", "rules")
|
|
if got != want {
|
|
t.Errorf("expected %s, got %s", want, got)
|
|
}
|
|
}
|
|
|
|
func TestResolveExtrasSourceDir_PerExtraOverridesAll(t *testing.T) {
|
|
extra := ExtraConfig{Name: "rules", Source: "/exact/path"}
|
|
got := ResolveExtrasSourceDir(extra, "/global-extras", "/skills")
|
|
if got != "/exact/path" {
|
|
t.Errorf("expected /exact/path, got %s", got)
|
|
}
|
|
}
|
|
|
|
func TestResolveExtrasSourceDir_EmptyExtrasSource(t *testing.T) {
|
|
extra := ExtraConfig{Name: "rules"}
|
|
got := ResolveExtrasSourceDir(extra, "", "/home/user/.config/skillshare/skills")
|
|
want := filepath.Join("/home/user/.config/skillshare", "extras", "rules")
|
|
if got != want {
|
|
t.Errorf("expected %s, got %s", want, got)
|
|
}
|
|
}
|
|
|
|
func TestResolveExtrasSourceDir_EmptyPerExtraSource(t *testing.T) {
|
|
extra := ExtraConfig{Name: "rules", Source: ""}
|
|
got := ResolveExtrasSourceDir(extra, "/global-extras", "/skills")
|
|
want := filepath.Join("/global-extras", "rules")
|
|
if got != want {
|
|
t.Errorf("expected %s, got %s", want, got)
|
|
}
|
|
}
|
|
|
|
func TestResolveExtrasSourceType(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
extra ExtraConfig
|
|
extrasSource string
|
|
want string
|
|
}{
|
|
{"per-extra", ExtraConfig{Source: "/custom"}, "/global", "per-extra"},
|
|
{"extras_source", ExtraConfig{}, "/global", "extras_source"},
|
|
{"default", ExtraConfig{}, "", "default"},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := ResolveExtrasSourceType(tt.extra, tt.extrasSource)
|
|
if got != tt.want {
|
|
t.Errorf("got %s, want %s", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestExtrasParentDir(t *testing.T) {
|
|
got := ExtrasParentDir("/home/user/.config/skillshare/skills")
|
|
want := filepath.Join("/home/user/.config/skillshare", "extras")
|
|
if got != want {
|
|
t.Errorf("ExtrasParentDir() = %q, want %q", got, want)
|
|
}
|
|
}
|