mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
* fix(sync): close gaps found while simulating the prefixed naming switch Simulating the #497 reporter's switch from merge + flat to copy + prefixed turned up four problems: - `target X --mode copy --target-naming prefixed` applied only --mode, since the setter dispatch returned after the first flag. Both flags given together now check the final pair, then apply in an order that keeps the saved pair valid (copy mode first, any other mode last). - Skipped skills were only counted, so a prefixed name over 64 characters vanished with "1 skill(s) skipped". Sync now names the first five with their reason; the cap keeps huge sources from flooding the output. - In copy mode a merge-mode link to the skill was not a managed entry, so when a local folder held the new name the old link was pruned and the skill left the target, contrary to the documented "old managed entry is preserved". Copy mode now migrates such links like managed copies. - PATCH /api/targets validated the mode/naming pair against the current skills state, so disabling skills while changing mode was rejected. It now checks the state the request leaves the target in. * docs(target): drop stray space in the Japanese mode+naming sentence * fix(diff): save paired target settings once and report kept legacy entries - `target X --mode M --target-naming N` ran the two setters, each saving the config, so a failed second save left half the change behind (Codex on #504). Both fields are now set and saved once, after the final pair is checked. - When a local folder holds the name a skill's naming now gives it, sync keeps the skill under its old entry and leaves the folder alone, even with --force. diff still called the folder a "local copy" and suggested `sync --force`, which does nothing for it. CLI and Web API diff, copy and merge mode, now report the folder and the entry the skill stays at. * fix(sync): migrate only links the manifest records as merge-made Copy mode treated any link to the skill's source at an old naming's name as the entry merge mode left behind, so a user's own link was renamed and replaced with a copy (Codex on #504). A link now migrates only when the manifest records it as "symlink", which merge mode writes for links it makes; other links stay as the user left them. The value is now a named constant. * fix(diff): mark kept legacy entries as unaffected by force Two problems Codex found on #504: - The Web API diff sent a local folder on a skill's new name as a "skip", which the dashboard shows as an edited entry that Force replaces. Sync keeps that folder and the legacy entry even with force, so the preview promised a change that never happens. It is now its own "kept" action, shown with its reason and not counted. - `target X --mode M --target-naming N` printed the target's own naming as the old value, so a target inheriting standard or prefixed showed "flat -> ...". It now prints the naming the target had in effect. * fix(diff): keep kept-name conflicts out of the sync count Two problems Codex found on #504: - A local folder on a skill's new name counted toward "N to sync" and fell through to the plain `skillshare sync` hint, though sync changes nothing there until the folder is renamed or removed. Such rows now carry a kept flag, count as neither sync nor local, and print their own hint; a target whose only row is kept still shows that row. - The dashboard grouped targets by row name and icon only, so two targets keeping the same skill at different old entries merged and showed one target's old location for both. The row detail is now part of the key. * fix(diff): do not list a kept local folder's files as deletions A kept row (a local folder on a skill's new name) still pointed at that folder, so `diff --stat` and `--patch` listed each of its files as removed, though sync never touches the folder (Codex on #504). Kept rows no longer point at a target directory, so no file-level diff is built for them in the CLI or the TUI. * fix(diff): report kept skills consistently in every diff view An exhaustive review of the kept-row change (prompted by two Codex findings on #504) found the same gap in several places: - A target whose only rows were kept was summarized as "in sync", and mixed summaries left it out of every count. Such targets now count as "N kept under old name" with a warning mark, and the scan progress counts them. - Plain output and the TUI hid where the skill stays; rows now read "name (stays at old-name)". The TUI also lacked the kept Next hint and called kept-only targets "differs"; it now matches the plain output. - `diff --json` emitted kept rows as "remove", indistinguishable from local-only folders; it now emits "kept", as the Web API does. The diff docs' JSON example also showed actions the CLI never emits. - Renamed rows whose old entry is a merge-made link showed a bogus file stat, because the link was walked as a file; a link now stands for the folder it points to. - A dry-run migration printed "Would copy" to the old path; it now names the new one. * fix(sync): stop reporting kept folders and skipped skills as pending work (#509) Three reports told users to do something sync cannot do, or hid what it did: - Copy and merge sync kept a folder the user made on a skill's name but counted it as "up to date" with no hint. Sync now counts it as local and adds one capped line per target naming the folders and saying that `sync --force` replaces them. The line is added in SyncSkillTarget, so the dashboard gets it too. - status and doctor counted skills that sync skips on purpose (invalid names under standard or prefixed naming, name collisions) as "not synced — run skillshare sync". Running sync can never add them, so the advice looped. They now compare against the skills sync places. - diff marked a target whose only items were local-only folders as "to sync" and `synced: false`. Those items are still listed, but they no longer make the target pending. * fix(target): apply every setting flag, require flag values, report no-ops as unchanged (#507) * fix(target): apply every setting flag, require flag values, report no-ops as unchanged `skillshare target <name>` dispatched --mode, --agent-mode and --target-naming through an if-chain that returned after the first match, so `--agent-mode copy --target-naming prefixed` applied one setting and silently dropped the other. Filters, --skills and --dry-run had the same early-return problem. - Check --mode, --agent-mode and --target-naming as a whole and save once, in global and project mode (one targetSettingsUpdate replaces six per-flag functions). - Reject --mode/--agent-mode/--target-naming combined with filters or --skills, and --dry-run without --skills, instead of dropping them. - A value flag followed by another flag (or an empty string) now reports "<flag> requires a value"; `--target-naming -p` used to report an invalid naming '-p'. - A value the target already has is reported as unchanged and the config is not rewritten. * fix(target): leave the skills pair alone on agents-only changes A target with skills off may keep target_naming prefixed with a merge mode it cannot sync; validateGlobalTarget and validateProjectTarget only check that pair for enabled skills. The combined settings update ran the pair check for every setting, so `target claude --agent-mode copy` was refused on such a target although the old agent-mode handler never looked at skills settings. Check the pair only when --mode or --target-naming is given. * docs(target): show combined settings in --help and the built-in skill The combined --mode/--agent-mode/--target-naming form is now the way to move a target to copy + prefixed in one step, but neither the help examples nor the built-in skill's target reference showed it.
302 lines
8.2 KiB
Go
302 lines
8.2 KiB
Go
//go:build !online
|
|
|
|
package integration
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
ssync "skillshare/internal/sync"
|
|
"skillshare/internal/testutil"
|
|
)
|
|
|
|
func TestSync_IncludePatternMatchingNothing_IsReported(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.CreateNestedSkill("frontend/dev", map[string]string{
|
|
"SKILL.md": "---\nname: dev\n---\n# Dev",
|
|
})
|
|
targetPath := sb.CreateTarget("claude")
|
|
|
|
writeInclude := func(naming, include string) {
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
target_naming: ` + naming + `
|
|
targets:
|
|
claude:
|
|
path: ` + targetPath + `
|
|
mode: merge
|
|
include: [` + include + `]
|
|
`)
|
|
}
|
|
|
|
// Filters match the source-path name, so this is the pattern that works.
|
|
writeInclude("standard", "frontend__dev")
|
|
first := sb.RunCLI("sync")
|
|
first.AssertSuccess(t)
|
|
if !sb.IsSymlink(filepath.Join(targetPath, "dev")) {
|
|
t.Fatal("expected frontend__dev to link under the bare name dev")
|
|
}
|
|
first.AssertOutputNotContains(t, "matches no skill")
|
|
|
|
// The same skill addressed by the name the target shows matches nothing, and
|
|
// the entry the previous filter created is pruned. The mismatch has to be
|
|
// visible instead of silent.
|
|
writeInclude("standard", "dev")
|
|
second := sb.RunCLI("sync")
|
|
second.AssertSuccess(t)
|
|
second.AssertOutputContains(t, `claude: include filter "dev" matches no skill`)
|
|
second.AssertOutputContains(t, "frontend__dev")
|
|
|
|
// The heuristic also runs in the default flat naming mode.
|
|
writeInclude("flat", "dev")
|
|
third := sb.RunCLI("sync")
|
|
third.AssertSuccess(t)
|
|
third.AssertOutputContains(t, `include filter "dev" matches no skill`)
|
|
}
|
|
|
|
func TestSync_TargetNamingStandard_InvalidSkillWarnsAndSkips(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.CreateNestedSkill("frontend/dev", map[string]string{
|
|
"SKILL.md": "---\nname: wrong-name\n---\n# Wrong",
|
|
})
|
|
sb.CreateSkill("alpha", map[string]string{
|
|
"SKILL.md": "---\nname: alpha\n---\n# Alpha",
|
|
})
|
|
targetPath := sb.CreateTarget("claude")
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
target_naming: standard
|
|
targets:
|
|
claude:
|
|
path: ` + targetPath + `
|
|
mode: merge
|
|
`)
|
|
|
|
result := sb.RunCLI("sync")
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "skill(s) skipped (naming validation)")
|
|
result.AssertAnyOutputContains(t, "skipped frontend/dev because")
|
|
|
|
if !sb.IsSymlink(filepath.Join(targetPath, "alpha")) {
|
|
t.Fatal("expected valid skill alpha to sync")
|
|
}
|
|
if sb.FileExists(filepath.Join(targetPath, "dev")) {
|
|
t.Fatal("did not expect invalid skill to sync as dev")
|
|
}
|
|
if sb.FileExists(filepath.Join(targetPath, "frontend__dev")) {
|
|
t.Fatal("did not expect invalid skill to sync as flat legacy name")
|
|
}
|
|
}
|
|
|
|
func TestSync_TargetNamingStandard_CollisionWarnsAndSkipsBoth(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.CreateNestedSkill("frontend/dev", map[string]string{
|
|
"SKILL.md": "---\nname: dev\n---\n# Frontend Dev",
|
|
})
|
|
sb.CreateNestedSkill("backend/dev", map[string]string{
|
|
"SKILL.md": "---\nname: dev\n---\n# Backend Dev",
|
|
})
|
|
sb.CreateSkill("alpha", map[string]string{
|
|
"SKILL.md": "---\nname: alpha\n---\n# Alpha",
|
|
})
|
|
targetPath := sb.CreateTarget("claude")
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
target_naming: standard
|
|
targets:
|
|
claude:
|
|
path: ` + targetPath + `
|
|
mode: merge
|
|
`)
|
|
|
|
result := sb.RunCLI("sync")
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "duplicate skill names")
|
|
|
|
if sb.FileExists(filepath.Join(targetPath, "dev")) {
|
|
t.Fatal("did not expect colliding bare name dev to be synced")
|
|
}
|
|
if !sb.IsSymlink(filepath.Join(targetPath, "alpha")) {
|
|
t.Fatal("expected non-conflicting skill alpha to sync")
|
|
}
|
|
}
|
|
|
|
func TestSync_TargetNamingStandard_MergeMigratesManagedFlatEntry(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.CreateNestedSkill("frontend/dev", map[string]string{
|
|
"SKILL.md": "---\nname: dev\n---\n# Dev",
|
|
})
|
|
targetPath := sb.CreateTarget("claude")
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
targets:
|
|
claude:
|
|
path: ` + targetPath + `
|
|
mode: merge
|
|
`)
|
|
sb.RunCLI("sync").AssertSuccess(t)
|
|
|
|
legacyPath := filepath.Join(targetPath, "frontend__dev")
|
|
if !sb.IsSymlink(legacyPath) {
|
|
t.Fatal("expected initial flat entry frontend__dev")
|
|
}
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
target_naming: standard
|
|
targets:
|
|
claude:
|
|
path: ` + targetPath + `
|
|
mode: merge
|
|
`)
|
|
|
|
result := sb.RunCLI("sync")
|
|
result.AssertSuccess(t)
|
|
|
|
if !sb.IsSymlink(filepath.Join(targetPath, "dev")) {
|
|
t.Fatal("expected managed entry to migrate to bare name dev")
|
|
}
|
|
if sb.FileExists(legacyPath) {
|
|
t.Fatal("did not expect legacy flat entry to remain after migration")
|
|
}
|
|
}
|
|
|
|
func TestSync_TargetNamingStandard_CopyMigratesManagedFlatEntry(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.CreateNestedSkill("frontend/dev", map[string]string{
|
|
"SKILL.md": "---\nname: dev\n---\n# Dev",
|
|
})
|
|
targetPath := sb.CreateTarget("claude")
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
targets:
|
|
claude:
|
|
path: ` + targetPath + `
|
|
mode: copy
|
|
`)
|
|
sb.RunCLI("sync").AssertSuccess(t)
|
|
|
|
legacyPath := filepath.Join(targetPath, "frontend__dev")
|
|
if !sb.FileExists(filepath.Join(legacyPath, "SKILL.md")) {
|
|
t.Fatal("expected initial flat copy frontend__dev")
|
|
}
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
target_naming: standard
|
|
targets:
|
|
claude:
|
|
path: ` + targetPath + `
|
|
mode: copy
|
|
`)
|
|
|
|
result := sb.RunCLI("sync")
|
|
result.AssertSuccess(t)
|
|
|
|
if !sb.FileExists(filepath.Join(targetPath, "dev", "SKILL.md")) {
|
|
t.Fatal("expected managed copy to migrate to bare name dev")
|
|
}
|
|
if sb.FileExists(legacyPath) {
|
|
t.Fatal("did not expect legacy flat copy to remain after migration")
|
|
}
|
|
|
|
var manifest ssync.Manifest
|
|
data := sb.ReadFile(filepath.Join(targetPath, ssync.ManifestFile))
|
|
if err := json.Unmarshal([]byte(data), &manifest); err != nil {
|
|
t.Fatalf("unmarshal manifest: %v", err)
|
|
}
|
|
if _, ok := manifest.Managed["dev"]; !ok {
|
|
t.Fatal("expected manifest to track migrated bare name dev")
|
|
}
|
|
if _, ok := manifest.Managed["frontend__dev"]; ok {
|
|
t.Fatal("did not expect manifest to retain legacy flat key")
|
|
}
|
|
}
|
|
|
|
func TestSync_TargetNamingStandard_PreservesLegacyManagedEntryWhenDestinationExists(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.CreateNestedSkill("frontend/dev", map[string]string{
|
|
"SKILL.md": "---\nname: dev\n---\n# Dev",
|
|
})
|
|
targetPath := sb.CreateTarget("claude")
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
targets:
|
|
claude:
|
|
path: ` + targetPath + `
|
|
mode: merge
|
|
`)
|
|
sb.RunCLI("sync").AssertSuccess(t)
|
|
|
|
legacyPath := filepath.Join(targetPath, "frontend__dev")
|
|
localPath := filepath.Join(targetPath, "dev")
|
|
if err := os.MkdirAll(localPath, 0755); err != nil {
|
|
t.Fatalf("mkdir local path: %v", err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(localPath, "SKILL.md"), []byte("# Local"), 0644); err != nil {
|
|
t.Fatalf("write local skill: %v", err)
|
|
}
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
target_naming: standard
|
|
targets:
|
|
claude:
|
|
path: ` + targetPath + `
|
|
mode: merge
|
|
`)
|
|
|
|
result := sb.RunCLI("sync")
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "kept legacy managed entry")
|
|
|
|
if !sb.IsSymlink(legacyPath) {
|
|
t.Fatal("expected legacy managed entry to be preserved when bare name already exists")
|
|
}
|
|
if !sb.FileExists(filepath.Join(localPath, "SKILL.md")) {
|
|
t.Fatal("expected existing bare-name local skill to be preserved")
|
|
}
|
|
}
|
|
|
|
func TestSync_TargetNaming_IgnoredInSymlinkMode(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.CreateNestedSkill("frontend/dev", map[string]string{
|
|
"SKILL.md": "---\nname: dev\n---\n# Dev",
|
|
})
|
|
targetPath := sb.CreateTarget("claude")
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
target_naming: standard
|
|
targets:
|
|
claude:
|
|
path: ` + targetPath + `
|
|
mode: symlink
|
|
`)
|
|
|
|
result := sb.RunCLI("sync")
|
|
result.AssertSuccess(t)
|
|
|
|
if !sb.IsSymlink(targetPath) {
|
|
t.Fatal("expected entire target directory to be symlinked in symlink mode")
|
|
}
|
|
if got := sb.SymlinkTarget(targetPath); got != sb.SourcePath {
|
|
t.Fatalf("symlink target = %q, want %q", got, sb.SourcePath)
|
|
}
|
|
if strings.Contains(result.Output(), "kept legacy managed entry") {
|
|
t.Fatal("did not expect target naming migration warnings in symlink mode")
|
|
}
|
|
}
|