Artifact 9576bbe8b18a6afa6b0cbff658380dc8dcc296df56e4f47f40f7854cfa1878c4:
- File
test/tui/tui.sh
— part of check-in
[dd27c70e9d]
at
2026-11-19 16:10:29
on branch userdb
— User state in ~/.pic/pic.sqlite instead of loose files (ticket 2ad667b78b)
pic's user-level state now lives in one SQLite database, shared by every pic process (WAL, a busy timeout), in tables prefixed picu_: settings, the model catalog cache from pi.dev (stored with the SQLite Archive compression rule; sqlar_compress and sqlar_uncompress are registered), project trust, model scopes and the workspaces pic has used. ~/.pic/settings.json and ~/.pic/models-store.json are imported on first open in one transaction and then deleted. pic settings shows and changes settings. Tests and benchmarks now run with a private HOME and an offline catalog, so they no longer read or write the real ~/.pic. (user: dmestas, size: 4144) [annotate] [blame] [check-ins using] [more...]
#!/bin/sh # The terminal interface, on a pseudo-terminal against a fake server: a # reply streams and lands in the transcript, tool calls show a header and # result, the footer counts tokens, Esc cancels a request, commands work # (/name, /resume with its picker, unknown ones), pic tui -c shows the # history, a resize is survived, Ctrl-D quits. set -eu PIC=${PIC:?set PIC to the pic binary} SERVER=${SERVER:?set SERVER to the fake_server binary} DRIVE=${DRIVE:?set DRIVE to the pty_drive binary} S=$(cd "$(dirname "$0")/../pic/streams" && pwd) T=$(mktemp -d "${TMPDIR:-/tmp}/pic-tui.XXXXXX") spid= cleanup() { [ -n "$spid" ] && kill "$spid" 2>/dev/null; rm -rf -- "$T"; } trap cleanup EXIT HUP INT TERM fail() { printf 'FAIL: %s\n' "$*" >&2; exit 1; } mkdir "$T/ws" "$T/log" "$T/home" export HOME="$T/home" ANTHROPIC_API_KEY=pic-tui-test-key PIC_MODELS_FILE="$T/models.json" PIC_MODEL_CATALOG=offline # 1 text, 2 tool call, 3 text, 4 hang (cancelled), 5 hang (quit), then text "$SERVER" "$T/port" "$T/log" 120 "sse:$S/text.sse" "sse:$S/thinking_tool.sse" "sse:$S/text.sse" "hang:$S/text.sse:200" \ "hang:$S/text.sse:200" "sse:$S/text.sse" & spid=$! i=0 while [ ! -s "$T/port" ]; do i=$((i + 1)); [ "$i" -lt 100 ] || fail "server"; sleep 0.05; done printf '{"providers":{"fake":{"baseUrl":"http://127.0.0.1:%s","api":"anthropic-messages","apiKey":"$ANTHROPIC_API_KEY","models":[{"id":"m","contextWindow":200000}]}}}' \ "$(cat "$T/port")" > "$T/models.json" drive() { # NAME: run pic with the script on stdin name=$1 shift "$DRIVE" "$T/$name.tx" 80 24 "$PIC" --db "$T/j" --workspace "$T/ws" --model fake/m "$@" || fail "$name: $(perl -pe 's/\e\[[0-9;?]*[A-Za-z]//g; s/\r//g' "$T/$name.tx" | grep -v '^\s*$' | tail -8)" } drive first <<'EOF' expect pic fake/m send hello\r expect Hello, "world" expect ↑25 ↓12 send write it\r expect ✓ write t.txt expect Successfully wrote to t.txt expect > send /name main\r expect named main send /bogus\r expect unknown command /bogus size 60 18 wait 300 send \x04 expect pic: conversation EOF [ -f "$T/ws/t.txt" ] || fail "tool: file not written" printf 'PASS: a reply streams, a tool call shows its result, commands work, Ctrl-D quits\n' drive cancel <<'EOF' expect pic fake/m send wait for me\r expect Working wait 500 send \e expect request cancelled send \x04 EOF "$PIC" --db "$T/j" --workspace "$T/ws" check > /dev/null || fail "cancel: integrity" printf 'PASS: Esc cancels the running request\n' drive resume tui -c <<'EOF' expect continuing expect > wait for me send /resume\r expect Resume a conversation send \e[B wait 200 send \r expect continuing expect > hello expect > write it send \x04 EOF printf 'PASS: pic tui -c shows the history; /resume picks a conversation\n' # Quitting while a request is stuck: Ctrl-C twice leaves promptly, the # request is cancelled and the journal is whole. drive quit <<'EOF2' expect pic fake/m send stuck\r expect Working wait 300 send \x03 wait 100 send \x03 expect pic: conversation EOF2 "$PIC" --db "$T/j" --workspace "$T/ws" log | grep -q '(request cancelled)' || fail "quit: request not cancelled" "$PIC" --db "$T/j" --workspace "$T/ws" check > /dev/null || fail "quit: integrity" printf 'PASS: quitting during a stuck request cancels it and exits\n' # Slash menu and model picker: /mod completes with Tab; /model completes a # model name; Ctrl+L opens the picker, typing filters, Enter picks, Ctrl+S # also saves the default; /copy copies the last reply. drive models <<'EOF2' expect pic fake/m send /mod expect select a model send \t send haiku-5-5 expect claude-haiku-5-5 [anthropic] send \r wait 200 send \r expect model anthropic/claude-haiku-5-5 send \x0c expect Select a model send fake expect m [fake] send \r expect model fake/m send \x0c expect Select a model send fake expect ✓ m [fake] send \x13 expect saved as the default send /copy\r expect no reply to copy yet send \x04 EOF2 [ "$("$PIC" --db "$T/j" --workspace "$T/ws" settings defaultModel)" = fake/m ] || fail "models: default not saved" printf 'PASS: the slash menu completes commands and models; the picker filters, picks and saves a default\n'