fleet-memory/scripts/test-doc-examples.sh
Nicolò Boschi aefb3fcf4d
fix: improve async batch retain with large payloads (#366)
* fix: improve async batch retain with large payloads

* fix: improve async batch retain with large payloads

* api

* api

* api

* api

* api

* Clean up perf benchmark: keep only Python files

- Remove README.md and PERFORMANCE_FINDINGS.md
- Remove results/ JSON files (gitignored)
- Remove test_data/ directory
- Keep only __init__.py and retain_perf.py

* docs: explain automatic batch optimization for async retain

- Add section explaining Hindsight automatically handles batch sizing
- Users don't need to manually tune batch sizes with async mode
- Hindsight splits large batches (>10k tokens) into optimized sub-batches
- Include example showing best practices

* docs: remove emojis and code example from performance page

* fix: correct OperationDetails type to match API response

- Change optional fields to use | null instead of ?
- Fixes TypeScript compilation error in control plane build

* fix: use discriminated union for OperationDetails type

- Support both success and error states properly
- Fixes TypeScript error when setting error state

* fix: use unique document_ids in batch retain examples

- Each item in a batch must have unique document_id
- Update both Python and JavaScript examples
- Fixes test-doc-examples CI failure

* chore: trigger CI

* fix: test mocking and duplicate document_ids in examples

- Mock _get_pool() in test_async_retain_tags.py to avoid _initialized error
- Set _initialized = True on mocked MemoryEngine instances
- Fix duplicate document_ids in retain.py and retain.mjs examples

* fix: properly mock async pool/connection and fix more duplicate document_ids

- Use AsyncMock for pool.acquire() to fix 'can't be used in await' error
- Fix duplicate document_ids in retain-async examples (retain.py and retain.mjs)
- Remove batch-level document_id parameter that caused duplicates

* ci: collect all doc example failures and show summary

- Run all Python/Node.js/CLI examples regardless of individual failures
- Collect failure list and display summary at the end
- Show pass/fail count and list of failed files
- Exit with failure only after running all examples

* refactor: extract doc example testing to standalone script

- Create scripts/test-doc-examples.sh to run all examples
- Collects logs of failed examples separately
- Shows full error logs only for failures at the end
- Clean summary with pass/fail counts
- Proper exit codes
- Replaces inline bash in CI workflow

* fix: doc examples - duplicate document_ids and error handling

- retain.py: move document_id to item level to avoid duplicates
- documents.mjs: add error handling for getDocument to show clear error message

* fix: update tests for duplicate document_id validation

- test_async_retain_tags: verify operation structure instead of exact UUID
- test_delete_bank: use unique document_ids (team-doc-1, team-doc-2)
2026-02-16 12:51:42 +01:00

111 lines
2.9 KiB
Bash
Executable file

#!/bin/bash
set +e # Don't exit on errors - we want to collect all failures
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
EXAMPLES_DIR="$PROJECT_ROOT/hindsight-docs/examples/api"
LOG_DIR="/tmp/doc-example-logs"
mkdir -p "$LOG_DIR"
TOTAL_PASSED=0
TOTAL_FAILED=0
FAILED_EXAMPLES=()
echo "======================================"
echo "Running Documentation Examples"
echo "======================================"
echo ""
# Function to run a single example
run_example() {
local file="$1"
local runner="$2"
local workdir="${3:-$PROJECT_ROOT}"
local basename=$(basename "$file")
local logfile="$LOG_DIR/$basename.log"
echo -n "Running $basename... "
pushd "$workdir" > /dev/null 2>&1
if $runner "$file" > "$logfile" 2>&1; then
echo -e "${GREEN}✓ PASS${NC}"
TOTAL_PASSED=$((TOTAL_PASSED + 1))
rm -f "$logfile" # Clean up successful test logs
popd > /dev/null 2>&1
return 0
else
echo -e "${RED}✗ FAIL${NC}"
TOTAL_FAILED=$((TOTAL_FAILED + 1))
FAILED_EXAMPLES+=("$basename:$logfile")
popd > /dev/null 2>&1
return 1
fi
}
# Run Python examples
echo "======================================"
echo "Python Examples"
echo "======================================"
cd "$PROJECT_ROOT/hindsight-clients/python"
for f in "$EXAMPLES_DIR"/*.py; do
[ -e "$f" ] || continue # Skip if no files match
run_example "$f" "uv run python" "$PROJECT_ROOT/hindsight-clients/python"
done
echo ""
# Run Node.js examples
echo "======================================"
echo "Node.js Examples"
echo "======================================"
cd "$PROJECT_ROOT"
for f in "$EXAMPLES_DIR"/*.mjs; do
[ -e "$f" ] || continue # Skip if no files match
run_example "$f" "node" "$PROJECT_ROOT"
done
echo ""
# Run CLI examples
echo "======================================"
echo "CLI Examples"
echo "======================================"
cd "$PROJECT_ROOT"
for f in "$EXAMPLES_DIR"/*.sh; do
[ -e "$f" ] || continue # Skip if no files match
run_example "$f" "bash" "$PROJECT_ROOT"
done
echo ""
# Print summary
echo "======================================"
echo "Summary"
echo "======================================"
echo -e "${GREEN}Passed: $TOTAL_PASSED${NC}"
echo -e "${RED}Failed: $TOTAL_FAILED${NC}"
echo ""
# If there are failures, show the logs
if [ $TOTAL_FAILED -gt 0 ]; then
echo "======================================"
echo "Failed Example Logs"
echo "======================================"
for entry in "${FAILED_EXAMPLES[@]}"; do
IFS=':' read -r name logfile <<< "$entry"
echo ""
echo -e "${YELLOW}=== $name ===${NC}"
cat "$logfile"
done
echo ""
echo -e "${RED}$TOTAL_FAILED example(s) failed${NC}"
exit 1
fi
echo -e "${GREEN}All examples passed!${NC}"
exit 0