f99010fae1
Desktop Artifacts / Desktop Build (Linux) (push) Waiting to run
Desktop Artifacts / Desktop Build (Windows) (push) Waiting to run
Desktop Artifacts / Desktop Build (Linux (arm64)) (push) Waiting to run
Desktop Artifacts (macOS) / Desktop Build (macOS (aarch64)) (push) Waiting to run
Desktop Artifacts (macOS) / Desktop Build (macOS (x86_64)) (push) Waiting to run
CI / lint (push) Failing after 1s
CI / frontend (push) Failing after 1s
CI / scripts (push) Failing after 1s
CI / Go Test (ubuntu-latest) (push) Failing after 0s
CI / frontend-node-25 (push) Failing after 1s
CI / docs (push) Failing after 0s
CI / coverage (push) Failing after 0s
CI / e2e (push) Failing after 0s
Docker / build-and-push (push) Failing after 1s
CI / integration (push) Failing after 4m43s
CI / Go Test (windows-latest) (push) Has been cancelled
CI / Desktop Unit Tests (Windows) (push) Has been cancelled
57 lines
2.1 KiB
Go
57 lines
2.1 KiB
Go
package sync
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestChangedPathWithinRoot(t *testing.T) {
|
|
sep := string(filepath.Separator)
|
|
cases := []struct {
|
|
name string
|
|
path string
|
|
root string
|
|
want bool
|
|
}{
|
|
{"exact root", "/home/u/.claude/projects", "/home/u/.claude/projects", true},
|
|
{"nested file", "/home/u/.claude/projects/p/s.jsonl", "/home/u/.claude/projects", true},
|
|
{"deeply nested", "/home/u/.claude/projects/p/sub/agents/a.jsonl", "/home/u/.claude/projects", true},
|
|
{"sibling sharing prefix", "/home/u/.claude-backup/s.jsonl", "/home/u/.claude", false},
|
|
{"outside root", "/home/u/.cortex/sessions/s.jsonl", "/home/u/.claude/projects", false},
|
|
{"root with trailing separator", "/home/u/.gemini/tmp/s.json", "/home/u/.gemini/tmp" + sep, true},
|
|
{"dot segments resolving inside", "/home/u/.claude/x/../projects/s.jsonl", "/home/u/.claude/projects", true},
|
|
{"dot segments resolving outside", "/home/u/.claude/projects/../../other/s.jsonl", "/home/u/.claude/projects", false},
|
|
{"archive member form", "/home/u/ws/state.vscdb#session-1", "/home/u/ws", true},
|
|
{"root itself archive-suffixed", "/home/u/ws#member", "/home/u/ws", true},
|
|
{"empty root", "/home/u/x", "", false},
|
|
{"dot root", "/home/u/x", ".", false},
|
|
{"filesystem root", "/home/u/x", sep, true},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
path := filepath.FromSlash(strings.ReplaceAll(tc.path, "/", sep))
|
|
root := tc.root
|
|
if root != "" && root != "." && root != sep {
|
|
root = filepath.FromSlash(strings.ReplaceAll(root, "/", sep))
|
|
}
|
|
assert.Equal(t, tc.want, changedPathWithinRoot(path, root))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestChangedPathWithinAnyRoot(t *testing.T) {
|
|
roots := []string{
|
|
filepath.FromSlash("/home/u/.claude/projects"),
|
|
filepath.FromSlash("/home/u/.config/opencode"),
|
|
}
|
|
assert.True(t, changedPathWithinAnyRoot(
|
|
filepath.FromSlash("/home/u/.config/opencode/storage/s.json"), roots))
|
|
assert.False(t, changedPathWithinAnyRoot(
|
|
filepath.FromSlash("/home/u/.cortex/s.jsonl"), roots))
|
|
assert.False(t, changedPathWithinAnyRoot(
|
|
filepath.FromSlash("/home/u/.cortex/s.jsonl"), nil))
|
|
}
|