From a833e1dc64d540bf70593f7dfd0958d1b165969a Mon Sep 17 00:00:00 2001 From: Jason Huebert Date: Wed, 7 Oct 2026 12:13:42 -0500 Subject: [PATCH] fix: load() must not wipe the fleet's injected device services MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resetToDefaults() NULLed time_fn/jitter_fn/send_fn, and load() calls it — but MyMesh::begin() wires those services in just before fleet.begin(fs), so after every boot the clock read as unset (!at jobs always refused) and send_fn was NULL (!ack replies silently dropped). Wiring, not config state: the three members now get in-class initializers and resetToDefaults() never touches them. Regression test drives a load after wiring the clock and asserts the !at admission path still sees it; verified the test fails against the old resetToDefaults() and passes with the fix. AGENTS.md fleet count 81 -> 82. --- AGENTS.md | 4 ++-- examples/simple_repeater/FleetManager.cpp | 6 +++--- examples/simple_repeater/FleetManager.h | 10 ++++++---- test/test_fleet/test_fleet.cpp | 18 ++++++++++++++++++ 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 13f8a8eb..e19b48cd 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -81,7 +81,7 @@ commit** — the guides are user-facing API documentation, not optional docs. **Tests:** `test/test_packet_filter/` (295 behavior-level cases: matching, content rules, limiter, persistence upgrades, CLI surface, TinyRegex, -PatternMatch), `test/test_fleet/` (81 cases: runner grammar, tag targeting, +PatternMatch), `test/test_fleet/` (82 cases: runner grammar, tag targeting, acknowledgements, scheduling, persistence, CLI surface, the battery exemption contract) and `test/test_battery_gate/`. Test-only shims: `NativeShim.h`, `NativeTestStubs.cpp`, `RegionMapStub.cpp`, @@ -250,7 +250,7 @@ FILTER.md: googletest); reach them via the same CLI/`checkPacket`/`checkContent` entry points a user or the firmware would. - Pure refactors keep both suites green **unchanged** — the suites (295 filter, - 81 fleet, 44 battery) are the safety net that proves no behavior slipped. + 82 fleet, 44 battery) are the safety net that proves no behavior slipped. - Run both suites, then re-read the diff: ``` diff --git a/examples/simple_repeater/FleetManager.cpp b/examples/simple_repeater/FleetManager.cpp index 626b8c7c..a99bec2c 100644 --- a/examples/simple_repeater/FleetManager.cpp +++ b/examples/simple_repeater/FleetManager.cpp @@ -24,9 +24,9 @@ void FleetManager::resetToDefaults() { reply_count = 0; offered = 0; matched = 0; - time_fn = NULL; time_ctx = NULL; - jitter_fn = NULL; jitter_ctx = NULL; - send_fn = NULL; send_ctx = NULL; + // device services are deliberately NOT reset here: they are wiring (set by + // MyMesh::begin() before load()), not config state — they have in-class + // initializers and survive every resetToDefaults()/load() call } FleetManager::FleetManager() { diff --git a/examples/simple_repeater/FleetManager.h b/examples/simple_repeater/FleetManager.h index e8b98be0..130d61ee 100644 --- a/examples/simple_repeater/FleetManager.h +++ b/examples/simple_repeater/FleetManager.h @@ -121,10 +121,12 @@ class FleetManager { LazySave save_flag; // needs save, written back by loop() // device services (see typedefs above); NULL = unset: the clock counts as - // unset for !at admission, and replies are sent without jitter - FleetTimeFn time_fn; void* time_ctx; - FleetJitterFn jitter_fn; void* jitter_ctx; - FleetSendFn send_fn; void* send_ctx; + // unset for !at admission, and replies are sent without jitter. Wiring, + // not state: MyMesh::begin() sets them just before load(), so they get + // in-class initializers and resetToDefaults() must never touch them. + FleetTimeFn time_fn = NULL; void* time_ctx = NULL; + FleetJitterFn jitter_fn = NULL; void* jitter_ctx = NULL; + FleetSendFn send_fn = NULL; void* send_ctx = NULL; public: FleetManager(); diff --git a/test/test_fleet/test_fleet.cpp b/test/test_fleet/test_fleet.cpp index b8103d21..e38b4a2c 100644 --- a/test/test_fleet/test_fleet.cpp +++ b/test/test_fleet/test_fleet.cpp @@ -1138,6 +1138,24 @@ TEST_F(FleetHooksTest, AppendChannelByHash) { EXPECT_EQ(fleet.appendChannelByHash(hash, dest, 4, 0), 0); } +TEST_F(FleetHooksTest, LoadPreservesDeviceServices) { + // MyMesh wires the device services in just before fleet.begin(fs): a + // load-time resetToDefaults() must not wipe them (wiring, not state) + flushSave(); // a persisted config exists + FleetManager loaded; + loaded.setClock(HookEnv::timeFn, &env); + loaded.begin(&fs); // load() runs resetToDefaults() + // observable through the scheduled path: with the clock wired, an !at job + // within the stale window is admitted and fires on the next pass; a wiped + // clock would read as unset and refuse it + GroupTextPayload p = makeGroupText("alice", "!id k1\n!at 1800000000\nreset"); + loaded.onGroupData(PAYLOAD_TYPE_GRP_TXT, chan, p.data, p.len); + EXPECT_EQ(loaded.getSchedCount(), 1); // clock survived load: job admitted + loaded.runScripts(ExecRecorder::fn, &env.rec); + ASSERT_EQ(env.rec.lines.size(), (size_t)1); // dequeued by the wired clock + EXPECT_EQ(env.rec.lines[0], "reset"); +} + // ------------------------------------------------------------------ CLI TEST_F(FleetHooksTest, StatusLine) {