mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
* test(pi): reproduce Windows private registration access failures Use NTFS DACL assertions instead of POSIX mode bits and verify that broadly accessible existing records cannot be read or silently reused. Keep the Unix mode assertion unchanged. * fix(pi): reclaim Windows locks and protect private registration state Anchor stale directories with delete sharing and delete the verified empty Windows directory by handle, keeping inode, lease and racing-owner guards. Create new registration directories with protected owner/SYSTEM DACLs and validate existing owner/access rules without changing their ACLs. Leave Unix permissions and directory-only removal unchanged. * test(pi): capture Windows lock identity before path replacement Windows Lstat lazily fetches file IDs by pathname. Snapshot the stale fixture through its anchored handle and add a matching-mtime replacement regression before first verification or release. * fix(pi): snapshot Windows lock IDs and accept privileged default owners Capture acquired lock identity through a handle before Windows can lazily resolve a replaced pathname. Elevated tokens can default file ownership to Administrators; permit privileged owners only alongside a verified current-user-only DACL. Refuse unsafe existing registration directories without modifying their ACLs or writing records. * docs(pi): record Windows acceptance and isolated regression workflow Document private Windows ACL requirements and refusal without permission rewrites. Add pinned devcontainer kit packaging, token-isolated full/basic acceptance, preserved UTF-8 logs and a reproducible UTM runbook. Preserve the original Unix permission assertion. * test(backup): isolate explicit agent backup from sync snapshots Sync automatically backs up target-local agents. Creating the fixture before sync makes the exact-one-backup assertion depend on both commands sharing a timestamp second. Create it after successful sync so the explicit backup is the only operation that snapshots it, without weakening the assertion.
244 lines
6.9 KiB
Go
244 lines
6.9 KiB
Go
//go:build !online
|
|
|
|
package integration
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"skillshare/internal/testutil"
|
|
)
|
|
|
|
func TestBackup_Agents_CreatesBackup(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
createAgentSource(t, sb, map[string]string{
|
|
"tutor.md": "# Tutor agent",
|
|
})
|
|
claudeAgents := createAgentTarget(t, sb, "claude")
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
targets:
|
|
claude:
|
|
skills:
|
|
path: ` + sb.CreateTarget("claude") + `
|
|
agents:
|
|
path: ` + claudeAgents + `
|
|
`)
|
|
|
|
sb.RunCLI("sync", "agents").AssertSuccess(t)
|
|
// Create the local agent after sync so its automatic backup cannot be
|
|
// mistaken for this explicit backup when the commands cross a second.
|
|
// Synced agents remain symlinks and are not backed up (issue #252).
|
|
sb.WriteFile(filepath.Join(claudeAgents, "local-helper.md"), "# Local helper")
|
|
|
|
result := sb.RunCLI("backup", "agents")
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "claude-agents")
|
|
|
|
backups, _ := filepath.Glob(filepath.Join(sb.Home, ".local", "share", "skillshare", "backups", "*", "claude-agents", "local-helper.md"))
|
|
if len(backups) != 1 {
|
|
t.Fatalf("expected local-helper.md in one backup, found %v", backups)
|
|
}
|
|
}
|
|
|
|
func TestBackup_Agents_DryRun(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
createAgentSource(t, sb, map[string]string{
|
|
"tutor.md": "# Tutor agent",
|
|
})
|
|
claudeAgents := createAgentTarget(t, sb, "claude")
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
targets:
|
|
claude:
|
|
skills:
|
|
path: ` + sb.CreateTarget("claude") + `
|
|
agents:
|
|
path: ` + claudeAgents + `
|
|
`)
|
|
|
|
sb.RunCLI("sync", "agents")
|
|
|
|
result := sb.RunCLI("backup", "agents", "--dry-run")
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "Dry run")
|
|
}
|
|
|
|
func TestBackup_Agents_RestoreRoundTrip(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
createAgentSource(t, sb, map[string]string{
|
|
"tutor.md": "# Tutor agent",
|
|
})
|
|
claudeAgents := createAgentTarget(t, sb, "claude")
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
targets:
|
|
claude:
|
|
skills:
|
|
path: ` + sb.CreateTarget("claude") + `
|
|
agents:
|
|
path: ` + claudeAgents + `
|
|
`)
|
|
|
|
// A local agent that only exists in the target — this is what a backup
|
|
// protects. Synced agents are symlinks into the source and are recreated
|
|
// by `sync`, so they are deliberately not backed up (issue #252).
|
|
localPath := filepath.Join(claudeAgents, "local-helper.md")
|
|
sb.WriteFile(localPath, "# Local helper")
|
|
|
|
// Sync then backup
|
|
sb.RunCLI("sync", "agents")
|
|
sb.RunCLI("backup", "agents")
|
|
|
|
// Verify symlink exists
|
|
linkPath := filepath.Join(claudeAgents, "tutor.md")
|
|
if _, err := os.Lstat(linkPath); err != nil {
|
|
t.Fatalf("expected agent symlink at %s", linkPath)
|
|
}
|
|
|
|
// Delete the local agent from target
|
|
if err := os.Remove(localPath); err != nil {
|
|
t.Fatalf("remove local agent: %v", err)
|
|
}
|
|
|
|
// Restore
|
|
result := sb.RunCLI("restore", "agents", "claude", "--force")
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "Restored")
|
|
|
|
if _, err := os.Stat(localPath); err != nil {
|
|
t.Fatalf("expected restored agent at %s: %v", localPath, err)
|
|
}
|
|
}
|
|
|
|
func TestBackup_Default_DoesNotBackupAgents(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.CreateSkill("my-skill", map[string]string{
|
|
"SKILL.md": "---\nname: my-skill\n---\n# Content",
|
|
})
|
|
claudeSkills := sb.CreateTarget("claude")
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + `
|
|
targets:
|
|
claude:
|
|
skills:
|
|
path: ` + claudeSkills + `
|
|
`)
|
|
|
|
// Default backup should only backup skills, not mention agents
|
|
result := sb.RunCLI("backup")
|
|
result.AssertSuccess(t)
|
|
result.AssertOutputNotContains(t, "agent")
|
|
}
|
|
|
|
func TestBackup_Agents_ProjectMode_CreatesBackup(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
projectDir := setupProjectWithAgents(t, sb)
|
|
|
|
// Local agent — synced agents are symlinks and are not backed up (#252),
|
|
// so without local content there is nothing to snapshot.
|
|
sb.WriteFile(
|
|
filepath.Join(projectDir, ".claude", "agents", "local-helper.md"),
|
|
"# Local helper",
|
|
)
|
|
|
|
// Sync agents first
|
|
result := sb.RunCLIInDir(projectDir, "sync", "-p", "agents")
|
|
result.AssertSuccess(t)
|
|
|
|
// Backup project agents
|
|
result = sb.RunCLIInDir(projectDir, "backup", "-p", "agents")
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "Backed up agents of 1 target")
|
|
|
|
// Verify backup was created under .skillshare/backups/
|
|
backupDir := filepath.Join(projectDir, ".skillshare", "backups")
|
|
entries, err := os.ReadDir(backupDir)
|
|
if err != nil {
|
|
t.Fatalf("expected backup dir at %s: %v", backupDir, err)
|
|
}
|
|
if len(entries) == 0 {
|
|
t.Fatal("expected at least one backup timestamp directory")
|
|
}
|
|
}
|
|
|
|
func TestBackup_Agents_ProjectMode_DryRun(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
projectDir := setupProjectWithAgents(t, sb)
|
|
sb.RunCLIInDir(projectDir, "sync", "-p", "agents")
|
|
|
|
result := sb.RunCLIInDir(projectDir, "backup", "-p", "agents", "--dry-run")
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "Dry run")
|
|
|
|
// Backup dir should NOT exist
|
|
backupDir := filepath.Join(projectDir, ".skillshare", "backups")
|
|
if _, err := os.Stat(backupDir); !os.IsNotExist(err) {
|
|
t.Fatal("backup dir should not exist in dry run mode")
|
|
}
|
|
}
|
|
|
|
func TestBackup_Agents_ProjectMode_RestoreRoundTrip(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
projectDir := setupProjectWithAgents(t, sb)
|
|
|
|
// A local agent that only exists in the target — this is what a backup
|
|
// protects. Synced agents are symlinks into the source and are recreated
|
|
// by `sync`, so they are deliberately not backed up (issue #252).
|
|
claudeAgents := filepath.Join(projectDir, ".claude", "agents")
|
|
localPath := filepath.Join(claudeAgents, "local-helper.md")
|
|
sb.WriteFile(localPath, "# Local helper")
|
|
|
|
// Sync → backup
|
|
sb.RunCLIInDir(projectDir, "sync", "-p", "agents")
|
|
sb.RunCLIInDir(projectDir, "backup", "-p", "agents")
|
|
|
|
// Verify agent symlink exists
|
|
linkPath := filepath.Join(claudeAgents, "tutor.md")
|
|
if _, err := os.Lstat(linkPath); err != nil {
|
|
t.Fatalf("expected agent symlink at %s", linkPath)
|
|
}
|
|
|
|
// Delete the local agent from target
|
|
if err := os.Remove(localPath); err != nil {
|
|
t.Fatalf("remove local agent: %v", err)
|
|
}
|
|
|
|
// Restore
|
|
result := sb.RunCLIInDir(projectDir, "restore", "-p", "agents", "claude", "--force")
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "Restored")
|
|
|
|
// Verify the local agent is back
|
|
if _, err := os.Stat(localPath); err != nil {
|
|
t.Fatalf("expected restored agent at %s: %v", localPath, err)
|
|
}
|
|
}
|
|
|
|
func TestRestore_Agents_SkillsProjectModeRejected(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + "\ntargets: {}\n")
|
|
|
|
// Skills restore in project mode should still be rejected
|
|
result := sb.RunCLI("restore", "-p", "claude")
|
|
result.AssertFailure(t)
|
|
result.AssertAnyOutputContains(t, "not supported in project mode")
|
|
}
|