package main

import (
	"os"
	"path/filepath"
	"testing"
)

func TestReadReloadTarget_missing(t *testing.T) {
	got := readReloadTarget(filepath.Join(t.TempDir(), "reload.txt"))
	if got != "" {
		t.Fatalf("expected empty string for missing file, got %q", got)
	}
}

func TestReadReloadTarget_empty(t *testing.T) {
	f := filepath.Join(t.TempDir(), "reload.txt")
	if err := os.WriteFile(f, []byte(""), 0o644); err != nil {
		t.Fatal(err)
	}
	got := readReloadTarget(f)
	if got != "" {
		t.Fatalf("expected empty string for empty file, got %q", got)
	}
}

func TestReadReloadTarget_star(t *testing.T) {
	f := filepath.Join(t.TempDir(), "reload.txt")
	if err := os.WriteFile(f, []byte("*\n"), 0o644); err != nil {
		t.Fatal(err)
	}
	got := readReloadTarget(f)
	if got != "" {
		t.Fatalf("expected empty string for '*', got %q", got)
	}
}

func TestReadReloadTarget_agentID(t *testing.T) {
	f := filepath.Join(t.TempDir(), "reload.txt")
	if err := os.WriteFile(f, []byte("assistant-bot\n"), 0o644); err != nil {
		t.Fatal(err)
	}
	got := readReloadTarget(f)
	if got != "assistant-bot" {
		t.Fatalf("expected 'assistant-bot', got %q", got)
	}
}

func TestReadReloadTarget_whitespace(t *testing.T) {
	f := filepath.Join(t.TempDir(), "reload.txt")
	if err := os.WriteFile(f, []byte("  asistente-2  \n"), 0o644); err != nil {
		t.Fatal(err)
	}
	got := readReloadTarget(f)
	if got != "asistente-2" {
		t.Fatalf("expected 'asistente-2', got %q", got)
	}
}
