package quality

import (
	"testing"

	"github.com/stretchr/testify/require"
	"github.com/tidbcloud/AgentTeam/kits/agentteam-insight/internal/graphbuilder/schema"
)

func TestMeasureKnownGraphQualityDefects(t *testing.T) {
	graph := schema.KnowledgeGraph{Nodes: []schema.GraphNode{
		{Type: "function", Name: "Run", Summary: "Function Run", FilePath: "main.go"},
		{Type: "class", Name: "Config", Summary: "Type Config", FilePath: "config.go"},
		{Type: "file", Name: "main.go", Summary: "go code file", FilePath: "main.go"},
		{Type: "file", Name: "config.json", Summary: "Loads analyzer configuration", FilePath: ".ua/config.json"},
		{Type: "file", Name: "graph.json", Summary: "Stores the last graph", FilePath: `.agentteam-insight\knowledge-graph.json`},
		{Type: "function", Name: "Serve", Summary: "Implements server behavior", FilePath: "server.go"},
		{Type: "class", Name: "State", Summary: "Defines State state", FilePath: "state.go"},
	}}
	report := Measure(graph)
	require.Equal(t, 3, report.PlaceholderSummaries)
	require.Equal(t, 2, report.AnalyzerArtifactNodes)
	require.False(t, report.Grounded())
}

func TestMeasureGroundedGraph(t *testing.T) {
	report := Measure(schema.KnowledgeGraph{Nodes: []schema.GraphNode{{
		Type: "function", Name: "Run", Summary: "Coordinates graph generation", FilePath: "main.go",
	}}})
	require.True(t, report.Grounded())
}
