52 lines
1.8 KiB
Go
52 lines
1.8 KiB
Go
package author
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"pipelines/internal/draft"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestSkillActivationIsExplicitAndNoResume(t *testing.T) {
|
|
t.Setenv("PIPELINES_DRAFT_DIR", t.TempDir())
|
|
d, err := draft.Create("name", "source", "ws://local", true, 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
workspace, err := Workspace(d)
|
|
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+"'\nif [ \"$3\" = /api/session ]; then printf '%s' '{\"data\":{\"id\":\"ses_test\"}}'; fi\n"), 0700)
|
|
id, err := PrepareSession(context.Background(), script, workspace, d.Name)
|
|
if err != nil || id != "ses_test" {
|
|
t.Fatal(id, err)
|
|
}
|
|
data, _ := os.ReadFile(capture)
|
|
text := string(data)
|
|
if !strings.Contains(text, `"id":"pipelines"`) || !strings.Contains(text, `"resume":false`) {
|
|
t.Fatal("skill not explicitly loaded without generation", text)
|
|
}
|
|
if !strings.Contains(Prompt(d, "change X", "pipelines"), "do not submit or run") {
|
|
t.Fatal("draft-first instruction missing")
|
|
}
|
|
}
|
|
|
|
func TestSkillFailureDoesNotLaunchAndCleansOnlyCreatedSession(t *testing.T) {
|
|
workspace := t.TempDir()
|
|
capture := filepath.Join(workspace, "calls")
|
|
script := filepath.Join(workspace, "opencode")
|
|
os.WriteFile(script, []byte("#!/bin/sh\nprintf '%s\\n' \"$@\" >> '"+capture+"'\nif [ \"$3\" = /api/session ]; then printf '%s' '{\"data\":{\"id\":\"ses_new\"}}'; exit 0; fi\nif [ \"$2\" = delete ]; then exit 0; fi\nexit 1\n"), 0700)
|
|
if _, err := PrepareSession(context.Background(), script, workspace, "name"); err == nil {
|
|
t.Fatal("missing skill allowed")
|
|
}
|
|
data, _ := os.ReadFile(capture)
|
|
if !strings.Contains(string(data), "delete\n/api/session/ses_new") {
|
|
t.Fatal("created session not cleaned", string(data))
|
|
}
|
|
}
|