Files
Codex Local bf1233d5df
ci / verify (push) Canceled after 0s
feat: expand companion platform, device controls, and memoir workflows
Add customer and operator login, BLE provisioning, device fleet controls, call memory, memoir generation, and refreshed family and maintenance portals. Include API contracts, migrations, firmware sources, tests, assets, and deployment documentation.
2026-10-08 10:06:44 +08:00

57 lines
3.8 KiB
JavaScript

// Execute the production power transition code with failing hardware/NVS doubles.
const fs=require('fs'), path=require('path');
const root=path.resolve(__dirname,'..');
const json=path.join(process.env.IDF_PATH||'E:/Codex/toolchains/esp-idf-v5.5.1','components/json/cJSON');
const source=fs.readFileSync(path.join(root,'main/device_power.c'),'utf8').replace(/^#include[^\n]*\n/gm,'');
process.stdout.write(fs.readFileSync(path.join(json,'cJSON.h'),'utf8')+'\n'+fs.readFileSync(path.join(json,'cJSON.c'),'utf8').replace('#include "cJSON.h"','')+`
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
typedef int esp_err_t;
typedef int nvs_handle_t;
#define ESP_OK 0
#define ESP_FAIL -1
#define ESP_ERR_INVALID_ARG 1
#define ESP_ERR_INVALID_STATE 2
#define ESP_ERR_NVS_NOT_FOUND 3
#define NVS_READONLY 0
#define NVS_READWRITE 1
typedef struct {void *display_handle;} volc_hal_context_t;
static volc_hal_context_t context={(void *)1};
static bool held,busy,standby,paused;
static int brightness=80,stored=-1,staged=-1,commits,storage_error,audio_error,display_error;
static bool call_client_enter_maintenance(void){if(held||busy)return false;held=true;return true;}
static void call_client_leave_maintenance(void){held=false;}
static int call_client_set_standby(bool value){if(busy)return ESP_ERR_INVALID_STATE;standby=value;return 0;}
static bool call_client_standby(void){return standby;}
static int audio_recorder_set_standby(bool value){if(audio_error)return -1;paused=value;return 0;}
static bool audio_recorder_is_standby(void){return paused;}
static uint32_t audio_recorder_microphone_reads(void){return 42;}
static volc_hal_context_t *volc_get_global_hal_context(void){return &context;}
static int volc_hal_display_get_brightness(void *display){return brightness;}
static int volc_hal_display_set_brightness(void *display,int value){if(display_error)return -1;brightness=value;return 0;}
static int nvs_open(const char *name,int mode,int *n){*n=1;return 0;}
static int nvs_get_u8(int n,const char *key,uint8_t *value){if(stored<0)return ESP_ERR_NVS_NOT_FOUND;*value=stored;return 0;}
static int nvs_set_u8(int n,const char *key,uint8_t value){staged=value;return 0;}
static int nvs_commit(int n){if(storage_error)return -1;stored=staged;commits++;return 0;}
static void nvs_close(int n){}
`+source+`
static void expect_mode(const char *mode){cJSON *j=device_power_report();assert(!strcmp(cJSON_GetObjectItem(j,"mode")->valuestring,mode));cJSON_Delete(j);}
int main(void){
assert(device_power_boot()==0);assert(!standby&&!paused);expect_mode("active");
busy=true;assert(device_power_apply("standby",false)!=0);assert(!standby&&!paused&&brightness==80&&commits==0);busy=false;
assert(device_power_apply("off",false)!=0);
assert(device_power_apply("standby",false)==0);assert(standby&&paused&&brightness==0&&stored==1&&!held);expect_mode("standby");
int previous=commits;assert(device_power_apply("standby",false)==0);assert(commits==previous);
held=true;assert(device_power_apply("active",true)==0);assert(held&&!standby&&!paused&&brightness==80&&stored==0);held=false;
display_error=1;assert(device_power_apply("standby",false)!=0);expect_mode("transition");assert(stored==0&&!held);display_error=0;
assert(device_power_apply("active",false)==0);
audio_error=1;assert(device_power_apply("standby",false)!=0);assert(stored==0&&!held);audio_error=0;
storage_error=1;assert(device_power_apply("standby",false)!=0);expect_mode("standby");assert(stored==0&&!held);storage_error=0;
assert(device_power_apply("standby",false)==0);assert(stored==1);
standby=paused=false;brightness=80;assert(device_power_boot()==0);expect_mode("standby");
assert(device_power_apply("active",false)==0);expect_mode("active");
puts("PASS power transitions: busy exclusion, real state, failure paths, persistent standby, default wake and no repeated flash writes");
}
`);