File size: 1,823 Bytes
8830fa5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# Boot agent's app, seed data, run Playwright structural checks.
set -uo pipefail

mkdir -p /logs/verifier /logs/artifacts

for p in 5001 5173; do
    pids=$(lsof -ti :$p 2>/dev/null || true)
    if [ -n "$pids" ]; then
        echo "[test.sh] pre-clearing port $p (pids: $pids)"
        echo "$pids" | xargs -r kill -9 2>/dev/null || true
    fi
done
rm -f /app/backend/instance/*.db /app/backend/*.db 2>/dev/null || true

echo "[test.sh] starting backend (Flask :5001)..."
FLASK_DEBUG=0 nohup /opt/venv/bin/python /app/backend/run.py > /logs/artifacts/backend.log 2>&1 &
BACKEND_PID=$!

echo "[test.sh] starting frontend (Vite :5173)..."
( cd /app/frontend && nohup npm run dev -- --host 127.0.0.1 --port 5173 > /logs/artifacts/frontend.log 2>&1 & echo $! > /tmp/vite.pid )

cleanup() {
    kill "$BACKEND_PID" 2>/dev/null || true
    if [ -f /tmp/vite.pid ]; then kill "$(cat /tmp/vite.pid)" 2>/dev/null || true; fi
    for p in 5001 5173; do
        pids=$(lsof -ti :$p 2>/dev/null || true)
        [ -n "$pids" ] && echo "$pids" | xargs -r kill -9 2>/dev/null || true
    done
}
trap cleanup EXIT

for i in $(seq 1 60); do
    curl -fsS http://127.0.0.1:5001/api/groups -o /dev/null 2>/dev/null && { echo "[test.sh] backend up after ${i}s"; break; }
    sleep 1
done
for i in $(seq 1 90); do
    curl -fsS http://127.0.0.1:5173/ -o /dev/null 2>/dev/null && { echo "[test.sh] frontend up after ${i}s"; break; }
    sleep 1
done

echo "[test.sh] seeding..."
/opt/venv/bin/python /tests/seed.py || { echo 0 > /logs/verifier/reward.txt; exit 0; }

echo "[test.sh] running pytest..."
/opt/venv/bin/pytest --ctrf /logs/verifier/ctrf.json /tests/test_addexpense_sparse.py -rA
PYTEST_RC=$?

if [ $PYTEST_RC -eq 0 ]; then
    echo 1 > /logs/verifier/reward.txt
else
    echo 0 > /logs/verifier/reward.txt
fi
exit 0