mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
The rules "an extension forces copy mode" and "symlink mode drops include/exclude" were re-implemented in the create, edit-target, and quick mode handlers. ExtraTargetConfig.EffectiveMode and Normalize now hold them in one place, and the handlers call those instead. API behavior is unchanged: edit-target still clears filters on symlink, quick mode still rejects symlink when the target has filters, and an extension still forces copy. Refs #488
77 lines
2.3 KiB
Go
77 lines
2.3 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestValidateExtraName(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
wantErr bool
|
|
}{
|
|
// valid names
|
|
{name: "rules", wantErr: false},
|
|
{name: "my-commands", wantErr: false},
|
|
{name: "team_prompts", wantErr: false},
|
|
{name: "a1", wantErr: false},
|
|
// reserved names
|
|
{name: "skills", wantErr: true},
|
|
{name: "extras", wantErr: true},
|
|
// empty
|
|
{name: "", wantErr: true},
|
|
// path traversal / invalid characters
|
|
{name: "../escape", wantErr: true},
|
|
{name: "has space", wantErr: true},
|
|
{name: "has/slash", wantErr: true},
|
|
{name: "-starts-dash", wantErr: true},
|
|
{name: "_starts-under", wantErr: true},
|
|
{name: ".hidden", wantErr: true},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
err := ValidateExtraName(tc.name)
|
|
if tc.wantErr && err == nil {
|
|
t.Errorf("ValidateExtraName(%q) = nil, want error", tc.name)
|
|
}
|
|
if !tc.wantErr && err != nil {
|
|
t.Errorf("ValidateExtraName(%q) = %v, want nil", tc.name, err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestValidateExtraName_NoDuplicate(t *testing.T) {
|
|
existing := []ExtraConfig{{Name: "rules"}}
|
|
|
|
if err := ValidateExtraNameUnique("rules", existing); err == nil {
|
|
t.Error("ValidateExtraNameUnique(\"rules\", existing) = nil, want error for duplicate")
|
|
}
|
|
|
|
if err := ValidateExtraNameUnique("commands", existing); err != nil {
|
|
t.Errorf("ValidateExtraNameUnique(\"commands\", existing) = %v, want nil", err)
|
|
}
|
|
}
|
|
|
|
func TestValidateExtraName_CaseOnlyDifferenceIsDuplicate(t *testing.T) {
|
|
if err := ValidateExtraNameUnique("Rules", []ExtraConfig{{Name: "rules"}}); err == nil {
|
|
t.Error("ValidateExtraNameUnique(\"Rules\", [rules]) = nil, want error")
|
|
}
|
|
}
|
|
|
|
func TestExtraTargetNormalize_ExtensionForcesCopy(t *testing.T) {
|
|
target := ExtraTargetConfig{Mode: "symlink", Extension: "x", Include: []string{"*.md"}}
|
|
target.Normalize()
|
|
if target.Mode != "copy" || len(target.Include) != 1 {
|
|
t.Errorf("got mode %q include %v, want copy with include kept", target.Mode, target.Include)
|
|
}
|
|
}
|
|
|
|
func TestExtraTargetNormalize_SymlinkDropsFilters(t *testing.T) {
|
|
target := ExtraTargetConfig{Mode: "symlink", Include: []string{"*.md"}, Exclude: []string{"a"}}
|
|
target.Normalize()
|
|
if target.Include != nil || target.Exclude != nil {
|
|
t.Errorf("got include %v exclude %v, want both dropped", target.Include, target.Exclude)
|
|
}
|
|
}
|