mirror of
https://github.com/jhuebert/MeshCore.git
synced 2026-12-03 10:54:13 +00:00
fix: load() must not wipe the fleet's injected device services
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.
This commit is contained in:
1 parent
f195aa70f4
commit
a833e1dc64
4 files changed
+29
-9
No files matched your search
@@ -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:
|
||||
|
||||
```
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user