#!/bin/bash # Check if correct number of arguments are provided (now 4) if [ "$#" -ne 4 ]; then echo "Usage: $0 " exit 1 fi TASK_ID=$1 CMD=$2 RESULT_DIR=$3 REPO_PATH=$4 echo $TASK_ID # Create result directory if it doesn't exist (absolute path) mkdir -p "$RESULT_DIR" # Use realpath on the (now-existing) result dir and a clearer filename LOG_FILE="$(realpath "$RESULT_DIR")/${TASK_ID}-logging.html" # Initialize HTML file with basic styling cat < "$LOG_FILE"

Execution Log for Task: $TASK_ID

Working Directory: $REPO_PATH

Executing: $CMD


EOF # 1. CD into the repo path # 2. Execute command and capture output # 3. PIPESTATUS[0] captures the exit code of the eval "$CMD" export PYTHONUNBUFFERED=1 echo "--- Execution Start ---" | tee -a >(sed 's/$/
/' >> "$LOG_FILE") cd "$REPO_PATH" && stdbuf -oL -eL eval "$CMD" 2>&1 | tee -a >(sed 's/$/
/' >> "$LOG_FILE") EXIT_CODE=${PIPESTATUS[0]} echo "--- Execution End (Exit Code: $EXIT_CODE) ---" | tee -a >(sed 's/$/
/' >> "$LOG_FILE") # Close HTML tags echo "
" >> "$LOG_FILE" # Determine PASS/FAIL # We consider it a FAIL if the exit code is non-zero if [ $EXIT_CODE -eq 0 ]; then RESULT="PASS" else RESULT="FAIL" fi EVIDENCE_URL="file://$LOG_FILE" # Return JSON output # ... (rest of the script remains the same) # Return JSON output with a unique marker prefix printf 'FINAL_JSON_OUTPUT:{"%s": ["%s", "%s"]}\n' "$TASK_ID" "$RESULT" "$EVIDENCE_URL"