package builder

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

func TestApplySigilScrambleChangesFile(t *testing.T) {
	dir := t.TempDir()
	path := filepath.Join(dir, "worker.exe")
	orig := []byte{'M', 'Z', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0x40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0, 'P', 'E', 0, 0, 0, 0, 0, 0}
	if err := os.WriteFile(path, orig, 0755); err != nil {
		t.Fatal(err)
	}
	fp1, err := ApplySigilScramble(path, "build-a")
	if err != nil {
		t.Fatal(err)
	}
	st1, _ := os.Stat(path)
	fp2, err := ApplySigilScramble(path, "build-b")
	if err != nil {
		t.Fatal(err)
	}
	st2, _ := os.Stat(path)
	if st1.Size() == st2.Size() && fp1 == fp2 {
		t.Fatalf("expected different fingerprint/size got %s %s", fp1, fp2)
	}
}

func TestStealthScore(t *testing.T) {
	if StealthScore(true, true, true) < 90 {
		t.Fatal("expected high score")
	}
	if StealthScore(false, false, false) != 35 {
		t.Fatalf("got %d", StealthScore(false, false, false))
	}
}
