1package modes
2
3import (
4 "strings"
5 "testing"
6
7 "github.com/bnema/zut/packages/agent/skills"
8 "github.com/bnema/zut/packages/tui"
9)
10
11func TestSkillPinStateReadOnlyWithoutLoader(t *testing.T) {
12 called := false
13 state := newSkillPinState(nil, func(string, string, bool) error { called = true; return nil }, reviewSnapshot)
14 dialog := newSkillsDialog()
15 dialog.Open(reviewSnapshot())
16 state.refresh("/workspace", dialog)
17 if handled, _, _, _ := state.handleKey(pinKey('p'), "/workspace", dialog); handled || called {
18 t.Fatal("read-only picker wrote pin preferences")
19 }
20}
21
22func TestSkillPinAliasesShowScopesAndPreloadOnce(t *testing.T) {
23 skill := &skills.Skill{Name: "review", Aliases: []string{"group/review"}, Body: "Inspect carefully."}
24 pins := skills.Pins{Project: []string{"group/review"}, Global: []string{"review"}}
25 state := newSkillPinState(func(string) (skills.Pins, error) { return pins, nil }, func(string, string, bool) error { return nil }, func() []*skills.Skill { return []*skills.Skill{skill} })
26 dialog := newSkillsDialog()
27 dialog.Open([]*skills.Skill{skill})
28 state.arm(true, "/workspace", dialog)
29 if marker := dialog.pinMarker(skill); marker != "[pg] " {
30 t.Fatalf("marker=%q, want [pg]", marker)
31 }
32 notice := stripANSIBytes(strings.Join(state.notice(tui.Theme{}, 80), ""))
33 if !strings.Contains(notice, "review (project + global)") {
34 t.Fatalf("alias scope missing from notice: %q", notice)
35 }
36 if prompt := state.consume("question"); strings.Count(prompt, "Inspect carefully.") != 1 {
37 t.Fatalf("alias pin included body twice: %q", prompt)
38 }
39}