#!/usr/bin/env python3 """Execute real USB logging/mOTA handoffs across retained response boundaries.""" from pathlib import Path import subprocess import tempfile import unittest from test_companion_usb_input import ( CONTEXT, HARNESS, MAIN, ROOT, bind_production_input_constants, ) from test_replay_reset_integration import extract_braced CASES = r''' static void selectAscii() { if (!the_mesh.terminal) { input.push(USB_TERMINAL_START_TOKEN); input.push("\n"); uint8_t frame[MAX_FRAME_SIZE]={}; assert(usb_serial_interface.checkRecvFrame(frame)==0); serviceUsbTerminal(); assert(the_mesh.terminal); } } static void verifyNextClients() { selectAscii(); input.push("get name\r\n"); serviceUsbTerminal(); assert(the_mesh.commands.size()==1 && the_mesh.commands[0]=="get name"); logging=false; serviceUsbLoggingOwnership(false); input.push(USB_TERMINAL_STOP_TOKEN); serviceUsbTerminal(); assert(!the_mesh.terminal && !usb_serial_interface.isPassthroughMode()); input.frame(); uint8_t frame[MAX_FRAME_SIZE]={}; assert(usb_serial_interface.checkRecvFrame(frame)==2); assert(frame[0]==0x16 && frame[1]==3); assert(usb_serial_interface.getCompletedFrameCount()==1); } static void responseHandoffs() { // Every partial stage is exercised, with image bytes that resemble both // ASCII ownership commands and Companion framing (including embedded NUL). const char controls[]="\nget name\r\nota folder off\n+++MESHCORE-TERM-STOP\n"; std::vector payload(controls,controls+sizeof(controls)-1); payload.insert(payload.end(),{'<',2,0,0x16,3}); for (uint8_t status : {uint8_t(0),uint8_t(1)}) { const auto late=response(3,status==0?payload:std::vector{},status); for (size_t prefix=0;prefix data(payload.size()); assert(!source.read(0,0,data.data(),data.size())); assert(source.hasPendingResponse()); logging=network=true; serviceUsbLoggingOwnership(true); assert(!usb_mota_mode && usb_logging_network_parked); assert(usb_serial_interface.isPassthroughMode()); assert(the_mesh.attaches==1 && the_mesh.detaches==1); if (logging_off_before_close) { logging=false; serviceUsbLoggingOwnership(false); assert(!usb_logging_network_parked && source.hasPendingResponse()); assert(usb_serial_interface.isPassthroughMode()); } network=false; logging=logging_after_close; uint8_t command[MAX_FRAME_SIZE]={}; for (size_t i=prefix;i>8)}; for (uint32_t i=0;i