Files
AetherForge/server/internal/api/contingency_bridge_test.go
AetherForge 35c3271f20
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Integrator: AWS gate fixes and doc counts after cloud landing.
Apply SwarmMagnet, uiHelp, AccessDepthPanel, Seer, miningsurgery, and path-tracer test fixes; add agent cloud telemetry fields and main strings import; refresh tests/README and PROBLEMS AWS operator notes.
2026-06-07 10:52:38 -07:00

64 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)
}
t.Cleanup(func() { _ = database.Close() })
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")
}
}