// This file verifies strict metrics-profile parsing and safe profile references.
package evaluation

import (
	"strings"
	"testing"
)

func TestLoadMetricsProfileRejectsPathTraversal(t *testing.T) {
	_, err := LoadMetricsProfile(t.TempDir(), "../outside")
	if err == nil || !strings.Contains(err.Error(), "reference") {
		t.Fatalf("LoadMetricsProfile() error = %v, want invalid reference", err)
	}
}

func TestDecodeMetricsProfileRejectsUnsupportedPlaceholder(t *testing.T) {
	const input = `
version: v1alpha1
id: tidb/horizontal-v1
component: tidb
sources:
  - type: application
    queries:
      - name: tidb_connections
        promql: 'tidb_server_connections{tidb_cluster_id="${tenant_id}"}'
        type: range
        required: true
`

	_, err := DecodeMetricsProfile(strings.NewReader(input))
	if err == nil || !strings.Contains(err.Error(), "placeholder") {
		t.Fatalf("DecodeMetricsProfile() error = %v, want unsupported placeholder", err)
	}
}
