package tdd_test

import (
	"context"
	"encoding/json"
	"testing"

	"github.com/mathiasbq/supervisor/internal/skills/tdd"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestTDDSkillTools(t *testing.T) {
	skill := tdd.New(tdd.Config{
		SystemPrompt: "supervisor rules",
		SkillPrompt:  "tdd rules",
	})
	tools := skill.Tools()
	names := make([]string, len(tools))
	for i, tool := range tools {
		names[i] = tool.Name
	}
	assert.ElementsMatch(t, []string{"tdd_red", "tdd_green", "tdd_refactor"}, names)
}

func TestTDDSkillHandleUnknown(t *testing.T) {
	skill := tdd.New(tdd.Config{SystemPrompt: "s", SkillPrompt: "t"})
	_, err := skill.Handle(context.Background(), "tdd_unknown", json.RawMessage(`{}`))
	assert.ErrorContains(t, err, "unknown tool")
}

func TestTDDRedRequiresProjectRoot(t *testing.T) {
	skill := tdd.New(tdd.Config{SystemPrompt: "s", SkillPrompt: "t"})
	_, err := skill.Handle(context.Background(), "tdd_red", json.RawMessage(`{"spec":"add two numbers"}`))
	assert.ErrorContains(t, err, "project_root")
}

func TestTDDRedRequiresSpec(t *testing.T) {
	skill := tdd.New(tdd.Config{SystemPrompt: "s", SkillPrompt: "t"})
	_, err := skill.Handle(context.Background(), "tdd_red", json.RawMessage(`{"project_root":"/tmp/proj"}`))
	assert.ErrorContains(t, err, "spec")
}

// Ensure require is used (avoids import error).
var _ = require.New
