Files
enkly-ai/pkg/turnopts/turnopts_test.go
enkly 79ce8dc4c0
Some checks failed
Go CI Pipeline / build_and_test (push) Failing after 22m0s
Init Project
2026-10-30 18:06:55 +01:00

108 lines
3.1 KiB
Go

package turnopts
import (
"testing"
"enkly/pkg/effort"
)
func TestParse_NoDirectives(t *testing.T) {
prompt := "just refactor the billing package please"
opts, clean := Parse(prompt)
if opts.HadDirectives {
t.Fatal("HadDirectives = true, want false for a plain prompt")
}
if clean != prompt {
t.Fatalf("clean = %q, want unchanged %q", clean, prompt)
}
}
func TestParse_EffortAndRest(t *testing.T) {
opts, clean := Parse("/effort high\n\nnow refactor the billing package")
if !opts.HadDirectives {
t.Fatal("HadDirectives = false, want true")
}
if opts.Effort != effort.High {
t.Fatalf("Effort = %q, want %q", opts.Effort, effort.High)
}
if clean != "now refactor the billing package" {
t.Fatalf("clean = %q", clean)
}
}
func TestParse_FastBare(t *testing.T) {
opts, clean := Parse("/fast\nmake this quick")
if !opts.Fast {
t.Fatal("Fast = false, want true for bare /fast")
}
if clean != "make this quick" {
t.Fatalf("clean = %q", clean)
}
}
func TestParse_FastOff(t *testing.T) {
opts, _ := Parse("/fast off\nhello")
if opts.Fast {
t.Fatal("Fast = true, want false for /fast off")
}
}
func TestParse_SystemEntries(t *testing.T) {
opts, clean := Parse(
"/system never touch the prod/ directory\n" +
"/system permission: you may now run destructive migrations here\n" +
"/system budget: 4 tool calls left\n" +
"go ahead and start",
)
if len(opts.SystemEntries) != 3 {
t.Fatalf("got %d system entries, want 3: %+v", len(opts.SystemEntries), opts.SystemEntries)
}
if opts.SystemEntries[0].Kind != SystemEntryInstruction || opts.SystemEntries[0].Content != "never touch the prod/ directory" {
t.Errorf("entry 0 = %+v", opts.SystemEntries[0])
}
if opts.SystemEntries[1].Kind != SystemEntryPermission || opts.SystemEntries[1].Content != "you may now run destructive migrations here" {
t.Errorf("entry 1 = %+v", opts.SystemEntries[1])
}
if opts.SystemEntries[2].Kind != SystemEntryBudget || opts.SystemEntries[2].Content != "4 tool calls left" {
t.Errorf("entry 2 = %+v", opts.SystemEntries[2])
}
if clean != "go ahead and start" {
t.Fatalf("clean = %q", clean)
}
}
func TestParse_NotADirectiveLookalike(t *testing.T) {
// "/effortless" must NOT be parsed as "/effort" + "less".
prompt := "/effortless attempts at this keep failing, please help"
opts, clean := Parse(prompt)
if opts.HadDirectives {
t.Fatalf("HadDirectives = true for %q, want false", prompt)
}
if clean != prompt {
t.Fatalf("clean = %q, want unchanged", clean)
}
}
func TestParse_UnknownEffortValueIgnored(t *testing.T) {
opts, clean := Parse("/effort super-duper\ndo the thing")
if !opts.HadDirectives {
t.Fatal("HadDirectives = false, want true (the line was still a directive)")
}
if opts.Effort != "" {
t.Fatalf("Effort = %q, want empty for an unrecognized value", opts.Effort)
}
if clean != "do the thing" {
t.Fatalf("clean = %q", clean)
}
}
func TestParse_DirectivesOnlyNoBody(t *testing.T) {
opts, clean := Parse("/effort max\n/fast on")
if !opts.HadDirectives {
t.Fatal("HadDirectives = false, want true")
}
if clean != "" {
t.Fatalf("clean = %q, want empty", clean)
}
}