mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
skillshare backs up AGENTS.md, CLAUDE.md and shared-file locations before
rewriting them, but nothing could list or restore those copies, and a
target snapshot could not be deleted on its own. The file backups now
record why they were taken in their name (<time>.<reason>.bak; older ones
have none), and the server and CLI can list them, show a version and
restore it, saving the current content first. A link is only replaced
when the caller asks for it.
Also:
- DELETE /api/backups/{timestamp} and `backup --delete`.
- Agents snapshots (<target>-agents) could not be restored from the
dashboard: the name was looked up as a target.
- Project mode uses the project's backups folder for snapshots and lists
only file backups inside the project.
- MCP backups report which servers they changed and when.
Refs #299
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
package mcp
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestBackupsReportServersAndTime(t *testing.T) {
|
|
s := testService(t)
|
|
if _, err := s.Apply(""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := s.Mutate(Mutation{Name: "docs", Remove: true}, "", true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
backups, err := s.Backups()
|
|
if err != nil || len(backups) == 0 {
|
|
t.Fatalf("backups = %v, %v", backups, err)
|
|
}
|
|
changes := map[string]bool{}
|
|
for _, b := range backups {
|
|
if _, err := time.Parse(time.RFC3339, b.Time); err != nil {
|
|
t.Fatalf("time %q: %v", b.Time, err)
|
|
}
|
|
if len(b.Servers) != 1 || b.Servers[0].Name != "docs" {
|
|
t.Fatalf("servers = %+v", b.Servers)
|
|
}
|
|
changes[b.Servers[0].Change] = true
|
|
}
|
|
if !changes["added"] || !changes["removed"] {
|
|
t.Fatalf("changes = %v, want added and removed", changes)
|
|
}
|
|
}
|
|
|
|
func TestBackupsOfProjectConfigStayInProjectScope(t *testing.T) {
|
|
global := testService(t)
|
|
root := t.TempDir()
|
|
projectConfig := filepath.Join(root, ".skillshare", "config.yaml")
|
|
os.MkdirAll(filepath.Dir(projectConfig), 0755)
|
|
if err := os.WriteFile(projectConfig, []byte("mcp:\n targets: [cursor]\n servers:\n local:\n command: tool\n"), 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
project := &Service{ConfigPath: projectConfig, ProjectRoot: root, Home: global.Home, StateDir: global.StateDir, Platform: "linux"}
|
|
if _, err := project.Apply(""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
backups, err := project.Backups()
|
|
if err != nil || len(backups) != 1 || backups[0].Servers[0].Name != "local" {
|
|
t.Fatalf("project backups = %+v, %v", backups, err)
|
|
}
|
|
if backups, _ := global.Backups(); len(backups) != 0 {
|
|
t.Fatalf("global scope lists project backups: %+v", backups)
|
|
}
|
|
}
|