feat: add template system for role contexts and messages
Implements gt-u1j.20: Prompt templates using go:embed. - Add internal/templates package with embedded .md.tmpl files - Role templates: mayor, witness, refinery, polecat, crew - Message templates: spawn, nudge, escalation, handoff - Update gt prime to use templates with fallback to hardcoded output - Add crew role detection for <rig>/crew/<name>/ paths - Include Gas Town architecture overview in all role contexts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
155
internal/templates/templates_test.go
Normal file
155
internal/templates/templates_test.go
Normal file
@@ -0,0 +1,155 @@
|
||||
package templates
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
tmpl, err := New()
|
||||
if err != nil {
|
||||
t.Fatalf("New() error = %v", err)
|
||||
}
|
||||
if tmpl == nil {
|
||||
t.Fatal("New() returned nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderRole_Mayor(t *testing.T) {
|
||||
tmpl, err := New()
|
||||
if err != nil {
|
||||
t.Fatalf("New() error = %v", err)
|
||||
}
|
||||
|
||||
data := RoleData{
|
||||
Role: "mayor",
|
||||
TownRoot: "/test/town",
|
||||
WorkDir: "/test/town",
|
||||
}
|
||||
|
||||
output, err := tmpl.RenderRole("mayor", data)
|
||||
if err != nil {
|
||||
t.Fatalf("RenderRole() error = %v", err)
|
||||
}
|
||||
|
||||
// Check for key content
|
||||
if !strings.Contains(output, "Mayor Context") {
|
||||
t.Error("output missing 'Mayor Context'")
|
||||
}
|
||||
if !strings.Contains(output, "/test/town") {
|
||||
t.Error("output missing town root")
|
||||
}
|
||||
if !strings.Contains(output, "global coordinator") {
|
||||
t.Error("output missing role description")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderRole_Polecat(t *testing.T) {
|
||||
tmpl, err := New()
|
||||
if err != nil {
|
||||
t.Fatalf("New() error = %v", err)
|
||||
}
|
||||
|
||||
data := RoleData{
|
||||
Role: "polecat",
|
||||
RigName: "myrig",
|
||||
TownRoot: "/test/town",
|
||||
WorkDir: "/test/town/myrig/polecats/TestCat",
|
||||
Polecat: "TestCat",
|
||||
}
|
||||
|
||||
output, err := tmpl.RenderRole("polecat", data)
|
||||
if err != nil {
|
||||
t.Fatalf("RenderRole() error = %v", err)
|
||||
}
|
||||
|
||||
// Check for key content
|
||||
if !strings.Contains(output, "Polecat Context") {
|
||||
t.Error("output missing 'Polecat Context'")
|
||||
}
|
||||
if !strings.Contains(output, "TestCat") {
|
||||
t.Error("output missing polecat name")
|
||||
}
|
||||
if !strings.Contains(output, "myrig") {
|
||||
t.Error("output missing rig name")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderMessage_Spawn(t *testing.T) {
|
||||
tmpl, err := New()
|
||||
if err != nil {
|
||||
t.Fatalf("New() error = %v", err)
|
||||
}
|
||||
|
||||
data := SpawnData{
|
||||
Issue: "gt-123",
|
||||
Title: "Test Issue",
|
||||
Priority: 1,
|
||||
Description: "Test description",
|
||||
Branch: "feature/test",
|
||||
RigName: "myrig",
|
||||
Polecat: "TestCat",
|
||||
}
|
||||
|
||||
output, err := tmpl.RenderMessage("spawn", data)
|
||||
if err != nil {
|
||||
t.Fatalf("RenderMessage() error = %v", err)
|
||||
}
|
||||
|
||||
// Check for key content
|
||||
if !strings.Contains(output, "gt-123") {
|
||||
t.Error("output missing issue ID")
|
||||
}
|
||||
if !strings.Contains(output, "Test Issue") {
|
||||
t.Error("output missing issue title")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderMessage_Nudge(t *testing.T) {
|
||||
tmpl, err := New()
|
||||
if err != nil {
|
||||
t.Fatalf("New() error = %v", err)
|
||||
}
|
||||
|
||||
data := NudgeData{
|
||||
Polecat: "TestCat",
|
||||
Reason: "No progress for 30 minutes",
|
||||
NudgeCount: 2,
|
||||
MaxNudges: 3,
|
||||
Issue: "gt-123",
|
||||
Status: "in_progress",
|
||||
}
|
||||
|
||||
output, err := tmpl.RenderMessage("nudge", data)
|
||||
if err != nil {
|
||||
t.Fatalf("RenderMessage() error = %v", err)
|
||||
}
|
||||
|
||||
// Check for key content
|
||||
if !strings.Contains(output, "TestCat") {
|
||||
t.Error("output missing polecat name")
|
||||
}
|
||||
if !strings.Contains(output, "2/3") {
|
||||
t.Error("output missing nudge count")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRoleNames(t *testing.T) {
|
||||
tmpl, err := New()
|
||||
if err != nil {
|
||||
t.Fatalf("New() error = %v", err)
|
||||
}
|
||||
|
||||
names := tmpl.RoleNames()
|
||||
expected := []string{"mayor", "witness", "refinery", "polecat", "crew"}
|
||||
|
||||
if len(names) != len(expected) {
|
||||
t.Errorf("RoleNames() = %v, want %v", names, expected)
|
||||
}
|
||||
|
||||
for i, name := range names {
|
||||
if name != expected[i] {
|
||||
t.Errorf("RoleNames()[%d] = %q, want %q", i, name, expected[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user