Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Single-host branch runner complements fallback chain under Fleet AI Control: persona ghost forks, onion_miner_log hops, server exhaustion splice from graft mining genome, Crucible depth badge, and hospice retire after max cycles.
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"crypto-miner-server/internal/db"
|
|
)
|
|
|
|
func TestAttachContingencyPolicyWhenAIControl(t *testing.T) {
|
|
hub := NewWSHub(nil)
|
|
hub.serverPolicy = ServerPolicy{AIControlEnabled: true, AIPersona: "silent"}
|
|
|
|
resp := map[string]interface{}{}
|
|
hub.attachContingencyPolicy(resp)
|
|
cp, ok := resp["contingency_policy"].(map[string]interface{})
|
|
if !ok || cp["enabled"] != true {
|
|
t.Fatalf("policy=%v", resp["contingency_policy"])
|
|
}
|
|
order, _ := cp["branch_order"].([]string)
|
|
if len(order) == 0 {
|
|
t.Fatalf("branch_order=%v", cp["branch_order"])
|
|
}
|
|
}
|
|
|
|
func TestHandleOnionMinerLogEmitsSeerAndDepth(t *testing.T) {
|
|
database, err := db.New(t.TempDir())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
hub := NewWSHub(database)
|
|
hub.serverPolicy = ServerPolicy{AIControlEnabled: true, AIPersona: "balanced"}
|
|
|
|
raw, _ := json.Marshal(map[string]interface{}{
|
|
"method": "inprocess", "outcome": "won", "contingency_depth": 4,
|
|
})
|
|
hub.handleOnionMinerLog("agent-onion", raw)
|
|
|
|
if hub.contingencyDepthForAgent("agent-onion") != 4 {
|
|
t.Fatalf("depth=%d", hub.contingencyDepthForAgent("agent-onion"))
|
|
}
|
|
events, _ := database.ListSeerEvents(10)
|
|
found := false
|
|
for _, ev := range events {
|
|
if ev.EventType == "onion_miner_log" && ev.AgentID == "agent-onion" {
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatal("expected onion_miner_log seer event")
|
|
}
|
|
}
|
|
|
|
func TestContingencyPolicyAbsentWithoutAIControl(t *testing.T) {
|
|
hub := NewWSHub(nil)
|
|
hub.serverPolicy = ServerPolicy{AIControlEnabled: false}
|
|
resp := map[string]interface{}{}
|
|
hub.attachContingencyPolicy(resp)
|
|
if _, ok := resp["contingency_policy"]; ok {
|
|
t.Fatal("expected no contingency_policy without ai control")
|
|
}
|
|
}
|