package memoryskill

import (
	"strings"
	"testing"

	"github.com/stretchr/testify/require"
	"go.yaml.in/yaml/v3"
)

func TestMaintenanceSkillContract(t *testing.T) {
	name, content := Maintenance()
	require.Equal(t, "memory-maintenance", name)
	require.NotEmpty(t, content)

	parts := strings.SplitN(content, "---", 3)
	require.Len(t, parts, 3)
	var frontmatter struct {
		Name        string `yaml:"name"`
		Description string `yaml:"description"`
	}
	require.NoError(t, yaml.Unmarshal([]byte(parts[1]), &frontmatter))
	require.Equal(t, name, frontmatter.Name)
	require.Contains(t, frontmatter.Description, "Use when")
	require.Contains(t, frontmatter.Description, "durable Memory")

	for _, required := range []string{
		"semantic Memory search",
		"2–6",
		"discriminative terms",
		"retry once",
		"bounded file traversal",
		"`system/`",
		"`profiles/`",
		"`profiles/user.md`",
		"Local Knowledge Index",
		"`knowledge/concepts/`",
		"`knowledge/workflows/`",
		"`events/`",
		"`reflections/`",
		"bounded consolidation",
		"Insights or Reflections",
		"local Memory write the current task",
		"before confirming that it was recorded",
		"Verify the canonical file exists",
		"never describe it as cloud-synced",
		"Do not store secrets",
		"raw chat transcripts",
	} {
		require.Contains(t, content, required)
	}
	require.NotContains(t, strings.ToLower(content), "unbounded walk over all")
}
