#!/bin/bash # E2E test for block ID functionality via the o CLI # Requires: running olliesrv, existing agent with chat history # # This test verifies: # 1. Block IDs can be extracted from log.raw (JSONL) # 2. block file returns JSON for exact ID # 3. Partial IDs are rejected # 4. Non-existent IDs return proper error # 5. Different block types (user, assistant, call, tool) work set -e SESSION="default" AGENT="src:ollie" echo "=== Block ID E2E Test ===" # Get some block IDs from the JSONL log echo "Extracting block IDs from log.raw..." BLOCK_IDS=$(o read session/$SESSION/agent/$AGENT/log.raw 2>&1 | grep -oE '"id":"[a-f0-9]{8}"' | sed 's/"id":"//;s/"//' | tail -5) if [ -z "$BLOCK_IDS" ]; then echo "FAIL: No block IDs found in log.raw" exit 1 fi echo "Found block IDs: $(echo $BLOCK_IDS | tr '\n' ' ')" # Test 1: Lookup existing blocks echo "" echo "Test 1: Lookup existing blocks via block file..." for bid in $BLOCK_IDS; do result=$(o rdwr session/$SESSION/agent/$AGENT/block "$bid" 2>&1) if echo "$result" | grep -q '"id":"'$bid'"'; then echo " PASS: Found block $bid" else echo " FAIL: Block $bid not found or malformed" echo " Got: $result" exit 1 fi done # Test 2: Partial ID rejection echo "" echo "Test 2: Partial ID rejection..." FIRST_ID=$(echo "$BLOCK_IDS" | head -1) PARTIAL=${FIRST_ID:0:4} if o rdwr session/$SESSION/agent/$AGENT/block "$PARTIAL" 2>&1 | grep -q "block not found"; then echo " PASS: Partial ID '$PARTIAL' correctly rejected" else echo " FAIL: Partial ID '$PARTIAL' should be rejected" exit 1 fi # Test 3: Non-existent ID echo "" echo "Test 3: Non-existent ID..." if o rdwr session/$SESSION/agent/$AGENT/block "deadbeef" 2>&1 | grep -q "block not found"; then echo " PASS: Non-existent ID 'deadbeef' correctly rejected" else echo " FAIL: Non-existent ID should return error" exit 1 fi # Test 4: Block JSON structure validation echo "" echo "Test 4: Block JSON structure validation..." FIRST_ID=$(echo "$BLOCK_IDS" | head -1) BLOCK=$(o rdwr session/$SESSION/agent/$AGENT/block "$FIRST_ID" 2>&1) if echo "$BLOCK" | grep -qE '^\{"role":"[^"]+","id":"[a-f0-9]{8}","content":'; then echo " PASS: Block has proper JSON structure with role, id, content" else echo " FAIL: Block missing required JSON fields" echo " Got: $BLOCK" exit 1 fi echo "" echo "=== All E2E tests passed ==="