refactor(webconfig): wire WebConfigBatch spec into WebConfigServer (Phase 6)

The pure batch/reboot/stop state machine in WebConfigBatch.h was host-tested
but not referenced by production, so the real logic in WebConfigServer.cpp was
untested and the two could drift silently.

Repoint the production decision points at the spec: POST classification and
replay-state naming, drain pacing/all-ok/finish, reboot scheduling and firing,
result classification, confirm-reboot arming, and stop gating. MAX_BATCH and
STOP_WARN_MS now alias kMaxBatch/kStopWarnMs so the constants cannot drift.

Behavior-preserving. Two asymmetries are deliberate and documented in the
header: finishRebootAt()'s 0 return must not be assigned unconditionally
(the manual /api/reboot route also owns _reboot_at and could be cancelled),
and classifyPost() is consulted in two phases because the change count is
only known after parsing, which must not precede the Replay/Busy answer.

Native suite (14 suites) and both MQTT smoke builds green.
This commit is contained in:
agessaman committed 2026-07-19 12:35:52 -07:00
1 parent c67d4022ec
commit cece565e11
3 files changed
+90 -38

No files matched your search

+17 -2
View File
@@ -29,6 +29,7 @@
#include <Arduino.h>
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
#include <helpers/WebConfigBatch.h>
class AsyncWebServer;
class AsyncWebServerRequest;
@@ -87,13 +88,27 @@ public:
bool isStopping() const { return _stopping; }
private:
static const int MAX_BATCH = 24;
// Batch/reboot/stop decisions and timings live in the fork-owned pure spec
// WebConfigBatch.h (host-tested by test/test_webconfig_batch). These aliases
// keep a single source of truth so the spec and this server cannot drift.
static const int MAX_BATCH = WebConfigBatch::kMaxBatch;
static const size_t MAX_BODY = 4096;
// A detached session normally drains immediately because handlers are short.
// If one does not, keep the session alive (safe) and emit a diagnostic rather
// than freeing memory still referenced by the async task.
static const uint32_t STOP_WARN_MS = 10000;
static const uint32_t STOP_WARN_MS = WebConfigBatch::kStopWarnMs;
enum BatchState : uint8_t { BATCH_IDLE = 0, BATCH_PENDING, BATCH_DONE };
// BatchState and WebConfigBatch::State are deliberately kept as separate
// types (the enum is stored in a volatile member and used in prints); this
// is the one conversion point.
static WebConfigBatch::State toSpecState(BatchState s) {
switch (s) {
case BATCH_PENDING: return WebConfigBatch::State::Pending;
case BATCH_DONE: return WebConfigBatch::State::Done;
default: return WebConfigBatch::State::Idle;
}
}
struct BatchEntry {
char key[24]; // allowlisted `set` key (echoed back to the UI)
char cmd[160]; // full CLI command (may contain secrets - never echoed)