Artifact a01e099cedbd3f0e8697c3160c141779a033c458f60ac2eb5789da69a10389ec:
- File
test/pic/migrate.sh
— part of check-in
[c55dfbb163]
at
2026-11-19 23:39:49
on branch images
— Images, as Pi's
User messages, steering and follow-ups, and tool results can carry images. Journal version 9 keeps their bytes in SQLite (pic_image, deduplicated by SHA3-256, deflated only when smaller) linked by pic_attachment, written in the same transaction as the entry; pic check covers them. Each adapter sends its native shape (Anthropic base64 blocks, Chat image_url data URLs, Responses input_image); a model whose catalog input lacks images gets Pi's placeholders. pic ask --image PATH, the RPC images field and the read tool on image files add them; the Pi and HTML exports include them. (user: dmestas, size: 3937) [annotate] [blame] [check-ins using]
#!/bin/sh # Journals written by earlier pic versions open with the current one: the # schema-3 fixture is migrated in place, passes pic check, keeps its history, # and takes new work. Needs the sqlite3 command to build the fixture. set -eu PIC=${PIC:?set PIC to the pic binary} command -v sqlite3 > /dev/null || { echo "migrate: skipped, no sqlite3 command"; exit 0; } T=$(mktemp -d "${TMPDIR:-/tmp}/pic-migrate.XXXXXX") # pic keeps user state under HOME: never the real one. export HOME="$T/home" mkdir -p "$HOME" trap 'rm -rf -- "$T"' EXIT HUP INT TERM fail() { printf 'FAIL: %s\n' "$*" >&2; exit 1; } DB="$T/journal.sqlite" mkdir "$T/ws" sqlite3 "$DB" < "$(dirname "$0")/journal-v3.sql" pic() { "$PIC" --db "$DB" --workspace "$T/ws" "$@"; } pic check > /dev/null || fail "migrated journal fails pic check" out=$(pic dump) printf '%s\n' "$out" | grep -qF 'entry 2 1 assistant | [{"type":"thinking","thinking":"Write it.","signature":"SIG-OLD"},{"type":"toolCall","id":"toolu_old","name":"write","arguments":{"path":"notes.txt","content":"hi"}}]' || fail "reply not converted to the neutral form" printf '%s\n' "$out" | grep -q '^entry 4 1 answer | \[{"type":"text","text":"done"}\]$' || fail "answer" printf '%s\n' "$out" | grep -q '^generation 1 1.0.1 done stop=toolUse' || fail "stop reasons not renamed" [ "$(sqlite3 "$DB" "SELECT value FROM pic_meta WHERE key='schema_version'")" = 9 ] || fail "version not 9" # Version 8 adds the queue of steering and follow-up messages, empty. [ "$(sqlite3 "$DB" "SELECT count(*) FROM pic_queued")" = 0 ] || fail "no empty pic_queued" # Version 9 adds images and their attachments, empty. [ "$(sqlite3 "$DB" "SELECT count(*) FROM pic_image") $(sqlite3 "$DB" "SELECT count(*) FROM pic_attachment")" = "0 0" ] || fail "no empty pic_image and pic_attachment" # Times older journals never wrote come from the ask key (054 ms, leading zero kept). [ "$(sqlite3 "$DB" "SELECT group_concat(DISTINCT created_ms) FROM pic_entry WHERE submission_id = 1")" = 1795035064054 ] || fail "entry times: $(sqlite3 "$DB" "SELECT group_concat(coalesce(created_ms, 'null')) FROM pic_entry")" [ "$(sqlite3 "$DB" "SELECT created_ms FROM pic_session")" = 1795035064054 ] || fail "session time: $(sqlite3 "$DB" "SELECT created_ms FROM pic_session")" [ "$(sqlite3 "$DB" "SELECT count(*) FROM pic_session")" = 1 ] || fail "submission not given a session" [ "$(sqlite3 "$DB" "SELECT group_concat(coalesce(parent_seq, 0), ' ') FROM (SELECT parent_seq FROM pic_entry WHERE submission_id = 1 ORDER BY seq)")" = "0 1 2 3" ] || fail "entries not chained" [ "$(sqlite3 "$DB" "SELECT provider || '/' || model || ' ' || (native LIKE '%tool_use%') FROM pic_entry WHERE seq=2")" = \ "anthropic/unknown 1" ] || fail "origin or native form" printf 'tool write new.txt again\ntext done again\n' > "$T/script" pic submit job-2 'more' > /dev/null pic run --script "$T/script" pic check > /dev/null || fail "journal broken after new work" [ "$(cat "$T/ws/new.txt")" = again ] || fail "new work did not run" printf 'PASS: a schema-3 journal migrates and keeps working\n' # A version-8 journal (the last without images) steps to 9 alone, keeps its # rows, and takes new work. DB="$T/v8.sqlite" sqlite3 "$DB" < "$(dirname "$0")/journal-v3.sql" pic check > /dev/null || fail "v8: setup" sqlite3 "$DB" "DROP TABLE pic_attachment; DROP TABLE pic_image; UPDATE pic_meta SET value='8' WHERE key='schema_version'" pic check > /dev/null || fail "v8: migrated journal fails pic check" [ "$(sqlite3 "$DB" "SELECT value FROM pic_meta WHERE key='schema_version'")" = 9 ] || fail "v8: version not 9" [ "$(sqlite3 "$DB" "SELECT count(*) FROM pic_entry")" = 4 ] || fail "v8: entries lost" printf 'text done\n' > "$T/script" pic submit job-3 'more' > /dev/null pic run --script "$T/script" > /dev/null pic check > /dev/null || fail "v8: journal broken after new work" printf 'PASS: a schema-8 journal migrates to 9 and keeps working\n'