EV-10 round 2: judge the car against the alarm's own landing; test failed writes; honest hold wording
checks / unit (pull_request) Successful in 22m4s
infra-pin / fresh (pull_request) Successful in 2s

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-16 18:07:25 +01:00
parent a60342e4e8
commit 646f61e730
3 changed files with 150 additions and 36 deletions
+87 -12
View File
@@ -14,6 +14,7 @@ Mutating a module this file grades? Read MUTATION.md first (purge __pycache__).
"""
import asyncio
import dataclasses
import logging
import os
import sys
@@ -135,6 +136,38 @@ check("a house-only drain to the reserve with the car charging little: the "
"normal alarm still fires",
alarms(r10h) != [] and not r10h["c"].car_explains)
def plug_late(plant, c):
plant.ch.plug_in()
def house_reserve(plant, c):
plant.soc = 19.0
plant.load = lambda at: 3075.0 + plant.ch.power_w
def swapped_events():
ev = watch(850, house_reserve)
ev[800] = plug_late
return ev
def swapped(mode):
return P.drive(s81.constant(6000.0), dur=895, rating=12000.0, soc=60.0,
cap=CAP, phases=1, user_a=6, setpoint=6, mode=mode,
plug=False, events=swapped_events())
r10x = swapped("manual")
r10xo = swapped("off")
check("PRECONDITION (review): a 6 kW HOUSE drains the batteries, the car "
"plugs in late (a small share); the projection is under the aim at the "
"reserve, and Off raises the alarm", alarms(r10xo) != []
and any(p < a for _t, p, a in UNDER))
check("the house drains the batteries and a small car is plugged in: the "
"normal alarm still fires in Manual", alarms(r10x) != [])
r10off = P.drive(s81.constant(HOUSE), dur=895, rating=12000.0, soc=60.0,
cap=CAP, phases=1, mode="off", events=watch(850, at_reserve))
check("PRECONDITION: Off, the same case raises the normal alarm (the false "
@@ -147,6 +180,7 @@ class _Car(ctl_car.CarMixin):
self.o = {"ev_batt_cover": cover}
self.w = w
self._now = 0.0
self.site_batt_w, self.site_rating_w = 300.0, 5000.0
self.car_init({}, type("S", (), {"data": {}, "set": lambda s, k, v: 0})())
def car_now(self):
@@ -161,33 +195,44 @@ class _Car(ctl_car.CarMixin):
return "charging"
@dataclasses.dataclass
class _Proj:
def __init__(self, proj_w, elapsed=850.0):
self.projected_w, self.elapsed_s, self.held_w = proj_w, elapsed, proj_w
self.block_start = datetime(2026, 11, 16, 20, 0, tzinfo=timezone.utc)
projected_w: float
elapsed_s: float = 850.0
held_w: float = 0.0
block_start: object = datetime(2026, 11, 16, 20, 0, tzinfo=timezone.utc)
def __post_init__(self):
self.held_w = self.projected_w
class _G:
def __init__(self, floor=True, sat=False):
def __init__(self, floor=True, sat=False, within_aim=False):
self.floor_limited, self.saturated = floor, sat
self.floor_w, self.able_w, self.ceiling_w = 0.0, None, 4500.0
self.engaged, self.blind, self.wanted_w = True, None, 300.0
self.within_aim = within_aim
def explains(proj_w, car_w, *, floor=True, cover=True, car_so_far_w=None):
def explains(proj_w, car_w, *, floor=True, cover=True, car_so_far_w=None,
within_aim=False):
c = _Car(cover, car_w)
p = _Proj(proj_w)
c._carq = {"key": p.block_start,
"ws": (car_w if car_so_far_w is None else car_so_far_w)
* p.elapsed_s, "mono": 0.0}
c.car_cycle(p, _G(floor), 4450.0, None)
c.car_cycle(p, _G(floor, within_aim=within_aim), 4450.0, None)
return c.car_explains
check("rule: the period without the car (4468 - 3700 = 768 W) is under the "
"aim: the car explains it, even with the projection under the aim",
explains(4300.0, 3700.0) and explains(4468.0, 3700.0))
check("rule: the alarm's test is true with the car (4468 W, the batteries "
"at 0 W land 4485 W) and false without it (768 W): the car explains it, "
"with the projection under the aim", explains(4468.0, 3700.0))
check("rule: where the alarm would not fire anyway nothing is explained",
not explains(4300.0, 3700.0, within_aim=True))
check("rule: without the car it is still over the aim: the car does not "
"explain it", not explains(9000.0, 3700.0))
check("rule: no car power, no explanation", not explains(4300.0, 0.0))
check("rule: no car power, no explanation", not explains(9000.0, 0.0))
check("rule: the guard is not floor-limited or saturated: nothing to explain",
not explains(4300.0, 3700.0, floor=False))
@@ -209,7 +254,7 @@ def over_run(c, secs, proj_of, w_of=lambda t: 11000.0, t0=0.0, target=14000.0,
t = t0 + k
c._now = t
c.w = w_of(t)
p = _Proj(proj_of(t), elapsed=300.0 + (t % 400))
p = _Proj(proj_of(t), elapsed_s=300.0 + (t % 400))
c._carq = {"key": p.block_start, "ws": 11000.0 * p.elapsed_s,
"mono": t}
c.car_cycle(p, _G(True), target, None)
@@ -236,7 +281,7 @@ c11o = _Car(cover=False)
raw = []
for k in range(1200):
c11o._now = float(k)
p = _Proj(noisy(k), elapsed=300.0 + (k % 400))
p = _Proj(noisy(k), elapsed_s=300.0 + (k % 400))
c11o._carq = {"key": p.block_start, "ws": 11000.0 * p.elapsed_s, "mono": k}
ex = p.projected_w - 14000.0
raw.append(ex > 0.0 and c11o.car_avg_w(p, 11000.0) >= ex)
@@ -442,6 +487,36 @@ wm = asyncio.run(manual_own())
check("Manual: two writes of ours, never 'another writer' in the tracker",
wm.c.car.writer_at_utc is None and "charger_other" not in wm.rows())
async def failed_write_then_outside(how):
"""A write that RAISES or returns FAILURE must still close the self-mute:
a later outside change shows the row."""
w = World()
await w.step(3)
await w.c.handle_action("car_mode", value="manual")
async def bad(a):
await w.sleep(1.0)
if how == "raise":
raise RuntimeError("the charger link broke")
return False
w.drv.write_current = bad
await w.c.handle_action("car_current", value=12)
await w.step(3) # the write is tried
await w.c.handle_action("car_mode", value="off")
await w.step(20) # past the 15 s mute
w.sim.set_current(7) # somebody else
await w.step(3)
return w
for how in ("raise", "fail"):
wf = asyncio.run(failed_write_then_outside(how))
check(f"a write that {'raises' if how == 'raise' else 'returns failure'}"
": the mute closes within 15 s, and a later outside change shows "
"the row", wf.c.car.mute_until < wf.t
and "charger_writer" in wf.rows())
print()
print("FAIL: " + ", ".join(fails) if fails else "PASS: every check passed")
sys.exit(1 if fails else 0)