diff options
Diffstat (limited to 'tests/pi-live.sh')
| -rwxr-xr-x | tests/pi-live.sh | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/pi-live.sh b/tests/pi-live.sh index 6dff42f..95c5885 100755 --- a/tests/pi-live.sh +++ b/tests/pi-live.sh @@ -50,7 +50,7 @@ PORT=$(cat "$D/port") for agent in agent agent-plain; do mkdir -p "$D/$agent/extensions" cat >"$D/$agent/models.json" <<EOF -{"providers": {"fake": {"baseUrl": "http://127.0.0.1:$PORT/v1", "api": "openai-completions", "apiKey": "fake", "models": [{"id": "fake-model"}]}}} +{"providers": {"fake": {"baseUrl": "http://127.0.0.1:$PORT/v1", "api": "openai-completions", "apiKey": "fake", "models": [{"id": "fake-model", "cost": {"input": 100000, "output": 1000000, "cacheRead": 0, "cacheWrite": 0}}]}}} EOF echo '{"defaultProvider": "fake", "defaultModel": "fake-model"}' >"$D/$agent/settings.json" done @@ -70,6 +70,10 @@ printf 'set -g default-shell /bin/sh\nset -g default-command /bin/sh\n' >"$D/tmu # Every pi here uses the test's agent directory, including one a restore # starts (`pi --session`, without the command line's own variables). export PATH="$D/bin:$PATH" PI_CODING_AGENT_DIR="$D/agent" PI_OFFLINE=1 PI_SKIP_VERSION_CHECK=1 PI_TELEMETRY=0 +# The fake model's prices make each reply cost $4.00 (10 input tokens at +# $100,000 per million, 3 output at $1,000,000); the daemon reads costs +# from session files every 0.3 s. +export DINGGER_COST_SCAN_SECS=0.3 export DINGGER_TMUX_SOCKET="$R" DINGGER_AGENT_SOCKET="$D/hook.sock" DINGGER_STATE_DIR="$D/state" DINGGER_TMUX_CONFIG="$D/tmux.conf" t -f "$D/tmux.conf" new-session -d -s main -n agent -x 140 -y 40 -c "$D/work" t new-window -d -t main: -n plain -c "$D/work2" @@ -196,6 +200,23 @@ expect "it still works: working" "st agent" working 50 expect "and done" "st agent" done 60 expect "a message sent is no draft" "draft" "" 30 expect "nor kept" "[ -e \"\$(draft_file)\" ] && echo left || echo gone" gone 30 +# What it cost: pi prices each reply; dingger counts them. +replies() { grep -c '"role":"assistant"' "$1"; } +SESSION_FILE=$(t show -pv -t main:agent @agent_session) +N=$(replies "$SESSION_FILE") +[ "$N" -ge 3 ] && pass "$N replies so far" || fail "only $N replies" +WANT=$(python3 -c "print(f'{4*$N:.2f}')" ) +expect "the agent's spend today" "t show -pv -t main:agent @dingger_cost 2>/dev/null" "$WANT" 30 +expect "in total" "t show -gv @dingger_cost_today 2>/dev/null" "$WANT" 30 +expect "and this week and month" "t show -gv @dingger_cost_week; t show -gv @dingger_cost_month" "$WANT +$WANT" +# A fork copies the session's replies into a new file, then adds its own. +(cd "$D/work" && pi --fork "$SESSION_FILE" -p "slow 1 forked" $NO_MCP >"$D/fork.out" 2>&1) +FORK=$(ls -t "$(dirname "$SESSION_FILE")"/*.jsonl | head -1) +[ "$FORK" != "$SESSION_FILE" ] && [ "$(replies "$FORK")" -eq $((N + 1)) ] \ + && pass "pi --fork: a new file with the $N replies copied and its own" || fail "fork: $FORK ($(replies "$FORK") replies)" +expect "the fork adds only its own reply" "t show -gv @dingger_cost_today 2>/dev/null" "$(python3 -c "print(f'{4*($N+1):.2f}')")" 30 +expect "the agent's own spend is unchanged" "t show -pv -t main:agent @dingger_cost 2>/dev/null" "$WANT" echo "2. screen detection (pi without the extension)" t send-keys -t main:plain "PI_CODING_AGENT_DIR=$D/agent-plain pi $NO_MCP" Enter |
