Files
skillshare/tests/integration/sync_test.go
T
1419b62499 fix(sync): never delete or re-point entries skillshare did not create (#914)
* fix(sync): never delete or re-point entries skillshare did not create

On Windows, a plain `init` followed by `sync` deleted things in
~/.claude/skills that skillshare never created, with no backup and no
prompt. It also re-pointed another tool's junction. Seen in a sandbox
run of v0.30.7:

- prune removed real folders whose names only look like skillshare's
  flat naming (team__shared, _drafts), via the name heuristic
- prune removed a broken link that another tool or the user made
- merge sync deleted and re-created a same-name link that pointed into
  another manager's store
- init's import deleted original folders that matched the source
  byte for byte

The manifest already records what skillshare made, so use it:

- prune keeps a look-alike folder that is not in the manifest and warns
  once per sync; --force still removes it
- prune removes a broken external link only if the manifest records it
  (e.g. after the source moved); otherwise it keeps the link and warns
- merge sync re-points a link only if the manifest records it or it
  already points into the source; otherwise it reports the entry as
  kept local, as it already does for a real folder; --force replaces it
- init's import moves identical copies to the trash under
  replaced-by-init/<target>/ instead of deleting them

Tests: ownership_test.go adds regression tests that use createLink, so
they run on Windows without Developer Mode (junctions). The 4 keep
tests fail without this change. TestSyncTargetMerge_FixesBrokenLink now
records the link in the manifest first, since a same-name link that
skillshare did not make is no longer re-pointed. Existing tests in
internal/sync, internal/trash and cmd/skillshare show the same failures
on a Windows host with and without the change (symlink privilege). The
devcontainer suite has not been run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: say what sync and init keep when skillshare did not create it

The previous commit makes sync and init leave alone entries skillshare
did not create. Update the pages that describe that behaviour:

- sync-modes: merge mode keeps a same-name link from another tool and
  reports it as local; orphan cleanup keeps folders that only look like
  skillshare's flat names, and broken links outside the source that the
  manifest does not record. sync --force still removes them.
- init: identical folders replaced with links during the first sync go
  to the trash first (replaced-by-init/<tool>/, cleaned after 7 days).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(sourcefs): drop the raw-write allowance replaceIdenticalCopies no longer needs

replaceIdenticalCopies now moves an identical copy to the trash instead
of calling os.RemoveAll, so TestRawWriteRatchet reports its allowance as
stale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(sync): apply the ownership rule at every consumer

Review of the first commit found places that still did, or predicted,
the old behaviour. One rule now decides whether a link is skillshare's:
Manifest.OwnsLink (the manifest records a link there, or it points into
the source). It compares canonical paths, so a source reached through an
alias and a relative project link still count as skillshare's.

- copy mode kept re-pointing: it removed any same-name link and wrote a
  copy. It now keeps a link it does not own, like merge mode.
- the dashboard diff predicted a prune for a folder that is only named
  like skillshare's, and an update for another tool's link. It now
  reports them as local and kept. The orphan-link prediction uses the
  same rule as prune.
- `diff` reported a target as in sync while sync printed "kept local"
  for another tool's link. It lists the link as a local override.
- doctor reported a broken link skillshare did not create as an error
  and suggested `skillshare sync`, which now keeps it. It is a warning
  with its own row, and `broken_symlinks` is `warning` in --json.
- `trash restore` put a folder init had replaced into the source as a
  new nested skill. Restore refuses entries under replaced-by-init/ and
  names the trash folder to copy from.
- init reported a folder it could not move to the trash as one that
  differs from the source, and dropped the error. It is reported
  separately, with the error.
- the PruneOptions.ManagedOnly comment still said broken external links
  are skipped; manifest-recorded ones are removed.

Tests cover the states the review listed: a source behind an alias, a
relative project link, ManagedOnly, standard naming, dry run with
--force, and a recorded copy the user replaced with a link.
TestSync_Pruning_RemovesBrokenExternalSymlinks passed without testing
anything, because FileExists follows links; it is now two tests that
use Lstat, one per owner.

Agent merge is unchanged: agents have no link manifest.

* fix(diff): list another tool's link as kept in copy mode too

Copy mode now keeps a same-name link skillshare did not create, but both
diffs read the entry with os.Stat. A broken link showed as a skill to
add on every run, and a live one as a plain local copy, while sync kept
both and said "kept local".

`diff` and the dashboard diff check the link first and report it the way
merge mode does: a local override, kept until --force.

* test(sync): make the aliased-source link while its folder exists

TestSyncMergeRepointsUnrecordedLinkIntoAliasedSource failed on Windows:
it linked straight to a missing folder, and a junction cannot be made
to one. It now links first and removes the folder after, like the other
broken-link tests in this file.

* fix(sync): compare a broken link by where it would point

linksIntoSource resolved both paths with EvalSymlinks, which gives up on
a path that does not exist. A broken link is exactly that, so a link
into a source reached through an alias (a symlinked config folder, or a
short 8.3 path on Windows) compared an unresolved path with a resolved
one and was taken for another tool's link. Sync then kept it instead of
repairing or pruning it.

It now uses sourcewalk.Canonical, which resolves the nearest folder that
exists and keeps the missing tail. The test covers both spellings: the
alias in the link, and the alias in the configured source.

* fix(init): report what the first sync kept, and match prune in the diff

Two previews said less, or more, than sync does.

init ran its first sync quietly and printed only "Synced". Sync now keeps
a link another tool put on a skill's name, a folder that is only named
like skillshare's, and a broken link it did not create, so the skill was
reported as synced while the tool still loaded the other copy. firstSync
returns the warnings a plain sync prints, and init shows them. They
already name the folders that differ from the source, so the separate
list of those is gone.

The dashboard diff counted an orphan link as a removal whenever the
manifest recorded it. Prune keeps a recorded link that still resolves
outside the source (the source moved and the old checkout stayed), so
the Sync page showed a removal that never happened. The diff now uses
prune's own rule: a link into the source goes when broken or recorded;
any other link only when broken and recorded.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Willie <egg358358@gmail.com>
2026-11-17 04:15:04 +08:00

715 lines
20 KiB
Go

//go:build !online
package integration
import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
"skillshare/internal/testutil"
)
func TestSync_MergeMode_CreatesSymlinks(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
// Create a skill in source
sb.CreateSkill("my-skill", map[string]string{
"SKILL.md": "# My Skill\n\nDescription here.",
})
// Create target directory
targetPath := sb.CreateTarget("claude")
// Write config
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
claude:
path: ` + targetPath + `
`)
result := sb.RunCLI("sync")
result.AssertSuccess(t)
result.AssertRowContains(t, "claude", "1 linked")
// Verify symlink was created
skillLink := filepath.Join(targetPath, "my-skill")
if !sb.IsSymlink(skillLink) {
t.Error("skill should be a symlink")
}
expectedTarget := filepath.Join(sb.SourcePath, "my-skill")
if got := sb.SymlinkTarget(skillLink); got != expectedTarget {
t.Errorf("symlink target = %q, want %q", got, expectedTarget)
}
}
func TestSync_DryRun_NoChanges(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("test-skill", map[string]string{
"SKILL.md": "# Test",
})
targetPath := sb.CreateTarget("claude")
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
claude:
path: ` + targetPath + `
`)
// Record initial state
entriesBefore, _ := os.ReadDir(targetPath)
// Execute with --dry-run
result := sb.RunCLI("sync", "--dry-run")
result.AssertSuccess(t)
result.AssertOutputContains(t, "Dry run")
// Verify no changes made
entriesAfter, _ := os.ReadDir(targetPath)
if len(entriesAfter) != len(entriesBefore) {
t.Error("dry-run should not modify file system")
}
}
func TestSync_NoConfig_ReturnsError(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
// Remove config file
os.Remove(sb.ConfigPath)
result := sb.RunCLI("sync")
result.AssertFailure(t)
result.AssertAnyOutputContains(t, "init")
}
func TestSync_SourceNotExist_ReturnsError(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
// Config points to non-existent source
targetPath := sb.CreateTarget("claude")
sb.WriteConfig(`source: /nonexistent/path
targets:
claude:
path: ` + targetPath + `
`)
result := sb.RunCLI("sync")
result.AssertFailure(t)
result.AssertAnyOutputContains(t, "source path does not exist")
}
func TestSync_GlobalDefaultSourceWhenOmitted(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("default-source-skill", map[string]string{
"SKILL.md": "# Default Source Skill",
})
targetPath := sb.CreateTarget("claude")
sb.WriteConfig(`targets:
claude:
skills:
path: ` + targetPath + `
`)
result := sb.RunCLI("sync", "--global")
result.AssertSuccess(t)
if !sb.IsSymlink(filepath.Join(targetPath, "default-source-skill")) {
t.Error("skill from default source should be synced")
}
}
func TestSync_SymlinkMode_CreatesSingleSymlink(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("skill1", map[string]string{"SKILL.md": "# Skill 1"})
sb.CreateSkill("skill2", map[string]string{"SKILL.md": "# Skill 2"})
targetPath := sb.CreateTarget("claude")
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets:
claude:
path: ` + targetPath + `
mode: symlink
`)
result := sb.RunCLI("sync")
result.AssertSuccess(t)
// Verify target is a symlink to source
if !sb.IsSymlink(targetPath) {
t.Error("target should be a symlink")
}
if got := sb.SymlinkTarget(targetPath); got != sb.SourcePath {
t.Errorf("symlink target = %q, want %q", got, sb.SourcePath)
}
}
func TestSync_MultipleTargets_SyncsAll(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("common-skill", map[string]string{
"SKILL.md": "# Common Skill",
})
claudePath := sb.CreateTarget("claude")
codexPath := sb.CreateTarget("codex")
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
claude:
path: ` + claudePath + `
codex:
path: ` + codexPath + `
`)
result := sb.RunCLI("sync")
result.AssertSuccess(t)
// Verify skill synced to both targets
if !sb.IsSymlink(filepath.Join(claudePath, "common-skill")) {
t.Error("skill should be synced to claude")
}
if !sb.IsSymlink(filepath.Join(codexPath, "common-skill")) {
t.Error("skill should be synced to codex")
}
}
func TestSync_TrackedRepoSkills_HiddenDirs(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
// Simulate a tracked repo with skills inside hidden directories (like openai/skills)
// Structure: _openai-skills/.curated/pdf/SKILL.md
// _openai-skills/.system/figma/SKILL.md
sb.CreateNestedSkill("_openai-skills/.curated/pdf", map[string]string{
"SKILL.md": "# PDF",
})
sb.CreateNestedSkill("_openai-skills/.system/figma", map[string]string{
"SKILL.md": "# Figma",
})
targetPath := sb.CreateTarget("claude")
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
claude:
path: ` + targetPath + `
`)
result := sb.RunCLI("sync")
result.AssertSuccess(t)
// Verify skills inside hidden dirs are discovered and synced
pdfLink := filepath.Join(targetPath, "_openai-skills__.curated__pdf")
if !sb.IsSymlink(pdfLink) {
t.Errorf("skill inside .curated/ should be synced: %s", pdfLink)
}
figmaLink := filepath.Join(targetPath, "_openai-skills__.system__figma")
if !sb.IsSymlink(figmaLink) {
t.Errorf("skill inside .system/ should be synced: %s", figmaLink)
}
}
func TestSync_Pruning_RemovesOrphanLinks(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
// Create initial skills
sb.CreateSkill("skill-a", map[string]string{"SKILL.md": "# Skill A"})
sb.CreateSkill("skill-b", map[string]string{"SKILL.md": "# Skill B"})
sb.CreateNestedSkill("nested/skill-c", map[string]string{"SKILL.md": "# Skill C"})
targetPath := sb.CreateTarget("claude")
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
claude:
path: ` + targetPath + `
`)
// First sync - creates all symlinks
result := sb.RunCLI("sync")
result.AssertSuccess(t)
// Verify all symlinks exist
if !sb.IsSymlink(filepath.Join(targetPath, "skill-a")) {
t.Error("skill-a should be a symlink")
}
if !sb.IsSymlink(filepath.Join(targetPath, "skill-b")) {
t.Error("skill-b should be a symlink")
}
if !sb.IsSymlink(filepath.Join(targetPath, "nested__skill-c")) {
t.Error("nested__skill-c should be a symlink")
}
// Remove skill-b from source
os.RemoveAll(filepath.Join(sb.SourcePath, "skill-b"))
// Second sync - should prune skill-b
result = sb.RunCLI("sync")
result.AssertSuccess(t)
result.AssertOutputContains(t, "pruned")
// Verify skill-b is removed, others remain
if !sb.IsSymlink(filepath.Join(targetPath, "skill-a")) {
t.Error("skill-a should still be a symlink")
}
if sb.FileExists(filepath.Join(targetPath, "skill-b")) {
t.Error("skill-b should have been pruned")
}
if !sb.IsSymlink(filepath.Join(targetPath, "nested__skill-c")) {
t.Error("nested__skill-c should still be a symlink")
}
}
func TestSync_PreservesRegistryEntries(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
// Create a local skill that sync will discover
sb.CreateSkill("local-skill", map[string]string{"SKILL.md": "# Local"})
targetPath := sb.CreateTarget("claude")
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
claude:
path: ` + targetPath + `
`)
// Write a registry with a remote-installed skill that has NO files on disk.
// Sync must NOT prune this entry — registry is the source of truth for installations.
registryPath := filepath.Join(sb.SourcePath, "registry.yaml")
registryContent := "skills:\n - name: remote-tool\n source: github.com/someone/remote-tool\n"
os.WriteFile(registryPath, []byte(registryContent), 0644)
result := sb.RunCLI("sync")
result.AssertSuccess(t)
// Verify registry still contains the remote-tool entry
data, err := os.ReadFile(registryPath)
if err != nil {
t.Fatalf("failed to read registry: %v", err)
}
content := string(data)
if !strings.Contains(content, "remote-tool") {
t.Errorf("sync should preserve registry entry for installed skill without local files, got:\n%s", content)
}
}
func TestSync_Pruning_RemovesExcludedSourceLinkedSkill(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("keep-me", map[string]string{"SKILL.md": "# Keep"})
sb.CreateSkill("exclude-me", map[string]string{"SKILL.md": "# Exclude"})
targetPath := sb.CreateTarget("claude")
// Initial sync with no filters so both links exist.
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
claude:
path: ` + targetPath + `
`)
sb.RunCLI("sync").AssertSuccess(t)
// Add an exclude filter and sync again.
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
claude:
path: ` + targetPath + `
exclude: [exclude-*]
`)
result := sb.RunCLI("sync")
result.AssertSuccess(t)
if !sb.IsSymlink(filepath.Join(targetPath, "keep-me")) {
t.Error("non-excluded skill should stay synced")
}
if sb.FileExists(filepath.Join(targetPath, "exclude-me")) {
t.Error("excluded source-linked skill should be removed by sync")
}
}
func TestSync_Pruning_PreservesExcludedSourceLocalCopy(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("exclude-me", map[string]string{"SKILL.md": "# Source"})
targetPath := sb.CreateTarget("claude")
// Create local copy in target (not symlink)
localSkillPath := filepath.Join(targetPath, "exclude-me")
if err := os.MkdirAll(localSkillPath, 0755); err != nil {
t.Fatalf("failed to create local skill dir: %v", err)
}
if err := os.WriteFile(filepath.Join(localSkillPath, "SKILL.md"), []byte("# Local"), 0644); err != nil {
t.Fatalf("failed to write local skill: %v", err)
}
// First sync keeps local copy (no force).
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
claude:
path: ` + targetPath + `
`)
sb.RunCLI("sync").AssertSuccess(t)
if !sb.FileExists(localSkillPath) {
t.Fatal("local copy should exist before exclude")
}
// Add exclude and sync again - local copy should stay.
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
claude:
path: ` + targetPath + `
exclude: [exclude-*]
`)
result := sb.RunCLI("sync")
result.AssertSuccess(t)
if !sb.FileExists(localSkillPath) {
t.Error("excluded source skill local copy should be preserved")
}
}
// A broken link that points outside the source and that skillshare did not
// create belongs to another tool or the user, so sync keeps it.
func TestSync_Pruning_KeepsBrokenExternalSymlinkItDidNotCreate(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("skill-a", map[string]string{"SKILL.md": "# Skill A"})
targetPath := sb.CreateTarget("claude")
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
claude:
path: ` + targetPath + `
`)
sb.RunCLI("sync").AssertSuccess(t)
foreign := filepath.Join(targetPath, "other-tool-skill")
if err := os.Symlink(filepath.Join(sb.Home, "other-tool", "skills", "gone"), foreign); err != nil {
t.Fatal(err)
}
result := sb.RunCLI("sync")
result.AssertSuccess(t)
// IsSymlink uses Lstat; FileExists follows the link and is false for a broken one.
if !sb.IsSymlink(foreign) {
t.Error("broken link skillshare did not create should be kept")
}
result.AssertAnyOutputContains(t, "skillshare did not create")
if !sb.IsSymlink(filepath.Join(targetPath, "skill-a")) {
t.Error("skill-a should still be a symlink")
}
}
// After the source moves, the links sync made earlier point into the old
// location. The manifest records them, so sync removes the ones left broken.
func TestSync_Pruning_RemovesBrokenExternalSymlinkItCreated(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("skill-a", map[string]string{"SKILL.md": "# Skill A"})
sb.CreateSkill("migrated-skill", map[string]string{"SKILL.md": "# Migrated"})
targetPath := sb.CreateTarget("claude")
config := func(source string) string {
return `source: ` + source + `
mode: merge
targets:
claude:
path: ` + targetPath + `
`
}
sb.WriteConfig(config(sb.SourcePath))
sb.RunCLI("sync").AssertSuccess(t)
// The source moves, and migrated-skill does not come along.
newSource := filepath.Join(sb.Home, "new-source")
if err := os.MkdirAll(filepath.Join(newSource, "skill-a"), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(newSource, "skill-a", "SKILL.md"), []byte("# Skill A"), 0o644); err != nil {
t.Fatal(err)
}
if err := os.RemoveAll(sb.SourcePath); err != nil {
t.Fatal(err)
}
sb.WriteConfig(config(newSource))
migrated := filepath.Join(targetPath, "migrated-skill")
if !sb.IsSymlink(migrated) {
t.Fatal("setup: migrated-skill should be a broken link into the old source")
}
sb.RunCLI("sync").AssertSuccess(t)
if _, err := os.Lstat(migrated); !os.IsNotExist(err) {
t.Errorf("broken link recorded in the manifest should be pruned: %v", err)
}
if !sb.FileExists(filepath.Join(targetPath, "skill-a", "SKILL.md")) {
t.Error("skill-a should be re-pointed to the new source")
}
}
func TestSync_Pruning_ForceRemovesExternalSymlinks(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("skill-a", map[string]string{"SKILL.md": "# Skill A"})
targetPath := sb.CreateTarget("claude")
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
claude:
path: ` + targetPath + `
`)
result := sb.RunCLI("sync")
result.AssertSuccess(t)
// Create a valid external symlink (target exists but outside source dir)
externalDir := filepath.Join(sb.Home, "external-skills", "ext-skill")
os.MkdirAll(externalDir, 0755)
os.WriteFile(filepath.Join(externalDir, "SKILL.md"), []byte("# External"), 0644)
os.Symlink(externalDir, filepath.Join(targetPath, "ext-skill"))
// Sync without force — external symlink should be preserved (with warning)
result = sb.RunCLI("sync")
result.AssertSuccess(t)
if !sb.IsSymlink(filepath.Join(targetPath, "ext-skill")) {
t.Error("valid external symlink should be preserved without --force")
}
// Sync with --force — external symlink should be removed
result = sb.RunCLI("sync", "--force")
result.AssertSuccess(t)
if sb.FileExists(filepath.Join(targetPath, "ext-skill")) {
t.Error("external symlink should have been removed with --force")
}
// Valid source skill should still exist
if !sb.IsSymlink(filepath.Join(targetPath, "skill-a")) {
t.Error("skill-a should still be a symlink")
}
}
func TestSync_MergeMode_InvalidFilterPatternFails(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("skill-a", map[string]string{"SKILL.md": "# Skill"})
targetPath := sb.CreateTarget("claude")
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
claude:
path: ` + targetPath + `
include: ["["]
`)
result := sb.RunCLI("sync")
result.AssertFailure(t)
result.AssertAnyOutputContains(t, "invalid include pattern")
}
func TestSync_IgnoredSkillsTextOutput(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("keep-me", map[string]string{
"SKILL.md": "---\nname: keep-me\n---\nKeep",
})
sb.CreateSkill("ignore-me", map[string]string{
"SKILL.md": "---\nname: ignore-me\n---\nIgnored",
})
targetPath := sb.CreateTarget("claude")
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
claude:
path: ` + targetPath + `
`)
os.WriteFile(filepath.Join(sb.SourcePath, ".skillignore"), []byte("ignore-me\n"), 0644)
result := sb.RunCLI("sync")
result.AssertSuccess(t)
result.AssertAnyOutputContains(t, "1 skill(s) ignored by .skillignore")
result.AssertAnyOutputContains(t, "ignore-me")
}
func TestSync_IgnoredSkillsJSONOutput(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("keep-me", map[string]string{
"SKILL.md": "---\nname: keep-me\n---\nKeep",
})
sb.CreateSkill("ignore-me", map[string]string{
"SKILL.md": "---\nname: ignore-me\n---\nIgnored",
})
targetPath := sb.CreateTarget("claude")
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
claude:
path: ` + targetPath + `
`)
os.WriteFile(filepath.Join(sb.SourcePath, ".skillignore"), []byte("ignore-me\n"), 0644)
result := sb.RunCLI("sync", "--json")
result.AssertSuccess(t)
var output map[string]any
if err := json.Unmarshal([]byte(result.Stdout), &output); err != nil {
t.Fatalf("failed to parse JSON: %v", err)
}
ignoredCount := int(output["ignored_count"].(float64))
if ignoredCount != 1 {
t.Errorf("expected ignored_count=1, got %d", ignoredCount)
}
ignoredSkills := output["ignored_skills"].([]any)
if len(ignoredSkills) != 1 || ignoredSkills[0].(string) != "ignore-me" {
t.Errorf("expected ignored_skills=[ignore-me], got %v", ignoredSkills)
}
}
func TestSync_NoSkillignore_NoIgnoredOutput(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("my-skill", map[string]string{
"SKILL.md": "---\nname: my-skill\n---\nContent",
})
targetPath := sb.CreateTarget("claude")
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
claude:
path: ` + targetPath + `
`)
result := sb.RunCLI("sync")
result.AssertSuccess(t)
result.AssertOutputNotContains(t, "ignored by .skillignore")
}
func TestSync_SkillignoreLocal_OverridesBase(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("keep-me", map[string]string{
"SKILL.md": "---\nname: keep-me\n---\nKeep",
})
sb.CreateSkill("private-mine", map[string]string{
"SKILL.md": "---\nname: private-mine\n---\nMine",
})
sb.CreateSkill("private-other", map[string]string{
"SKILL.md": "---\nname: private-other\n---\nOther",
})
targetPath := sb.CreateTarget("claude")
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
claude:
path: ` + targetPath + `
`)
// .skillignore blocks all private-* skills
os.WriteFile(filepath.Join(sb.SourcePath, ".skillignore"), []byte("private-*\n"), 0644)
// .skillignore.local un-ignores private-mine
os.WriteFile(filepath.Join(sb.SourcePath, ".skillignore.local"), []byte("!private-mine\n"), 0644)
result := sb.RunCLI("sync")
result.AssertSuccess(t)
// private-mine should be synced (un-ignored by .local)
if _, err := os.Stat(filepath.Join(targetPath, "private-mine")); os.IsNotExist(err) {
t.Error("private-mine should be synced (un-ignored by .skillignore.local)")
}
// private-other should NOT be synced (still ignored)
if _, err := os.Stat(filepath.Join(targetPath, "private-other")); err == nil {
t.Error("private-other should NOT be synced (still ignored)")
}
// keep-me should be synced
if _, err := os.Stat(filepath.Join(targetPath, "keep-me")); os.IsNotExist(err) {
t.Error("keep-me should be synced")
}
// Output should show 1 ignored skill and .local hint
result.AssertAnyOutputContains(t, "1 skill(s) ignored by .skillignore")
result.AssertAnyOutputContains(t, "private-other")
result.AssertAnyOutputContains(t, ".local")
}
// A built-in target listed without a path takes its path from targets.yaml.
// antigravity-cli used to be an alias, and DefaultTargets() is not alias-aware,
// so a path-less entry failed validation instead of resolving.
func TestSync_BuiltinTargetWithoutPath_UsesDefaultPath(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("my-skill", map[string]string{
"SKILL.md": "# My Skill",
})
targetPath := sb.CreateTarget("antigravity-cli")
sb.WriteConfig(`source: ` + sb.SourcePath + `
mode: merge
targets:
antigravity-cli:
`)
result := sb.RunCLI("sync")
result.AssertSuccess(t)
if !sb.IsSymlink(filepath.Join(targetPath, "my-skill")) {
t.Errorf("symlink not created at %s", filepath.Join(targetPath, "my-skill"))
}
}