feat: core tests, bug fixes, API docs rewrite, HTTP compat routes

- Fix state_machine reset_state_progress: reset sequence index before
  validation to prevent out-of-bounds error on state transitions
- Fix video transformer test: use ±1 tolerance for OpenCV interpolation
- Add core integration tests (service_manager, dependencies, messages)
- Add HTTP compat routes (/index.html, POST /api/wifi/scan, hotspot aliases)
- Rewrite clients/docs/API.md to match actual implementation
- Fix BLE unused imports warning
- CEO task planning for next round (ConfigReload, playlist snapshot)

cargo check: 0 warnings, cargo test: 22/22 passed

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
showen
2026-03-12 12:40:17 +08:00
parent 60488311d3
commit 5af7fc18a5
10 changed files with 924 additions and 306 deletions

View File

@@ -38,6 +38,7 @@ struct PendingWifiResponse {
pub(crate) struct HttpState {
wifi_response: Mutex<PendingWifiResponse>,
wifi_response_cv: Condvar,
last_wifi_result: Mutex<Option<String>>,
config: Mutex<Arc<AppConfig>>,
player_status: Mutex<crate::core::message::PlayerStatusData>,
ble_ready: AtomicBool,
@@ -62,6 +63,7 @@ impl HttpState {
payload: None,
}),
wifi_response_cv: Condvar::new(),
last_wifi_result: Mutex::new(None),
config: Mutex::new(config),
player_status: Mutex::new(player_status),
ble_ready: AtomicBool::new(false),
@@ -72,9 +74,22 @@ impl HttpState {
fn publish_wifi_result(&self, payload: String) {
if let Ok(mut state) = self.wifi_response.lock() {
state.version += 1;
state.payload = Some(payload);
state.payload = Some(payload.clone());
self.wifi_response_cv.notify_all();
}
if let Ok(mut last_wifi_result) = self.last_wifi_result.lock() {
*last_wifi_result = Some(payload.clone());
}
let ws_payload = match serde_json::from_str::<serde_json::Value>(&payload) {
Ok(value) => encode_ws_event("wifi_update", value),
Err(_) => encode_ws_event("wifi_update", serde_json::json!({ "raw": payload })),
};
if let Some(ws_payload) = ws_payload {
self.publish_ws(ws_payload);
}
}
pub(crate) fn config(&self) -> Arc<AppConfig> {
@@ -137,6 +152,19 @@ impl HttpState {
snapshots.push(payload);
}
if let Ok(last_wifi_result) = self.last_wifi_result.lock() {
if let Some(raw) = last_wifi_result.as_ref() {
let payload = match serde_json::from_str::<serde_json::Value>(raw) {
Ok(value) => encode_ws_event("wifi_update", value),
Err(_) => encode_ws_event("wifi_update", serde_json::json!({ "raw": raw })),
};
if let Some(payload) = payload {
snapshots.push(payload);
}
}
}
snapshots
}