Close test-gap noise rows and sync coverage documentation.
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled

Restore P1/P2/fleet/erasure COVERED rows in PROBLEMS.md with refreshed counts; drop fixed poll-duplication and Vitest-noise items. Silence ECONNREFUSED stderr in Vitest setup, alias download mock exports, and expand erasure/Path Tracer test coverage.
This commit is contained in:
AetherForge
2026-06-07 06:44:54 -07:00
parent 72ae457cca
commit 821a0e2cd7
14 changed files with 710 additions and 147 deletions

View File

@@ -3,14 +3,38 @@ package api
import (
"encoding/json"
"testing"
"crypto-miner-server/internal/db"
)
func TestAuthSpreadPolicyIncludesErasureLanes(t *testing.T) {
hub := NewWSHub(nil)
database, err := db.New(t.TempDir())
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = database.Close() })
hub := NewWSHub(database)
hub.SetServerPolicy(ServerPolicy{ErasureLanesEnabled: true})
raw := buildAuthSpreadPolicy(hub)
conn, _ := dialAgentWS(t, hub)
resp := authAgentConn(t, conn, map[string]interface{}{
"agent_id": "erasure-policy-agent",
"hostname": "host",
"platform": "windows",
"version": "test",
})
var body map[string]interface{}
if err := json.Unmarshal(resp.Payload, &body); err != nil {
t.Fatal(err)
}
raw, ok := body["spread_policy"]
if !ok {
t.Fatalf("spread_policy missing from auth_response: %#v", body)
}
policyBytes, _ := json.Marshal(raw)
var policy map[string]interface{}
if err := json.Unmarshal(raw, &policy); err != nil {
if err := json.Unmarshal(policyBytes, &policy); err != nil {
t.Fatal(err)
}
enabled, ok := policy["erasure_lanes_enabled"].(bool)
@@ -19,20 +43,28 @@ func TestAuthSpreadPolicyIncludesErasureLanes(t *testing.T) {
}
}
func buildAuthSpreadPolicy(hub *WSHub) json.RawMessage {
policy := hub.serverPolicySnapshot()
if !policy.ErasureLanesEnabled && policy.HashrateGateSpreadMin <= 0 && policy.HashrateGateHPS <= 0 {
return nil
func TestAuthSpreadPolicyOmitsErasureWhenDisabled(t *testing.T) {
database, err := db.New(t.TempDir())
if err != nil {
t.Fatal(err)
}
spreadPolicy := map[string]interface{}{
"erasure_lanes_enabled": policy.ErasureLanesEnabled,
t.Cleanup(func() { _ = database.Close() })
hub := NewWSHub(database)
hub.SetServerPolicy(ServerPolicy{})
conn, _ := dialAgentWS(t, hub)
resp := authAgentConn(t, conn, map[string]interface{}{
"agent_id": "no-erasure-agent",
"hostname": "host",
"platform": "windows",
"version": "test",
})
var body map[string]interface{}
if err := json.Unmarshal(resp.Payload, &body); err != nil {
t.Fatal(err)
}
if policy.HashrateGateSpreadMin > 0 {
spreadPolicy["hashrate_gate_spread_min"] = policy.HashrateGateSpreadMin
if _, ok := body["spread_policy"]; ok {
t.Fatalf("spread_policy should be omitted: %#v", body["spread_policy"])
}
if policy.HashrateGateHPS > 0 {
spreadPolicy["hashrate_gate_hps"] = policy.HashrateGateHPS
}
raw, _ := json.Marshal(spreadPolicy)
return raw
}