#!/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 chat log # 2. chat.search finds blocks by exact ID # 3. Partial IDs are rejected # 4. Non-existent IDs return proper error # 5. Different block types (user, assistant, call, tool, error) work set -e SESSION="default" AGENT="src:ollie" echo "=== Block ID E2E Test ===" # Get some block IDs from the log echo "Extracting block IDs from log..." BLOCK_IDS=$(o read session/$SESSION/agent/$AGENT/log 2>&1 | strings | grep -oE '\[\[\[[a-z]+[:#][^]]+#([a-f0-9]{8})\]\]\]' | sed 's/.*#\([a-f0-9]\{8\}\)\]\]\]/\1/' | tail -5) if [ -z "$BLOCK_IDS" ]; then echo "FAIL: No block IDs found in log" exit 1 fi echo "Found block IDs: $(echo $BLOCK_IDS | tr '\n' ' ')" # Test 1: Search for existing blocks echo "" echo "Test 1: Search for existing blocks..." for bid in $BLOCK_IDS; do result=$(o rdwr session/$SESSION/agent/$AGENT/chat.search "$bid" 2>&1) if echo "$result" | grep -q "\[\[\[.*#$bid\]\]\]"; then echo " PASS: Found block $bid" else echo " FAIL: Block $bid not found or malformed" 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/chat.search "$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/chat.search "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 content includes header and end marker echo "" echo "Test 4: Block structure validation..." FIRST_ID=$(echo "$BLOCK_IDS" | head -1) BLOCK=$(o rdwr session/$SESSION/agent/$AGENT/chat.search "$FIRST_ID" 2>&1) if echo "$BLOCK" | grep -q "^\[\[\[" && echo "$BLOCK" | grep -q "\[\[\[end\]\]\]$"; then echo " PASS: Block has proper header and end marker" else echo " FAIL: Block missing header or end marker" echo " Got: $BLOCK" exit 1 fi echo "" echo "=== All E2E tests passed ==="