diff options
| author | Igor Soarez <igor@soarez.org> | 2026-11-03 13:05:57 +0200 |
|---|---|---|
| committer | Igor Soarez <igor@soarez.org> | 2026-11-03 13:05:57 +0200 |
| commit | bd1eb9ef9b3b89ff5825eb8bf9b2e978167c9ad0 (patch) | |
| tree | ac3ea2a1f0f2243c692ba5e5fab251df6c9f077b /tests/pi-live.sh | |
| parent | 8146d1db419e8bdacd75920da6f3761abf724853 (diff) | |
show each pi agent's context use: a meter in the panel and search, text in the menu
Diffstat (limited to 'tests/pi-live.sh')
| -rwxr-xr-x | tests/pi-live.sh | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/tests/pi-live.sh b/tests/pi-live.sh index 95c5885..6083be4 100755 --- a/tests/pi-live.sh +++ b/tests/pi-live.sh @@ -16,6 +16,7 @@ PI_BIN=$(cd "$(dirname "$1")" && pwd)/$(basename "$1") ROOT=$(cd "$(dirname "$0")/.." && pwd) DINGGER="${2:-$ROOT/target/release/dingger}" case "$DINGGER" in /*) ;; *) DINGGER="$PWD/$DINGGER" ;; esac +MENU="$ROOT/target/dingger-menu" D=$(mktemp -d /tmp/dingger-pi-live.XXXXXX) R="dingger-pi-live-$$" PASSES=0; FAILS=0 @@ -50,9 +51,11 @@ 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", "cost": {"input": 100000, "output": 1000000, "cacheRead": 0, "cacheWrite": 0}}]}}} +{"providers": {"fake": {"baseUrl": "http://127.0.0.1:$PORT/v1", "api": "openai-completions", "apiKey": "fake", "models": [{"id": "fake-model", "contextWindow": 400, "cost": {"input": 100000, "output": 1000000, "cacheRead": 0, "cacheWrite": 0}}]}}} EOF - echo '{"defaultProvider": "fake", "defaultModel": "fake-model"}' >"$D/$agent/settings.json" + # A small window, so a few replies fill it measurably; nothing compacts + # on its own, and /compact keeps almost nothing. + echo '{"defaultProvider": "fake", "defaultModel": "fake-model", "compaction": {"enabled": false, "keepRecentTokens": 1}}' >"$D/$agent/settings.json" done PI_CODING_AGENT_DIR="$D/agent" "$DINGGER" install pi >/dev/null cat >"$D/agent/extensions/test-blocked.ts" <<'EOF' @@ -217,6 +220,36 @@ FORK=$(ls -t "$(dirname "$SESSION_FILE")"/*.jsonl | head -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" +# How full its context is: the number pi's footer shows ("3.3%/400"), in +# an agent of its own (compacting would hide this one's conversation from +# the restore below). +mkdir -p "$D/work3" +t new-window -d -t main: -n ctx -c "$D/work3" +t send-keys -t main:ctx "pi $NO_MCP" Enter +expect "context: an agent of its own" "st ctx" idle 150 +footer() { t capture-pane -p -t main:ctx | grep -oE '(\?|[0-9.]+%)/400' | tail -1 | sed 's|/400||'; } +as_footer() { python3 -c "import sys; f=sys.argv[1]; print('' if f in ('?', '') else round(float(f.rstrip('%'))))" "$(footer)"; } +ctx() { t show -pv -t main:ctx @dingger_context 2>/dev/null; } +same_as_footer() { [ "$(ctx)" = "$(as_footer)" ] && echo same || echo "dingger [$(ctx)] footer [$(footer)]"; } +expect "context: none yet" "footer; ctx" "0.0% +0" 30 +for msg in "slow 1 one" "slow 1 two"; do + t send-keys -t main:ctx -l "$msg" && t send-keys -t main:ctx Enter + expect "and done" "st ctx" done 60 +done +expect "context: after replies, pi's footer" "footer" "3.3%" 30 +expect "context: dingger has pi's number" same_as_footer same 30 +t send-keys -t main:ctx -l "/compact" && t send-keys -t main:ctx Enter +expect "context: after compacting, pi does not know" "footer" "?" 60 +expect "context: nor does dingger" same_as_footer same 30 +expect "the menu shows no percentage" "\"$MENU\" --print | grep -F 'main · ctx' | grep -c '%'" 0 +t send-keys -t main:ctx -l "slow 1 after compacting" && t send-keys -t main:ctx Enter +expect "and done" "st ctx" done 60 +expect "context: known again after a reply" "ctx | grep -cE '^[0-9]+$'" 1 30 +expect "context: pi's number again" same_as_footer same 30 +expect "the menu: the percentage last" "\"$MENU\" --print | grep -F 'main · ctx' | cut -f3 | grep -oE ' [0-9]+%$'" " $(ctx)%" +expect "the panel: cost, then context" "\"$MENU\" --print-panel --full | grep -F 'main · ctx' | cut -f4 | grep -oE '^\\\$[0-9.]+ [0-9]+%$' | grep -c ' $(ctx)%'" 1 +t kill-window -t main:ctx 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 |
