mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
UI (Extras page): - Label per-target flatten/extension/mode controls with column headers - Render flatten as a dropdown so it matches the adjacent selects - Collapse the add-target form behind a button and widen the path input - Confirm before removing a target - Polish layout: tinted icon, inset source chip, hover rows, aligned columns Components: - Select: bound the dropdown width so long option descriptions wrap instead of stretching the popup across the page - Toast: render messages multi-line, widen the container, and give error/warning toasts more time to read Sync feedback: - Restructure extras sync-failure toasts into readable lines and fix the contradictory "N more errors" count (new nMoreErrors translation) CLI/server: - Match extra target paths by resolved absolute path (handles ~ vs /home) when adding, removing, or updating targets
89 lines
2.4 KiB
Go
89 lines
2.4 KiB
Go
package sync
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestPruneExtraTarget_MergeRemovesSymlinksOnly verifies that merge-mode prune
|
|
// deletes skillshare symlinks but preserves the user's own real files.
|
|
func TestPruneExtraTarget_MergeRemovesSymlinksOnly(t *testing.T) {
|
|
src := t.TempDir()
|
|
tgt := t.TempDir()
|
|
|
|
srcFile := filepath.Join(src, "a.md")
|
|
if err := os.WriteFile(srcFile, []byte("x"), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
link := filepath.Join(tgt, "a.md")
|
|
if err := os.Symlink(srcFile, link); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
local := filepath.Join(tgt, "local.md")
|
|
if err := os.WriteFile(local, []byte("keep"), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
pruned, errs := PruneExtraTarget(tgt, "merge")
|
|
if len(errs) != 0 {
|
|
t.Fatalf("unexpected errors: %v", errs)
|
|
}
|
|
if pruned != 1 {
|
|
t.Errorf("expected 1 pruned, got %d", pruned)
|
|
}
|
|
if _, err := os.Lstat(link); !os.IsNotExist(err) {
|
|
t.Error("symlink should have been removed")
|
|
}
|
|
if _, err := os.Stat(local); err != nil {
|
|
t.Error("user's local file must be preserved")
|
|
}
|
|
}
|
|
|
|
func TestPruneExtraTargetFiles_CopyRemovesManagedOnly(t *testing.T) {
|
|
tgt := t.TempDir()
|
|
|
|
managed := filepath.Join(tgt, "managed.md")
|
|
if err := os.WriteFile(managed, []byte("managed"), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
local := filepath.Join(tgt, "local.md")
|
|
if err := os.WriteFile(local, []byte("local"), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
pruned, errs := PruneExtraTargetFiles(tgt, "copy", map[string]bool{"managed.md": true})
|
|
if len(errs) != 0 {
|
|
t.Fatalf("unexpected errors: %v", errs)
|
|
}
|
|
if pruned != 1 {
|
|
t.Errorf("expected 1 pruned, got %d", pruned)
|
|
}
|
|
if _, err := os.Stat(managed); !os.IsNotExist(err) {
|
|
t.Errorf("managed file should have been removed, stat err = %v", err)
|
|
}
|
|
if _, err := os.Stat(local); err != nil {
|
|
t.Errorf("local file must be preserved, stat err = %v", err)
|
|
}
|
|
}
|
|
|
|
func TestPruneExtraTargetFiles_SymlinkRequiresSymlink(t *testing.T) {
|
|
tgt := t.TempDir()
|
|
local := filepath.Join(tgt, "local.md")
|
|
if err := os.WriteFile(local, []byte("local"), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
pruned, errs := PruneExtraTargetFiles(tgt, "symlink", nil)
|
|
if pruned != 0 {
|
|
t.Errorf("expected 0 pruned, got %d", pruned)
|
|
}
|
|
if len(errs) != 1 || !strings.Contains(errs[0], "target is not a symlink") {
|
|
t.Fatalf("expected target-is-not-symlink error, got %v", errs)
|
|
}
|
|
if _, err := os.Stat(local); err != nil {
|
|
t.Errorf("local file must be preserved, stat err = %v", err)
|
|
}
|
|
}
|