package author import ( "context" "encoding/json" "git.a-wan.net/alan/pipelines/internal/draft" "os" "path/filepath" "strings" "testing" ) func TestInstalledSkillUpdatesWithoutOverwritingUserFiles(t *testing.T) { t.Setenv("XDG_CONFIG_HOME", t.TempDir()) dir, err := InstallSkill() if err != nil { t.Fatal(err) } if _, err = InstallSkill(); err != nil { t.Fatal("repeat install", err) } // Simulate an older package-owned file: update must refresh it, not refuse it. old := []byte("old packaged skill") markerData, _ := os.ReadFile(filepath.Join(dir, ".pipelines-managed.json")) var hashes map[string]string json.Unmarshal(markerData, &hashes) hashes["SKILL.md"] = digest(old) markerData, _ = json.Marshal(hashes) os.WriteFile(filepath.Join(dir, "SKILL.md"), old, 0600) os.WriteFile(filepath.Join(dir, ".pipelines-managed.json"), markerData, 0600) if _, err := InstallSkill(); err != nil { t.Fatal("skill update failed", err) } for _, file := range skillFiles { actual, err := os.ReadFile(filepath.Join(dir, file)) expected, _ := content.ReadFile("skill/" + file) if err != nil || string(actual) != string(expected) { t.Fatal(file, err) } } if err := os.WriteFile(filepath.Join(dir, "SKILL.md"), []byte("user modification"), 0600); err != nil { t.Fatal(err) } if _, err := InstallSkill(); err == nil { t.Fatal("overwrote user-modified skill") } data, _ := os.ReadFile(filepath.Join(dir, "SKILL.md")) if string(data) != "user modification" { t.Fatal("lost user changes") } } func TestCommandLaunchesOnceWithShortSkillReference(t *testing.T) { t.Setenv("XDG_CONFIG_HOME", t.TempDir()) t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir()) if _, err := InstallSkill(); err != nil { t.Fatal(err) } d, err := draft.Create("", "source", "ws://local", true, 0) if err != nil { t.Fatal(err) } capture := filepath.Join(t.TempDir(), "calls") script := filepath.Join(t.TempDir(), "opencode") os.WriteFile(script, []byte("#!/bin/sh\nprintf '%s\\n' \"$@\" >> '"+capture+"'\n"), 0700) cmd, err := Command(context.Background(), script, d, "", "pipelines") if err != nil { t.Fatal(err) } if err := cmd.Run(); err != nil { t.Fatal(err) } data, _ := os.ReadFile(capture) text := string(data) if strings.Contains(text, "--session") || strings.Contains(text, "api\n") || strings.Contains(text, "--help") || !strings.Contains(text, "--prompt\n@pipelines\n") { t.Fatal("unexpected prelaunch calls", text) } if len(Prompt(d, "", "pipelines")) > 512 || !strings.Contains(text, d.Path+".json") { t.Fatal("prompt must reference context, not preload instructions") } }