// Exercise the real durable wake state machine with failed hardware/NVS/replies. const fs=require('node:fs'), path=require('node: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_screen_wake.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"','')+String.raw` #include #include #include #include typedef int esp_err_t,nvs_handle_t; #define ESP_OK 0 #define ESP_FAIL -1 #define ESP_ERR_NVS_NOT_FOUND 1 #define ESP_ERR_INVALID_STATE 2 #define ESP_ERR_INVALID_RESPONSE 3 #define NVS_READONLY 0 #define NVS_READWRITE 1 static bool standby,storage_fail,power_fail,present,staged_present; static unsigned calls,commits,nonce; static unsigned char stored[256],staged[256]; static size_t stored_size,staged_size; static bool call_client_standby(void){return standby;} static int device_power_apply(const char *mode,bool held){assert(!strcmp(mode,"active")&&!held);calls++;if(power_fail)return -1;standby=false;return 0;} static void esp_fill_random(void *out,size_t size){uint32_t *p=out;for(size_t i=0;i=stored_size);memcpy(out,stored,stored_size);*size=stored_size;return 0;} static int nvs_set_blob(int n,const char *key,const void *data,size_t size){assert(sizeversion=2;present=true;stored_size=sizeof(wake_event_t); assert(device_screen_wake_init()==ESP_ERR_INVALID_STATE); puts("PASS screen wake: wake-only tap, startup intent, durable offline/reboot intent, duplicate tap, failed persistence/hardware/ACK, revision-fenced receipts"); } `);