package pack

import "testing"

func TestCheckHostCompatibilityAcceptsRange(t *testing.T) {
	manifest := Manifest{
		PackID:         "openai-cn-pack",
		TargetHost:     "sub2api",
		MinHostVersion: "0.1.126",
		MaxHostVersion: "0.2.x",
	}
	if err := CheckHostCompatibility(manifest, "0.1.126"); err != nil {
		t.Fatalf("CheckHostCompatibility() error = %v, want nil", err)
	}
	if err := CheckHostCompatibility(manifest, "0.2.9"); err != nil {
		t.Fatalf("CheckHostCompatibility() error = %v, want nil for wildcard upper bound", err)
	}
}

func TestCheckHostCompatibilityRejectsBelowMinimum(t *testing.T) {
	manifest := Manifest{TargetHost: "sub2api", MinHostVersion: "0.1.126"}
	if err := CheckHostCompatibility(manifest, "0.1.125"); err == nil {
		t.Fatal("CheckHostCompatibility() error = nil, want min version failure")
	}
}

func TestCheckHostCompatibilityRejectsDifferentMaxMinor(t *testing.T) {
	manifest := Manifest{TargetHost: "sub2api", MaxHostVersion: "0.2.x"}
	if err := CheckHostCompatibility(manifest, "0.3.0"); err == nil {
		t.Fatal("CheckHostCompatibility() error = nil, want max version failure")
	}
}
