package engine

import (
	"testing"

	"github.com/Armur-Ai/Pentest-Swarm-AI/internal/llm"
)

// Every role runs on GLM-5.3-Flash — the model Together still serves on its
// serverless tier. The former bulk default (Llama-3.3-70B-Instruct-Turbo) was
// moved off serverless and now 400s, so routing to it silently degraded recon
// to tool-only; the swarm uses one known-good serverless model instead.
func TestTogetherModelFor(t *testing.T) {
	for _, role := range []string{"exploit", "classifier", "recon", "report"} {
		if got := togetherModelFor(role); got != "zai-org/GLM-5.3-Flash" {
			t.Errorf("togetherModelFor(%q) = %q, want %q", role, got, "zai-org/GLM-5.3-Flash")
		}
	}
}

// The cost meter must price at the *costliest* model in the active mix so the
// budget cap never overspends. With every role on one model, the meter must
// price at that model. This guards the "never overspend" guarantee against
// future routing changes.
func TestTogetherMeterModelIsCostliest(t *testing.T) {
	meter := mixtureMeterModel(togetherModelFor)
	meterHi := hiPrice(llm.PricingFor(meter))
	for _, role := range []string{"recon", "classifier", "exploit", "report"} {
		if got := hiPrice(llm.PricingFor(togetherModelFor(role))); got > meterHi {
			t.Fatalf("meter model %q ($%.2f) is not the costliest — role %q costs $%.2f",
				meter, meterHi, role, got)
		}
	}
	if meter != "zai-org/GLM-5.3-Flash" {
		t.Errorf("meter model = %q, want zai-org/GLM-5.3-Flash", meter)
	}
}

func hiPrice(p llm.Pricing) float64 {
	if p.OutputPerMillion > p.InputPerMillion {
		return p.OutputPerMillion
	}
	return p.InputPerMillion
}
