mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
Global sync created a missing extras source, project sync and `sync --all` skipped it, and the Web API created it while ignoring any MkdirAll error. Creating an empty source only hides a misconfigured path, so every caller now skips the extra and tells the user to create the directory. The Web API reports the hint in a new per-extra "warnings" field; existing response fields are unchanged.
58 lines
1.8 KiB
Go
58 lines
1.8 KiB
Go
package sync
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"skillshare/internal/config"
|
|
)
|
|
|
|
func runTestOptions() ExtraRunOptions {
|
|
return ExtraRunOptions{
|
|
ResolvePath: func(p string) string { return p },
|
|
ResolveExtension: func(ext string) (*ExtensionSpec, error) {
|
|
return nil, errors.New("no extension " + ext)
|
|
},
|
|
}
|
|
}
|
|
|
|
func TestRunExtraTargets_MissingSourceSkip(t *testing.T) {
|
|
src := filepath.Join(t.TempDir(), "missing")
|
|
extra := config.ExtraConfig{Name: "rules", Targets: []config.ExtraTargetConfig{{Path: t.TempDir()}}}
|
|
|
|
run := RunExtraTargets(extra, src, runTestOptions())
|
|
|
|
if !run.SourceMissing || len(run.Targets) != 0 {
|
|
t.Fatalf("expected skipped extra, got %+v", run)
|
|
}
|
|
if _, err := os.Stat(src); !os.IsNotExist(err) {
|
|
t.Errorf("source must not be created, stat err = %v", err)
|
|
}
|
|
}
|
|
|
|
func TestRunExtraTargets_SkipsAgentOverlap(t *testing.T) {
|
|
src, tgt := setupExtrasTest(t, map[string]string{"a.md": "a"})
|
|
extra := config.ExtraConfig{Name: "agents", Targets: []config.ExtraTargetConfig{{Path: tgt}}}
|
|
opts := runTestOptions()
|
|
opts.AgentTargetPaths = map[string]bool{filepath.Clean(tgt): true}
|
|
|
|
run := RunExtraTargets(extra, src, opts)
|
|
|
|
if got := run.Targets[0]; got.SkippedBy != "agents" || got.Result != nil {
|
|
t.Fatalf("expected target skipped by agents, got %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestRunExtraTargets_ReportsModeAndExtensionErrors(t *testing.T) {
|
|
src, tgt := setupExtrasTest(t, map[string]string{"a.md": "a"})
|
|
extra := config.ExtraConfig{Name: "rules", Targets: []config.ExtraTargetConfig{{Path: tgt, Mode: "merge", Extension: "x"}}}
|
|
|
|
got := RunExtraTargets(extra, src, runTestOptions()).Targets[0]
|
|
|
|
if got.ModeErr == nil || got.ExtensionErr == nil || got.Result != nil || got.Mode != "merge" {
|
|
t.Fatalf("expected both errors, no sync and configured mode, got %+v", got)
|
|
}
|
|
}
|