Files
AetherForge/agent/client/self_surgery_test.go
AetherForge fac324ff80
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Add mining self-surgery for on-host recovery when AI control detects stalls.
When ai_control_enabled and mining interrupts or hashrate drops, the server composes same-agent fix plans (container restart, chain reorder, GPU swap, idle tune, RandomX restart) with Seer and oath ledger audit — no spread or lateral escalation.
2026-06-07 09:27:26 -07:00

51 lines
1.4 KiB
Go

package client
import (
"encoding/json"
"testing"
"crypto-miner-agent/config"
"crypto-miner-agent/miner"
"crypto-miner-agent/stats"
)
func TestSelfSurgeryIdleTune(t *testing.T) {
reporter := stats.NewReporter()
cfg := config.RuntimeConfig{BuiltinConfig: config.BuiltinConfig{IdleThresholdPct: 20}}
pool := miner.NewPool(1, cfg, reporter, nil)
c := &AgentClient{
agentID: "agent-1",
cfg: cfg,
pool: pool,
}
ok, detail := c.selfSurgeryIdleTune(35)
if !ok || detail == "" {
t.Fatalf("ok=%v detail=%q", ok, detail)
}
if c.cfg.IdleThresholdPct != 35 {
t.Fatalf("idle threshold=%d want 35", c.cfg.IdleThresholdPct)
}
}
func TestApplyMiningSelfSurgeryRejectsWrongAgent(t *testing.T) {
c := &AgentClient{agentID: "mine", pool: miner.NewPool(1, config.RuntimeConfig{}, stats.NewReporter(), nil)}
raw, _ := json.Marshal(MiningSelfSurgeryPlan{AgentID: "other", Actions: []string{"randomx_restart"}})
c.applyMiningSelfSurgeryJSON(raw) // no-op: agent_id mismatch
}
func TestForbiddenSelfSurgeryActionRejected(t *testing.T) {
if !isForbiddenSelfSurgeryAction("discover_and_join") {
t.Fatal("expected forbidden")
}
if isForbiddenSelfSurgeryAction("container_restart") {
t.Fatal("container_restart should be allowed")
}
}
func TestParseMiningMethodOrder(t *testing.T) {
order := parseMiningMethodOrder([]string{"inprocess", "container"})
if len(order) != 2 || order[0] != miner.MethodInProcess {
t.Fatalf("order=%v", order)
}
}