diff --git a/docs/validation/raw/collect-live-operations.sh b/docs/validation/raw/collect-live-operations.sh index 68b1e7f..cd756c4 100755 --- a/docs/validation/raw/collect-live-operations.sh +++ b/docs/validation/raw/collect-live-operations.sh @@ -13,6 +13,8 @@ root=$(mktemp -d) live="$root/live" mkdir -p "$live/backups" server_pid="" +trace_file=${TRACE_FILE:-} +if [[ -n "$trace_file" ]]; then : > "$trace_file"; fi cleanup() { set +e if [[ -n "$server_pid" ]]; then kill "$server_pid" 2>/dev/null || true; fi @@ -34,7 +36,12 @@ trap cleanup EXIT run_ps() { local script=$1 encoded encoded=$(printf '%s' "$script" | iconv -t UTF-16LE | base64 -w0) - ssh -o BatchMode=yes "$WINDOWS_HOST" "powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand $encoded" + if [[ -n "$trace_file" ]]; then + printf '\n--- POWERSHELL COMMAND ---\n%s\n--- RAW OUTPUT ---\n' "$script" >> "$trace_file" + ssh -o BatchMode=yes "$WINDOWS_HOST" "powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand $encoded" 2>&1 | tee -a "$trace_file" + else + ssh -o BatchMode=yes "$WINDOWS_HOST" "powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand $encoded" + fi } json_from_ps() { run_ps "$1" 2>/dev/null | tr -d '\r' | awk '/^\{.*\}$/ {line=$0} END {if (line != "") print line}' @@ -59,7 +66,7 @@ PS json_from_ps "$script" } queue_json() { - json_from_ps "\$q=\"$WINDOWS_DIR/data/remote-data-queue.json\"; \$pending=0; \$bytes=0; if(Test-Path \$q){\$bytes=(Get-Item \$q).Length; try{\$pending=@((Get-Content -Raw \$q|ConvertFrom-Json).items).Count}catch{}}; [ordered]@{queue_bytes=\$bytes;queue_pending=\$pending}|ConvertTo-Json -Compress" + json_from_ps "\$q=\"$WINDOWS_DIR/data/remote-data-queue.json\"; \$pending=0; \$bytes=0; if(Test-Path \$q){\$bytes=(Get-Item \$q).Length; try{\$pending=@((Get-Content -Raw \$q|ConvertFrom-Json).items).Count}catch{}}; \$queueSha=if(Test-Path \$q){(Get-FileHash \$q -Algorithm SHA256).Hash}else{\"\"}; \$state=\"$WINDOWS_DIR/data/remote-data-sync-state.json\"; \$stateSha=if(Test-Path \$state){(Get-FileHash \$state -Algorithm SHA256).Hash}else{\"\"}; [ordered]@{queue_bytes=\$bytes;queue_pending=\$pending;queue_sha256=\$queueSha;state_sha256=\$stateSha}|ConvertTo-Json -Compress" } start_server() { WXAGENT_CONTROL_PLANE_ADDR=0.0.0.0:8090 \ @@ -73,8 +80,9 @@ start_server() { WXAGENT_WEB_PASSWORD="$WEB_PASSWORD" \ "$CONTROL_PLANE_BIN" >"$live/server.log" 2>&1 & server_pid=$! + if [[ -n "$trace_file" ]]; then printf 'LOCAL_START_SERVER pid=%s sha256=%s\n' "$server_pid" "$(sha256sum "$CONTROL_PLANE_BIN" | awk '{print $1}')" >> "$trace_file"; fi } -stop_server() { [[ -n "$server_pid" ]] && kill "$server_pid" 2>/dev/null || true; server_pid=""; } +stop_server() { if [[ -n "$server_pid" ]]; then if [[ -n "$trace_file" ]]; then printf 'LOCAL_STOP_SERVER pid=%s\n' "$server_pid" >> "$trace_file"; fi; kill "$server_pid" 2>/dev/null || true; fi; server_pid=""; } sync_json() { curl -fsS -H "Authorization: Bearer $NODE_TOKEN" "http://127.0.0.1:8090/v1/nodes/local-node/data/accounts/$ACCOUNT_ID/sync-status"; } sync_summary() { sync_json | jq -c '{state,confirmed_sequence,last_success_at}'; } shard_json() { @@ -122,13 +130,16 @@ revoke=$(curl -sS -o "$root/revoke" -w '%{http_code}' -X POST -H "Authorization: conv=$(curl -sS -o "$root/conv" -w '%{http_code}' -H "Authorization: Bearer $web_token" "http://127.0.0.1:8090/v1/data/accounts/$ACCOUNT_ID/conversations") msgs=$(curl -sS -o "$root/msg" -w '%{http_code}' -H "Authorization: Bearer $web_token" "http://127.0.0.1:8090/v1/data/accounts/$ACCOUNT_ID/messages?chat_id=filehelper&limit=10") sync=$(curl -sS -o "$root/sync" -w '%{http_code}' -H "Authorization: Bearer $web_token" "http://127.0.0.1:8090/v1/data/accounts/$ACCOUNT_ID/sync-status") -echo "{\"event\":\"authorization-revoke\",\"revoke\":$revoke,\"conversations\":$conv,\"messages\":$msgs,\"sync_status\":$sync}" +reject_payload=$(jq -nc --arg account "$ACCOUNT_ID" '{node_id:"local-node",account_id:$account,batch_id:"revoked-batch-harness",source_generation:$account,stream_key:"messages",sequence:99,cursor_start:"0",cursor_end:"1",payload_hash:"revoked-batch-hash",coverage_state:"complete",conversations:[],messages:[]}') +batch_rejected=$(curl -sS -o "$root/rejected" -w '%{http_code}' -X POST -H "Authorization: Bearer $NODE_TOKEN" -H 'Content-Type: application/json' --data-binary "$reject_payload" http://127.0.0.1:8090/v1/data/batches) +echo "{\"event\":\"authorization-revoke\",\"revoke\":$revoke,\"conversations\":$conv,\"messages\":$msgs,\"sync_status\":$sync,\"batch_rejected\":$batch_rejected}" restore_process=$(start_tray) sleep 5 web_token=$(curl -fsS -X POST http://127.0.0.1:8090/v1/auth/login -H 'Content-Type: application/json' -d "{\"username\":\"admin\",\"password\":\"$WEB_PASSWORD\"}" | jq -r .access_token) conv=$(curl -sS -o /dev/null -w '%{http_code}' -H "Authorization: Bearer $web_token" "http://127.0.0.1:8090/v1/data/accounts/$ACCOUNT_ID/conversations") msgs=$(curl -sS -o /dev/null -w '%{http_code}' -H "Authorization: Bearer $web_token" "http://127.0.0.1:8090/v1/data/accounts/$ACCOUNT_ID/messages?chat_id=filehelper&limit=10") -echo "{\"event\":\"authorization-restore\",\"process\":$restore_process,\"conversations\":$conv,\"messages\":$msgs}" +restore_queue=$(queue_json) +echo "{\"event\":\"authorization-restore\",\"process\":$restore_process,\"conversations\":$conv,\"messages\":$msgs,\"queue\":$restore_queue}" before_shard=$(shard_json) old_server_pid=$server_pid