diff --git a/go/test/site/ev_battery_priority_test.go b/go/test/site/ev_battery_priority_test.go index c0ef73233..ef6a011e3 100644 --- a/go/test/site/ev_battery_priority_test.go +++ b/go/test/site/ev_battery_priority_test.go @@ -2,8 +2,6 @@ package site -import "math" - // #1868: the car has only [0, 4140] W, while the battery can charge at // 6000 W. The actual devices run over Modbus and OCPP; marks and the // physical meter record let the judge see which device yielded. @@ -53,18 +51,29 @@ func judgeS18(d *runData) (metrics, []criterion) { batteryBefore, batteryAfter := meanOf(pre, batSigned), meanOf(d.window(none-20, none), batSigned) // Core holds the phases at the fuse line, so the house's 0.1 A step // lands over it until Core cuts; the I²t model judges that stretch. - // Own commands are the rest, as in the minor window. - ownI := math.Max(maxOf(d.window(t0, small), maxAbsI), maxOf(minor, maxAbsI)) + // Own commands are the rest, as in the minor window. The working limit + // is the fuse rating (owner rule, 27 Oct 2026): a reading over it fails + // only while the 60 s heat is over it too, or over 1.2 x the fuse at + // once (heatOver). Readings jitter a few mA around the line. + fuse := d.metaF("fuse") + own := append(d.window(t0, small), minor...) + ownI, ownOver := maxOf(own, maxAbsI), 0 + d.warm() + for _, r := range own { + if heatOver(r, fuse) { + ownOver++ + } + } m := metrics{"battery_before_w": batteryBefore, "battery_after_w": batteryAfter, "restart_s": restart, "car_before_w": carMin(pre), "car_small_step_w": carMin(minor), "car_recovered_w": carMin(recovered), "fuse_blown": anyBlown(d.samples), "max_i_before_house_overload": maxOf(d.window(t0, none), maxAbsI), - "max_i_own_commands": ownI} + "max_i_own_commands": ownI, "own_commands_over_fuse_heat_samples": ownOver} return m, []criterion{ crit("setup: car and battery charge together", len(pre) > 0 && carMin(pre) >= 4100 && batteryBefore > 1000), crit("battery yields before the minimum-step car", len(minor) > 0 && carMin(minor) >= 4100 && batteryAfter < batteryBefore-40), crit("car stops when house leaves no room", len(paused) > 0 && maxOf(paused, func(r *sample) float64 { return carW(r, 0) }) < 100), crit("car restarts automatically within 150 s", le(restart, 150) && len(recovered) > 0 && carMin(recovered) >= 4100), - crit("own commands stay inside the rated fuse", ownI <= 16.01), + crit("own commands stay inside the rated fuse", len(own) > 0 && ownOver == 0), crit("fuse holds", !anyBlown(d.samples)), } } diff --git a/go/test/site/rig_unit_test.go b/go/test/site/rig_unit_test.go index 94f50466c..417bc9c98 100644 --- a/go/test/site/rig_unit_test.go +++ b/go/test/site/rig_unit_test.go @@ -283,11 +283,14 @@ func TestInvariantsChargeNowRoomAtTheFuse(t *testing.T) { // s18 at margin 0: Core holds the phases at the 16 A line, so the house's own // 0.1 A step lands over it until Core cuts. That stretch is the house's, not -// an own command. The same overage at any other time is Core's and fails. +// an own command. The same overage at any other time is Core's and fails: +// the phases sit at the fuse from the start, so the 60 s heat is at the fuse +// and any reading over it heats it past. func TestS18OwnCommandsSkipTheHouseStep(t *testing.T) { const own = "own commands stay inside the rated fuse" mk := func(overFrom float64) *runData { - d := &runData{marks: map[string]float64{"charge_now": 0, "small_step": 100, "no_room": 200, "room_returns": 300, "end": 450}} + d := &runData{marks: map[string]float64{"charge_now": 0, "small_step": 100, "no_room": 200, "room_returns": 300, "end": 450}, + meta: map[string]any{"fuse": 16.0}} for i := 0; i <= 450; i++ { a := 16.0 if float64(i) >= overFrom && float64(i) < overFrom+4 { @@ -317,6 +320,41 @@ func TestS18OwnCommandsSkipTheHouseStep(t *testing.T) { } } +// s18's own commands are judged at the 16 A rating by Core's heat model +// (owner rule, 27 Oct 2026): a reading over the fuse fails only while the +// 60 s heat is over it too, or at once over 1.2 x the fuse. On master +// 575152ea the local rig failed s18 at 16.011 A against a fixed 16.01 A +// bound, with the heat at 14.95 A. +func TestS18OwnCommandsJudgedByHeat(t *testing.T) { + const own = "own commands stay inside the rated fuse" + for _, c := range []struct { + name string + baseA, overA float64 + overS int + want bool + }{ + {"16.011 A jitter for 5 s at the line", 15.99, 16.011, 5, true}, + {"16.5 A for 30 s at the line heats past the fuse", 15.99, 16.5, 30, false}, + {"16.5 A for 5 s from a cool fuse", 12, 16.5, 5, true}, + {"one reading at 19.1 A from a cool fuse", 12, 19.1, 1, true}, + {"one reading at 19.3 A, over 1.2 x the fuse", 12, 19.3, 1, false}, + } { + d := &runData{marks: map[string]float64{"charge_now": 0, "small_step": 100, "no_room": 200, "room_returns": 300, "end": 450}, + meta: map[string]any{"fuse": 16.0}} + for i := 0; i <= 450; i++ { + a := c.baseA + if i >= 50 && i < 50+c.overS { + a = c.overA + } + d.samples = append(d.samples, &sample{T: float64(i), PhaseA: [3]float64{a, a, a}}) + } + _, cs := judgeS18(d) + if got := verdictsOf(cs)[own]; got != c.want { + t.Errorf("%s: %q = %v, want %v", c.name, own, got, c.want) + } + } +} + // s8 at margin 0: the car settles at the fuse rating, as the owner's rule // says. A phase at exactly the fuse for the whole run passes; 0.1 A above // it for longer than the charger's delay + 7 s fails. Before, the judge