Skip to content
pi-c Artifact [35a3dfac24]
Login

Artifact [35a3dfac24]

Artifact 35a3dfac24f121131c7c2aecdcc36383f69358d30b829c420b507b6a80ef9630:


#!/bin/sh
# The state behind the slash commands, through the command line: trust,
# the scoped models, bug reports (rows in ~/.pic/pic.sqlite), a Pi session
# imported as a conversation, a conversation as HTML, and its tree.
set -eu
PIC=${PIC:?set PIC to the pic binary}
T=$(mktemp -d "${TMPDIR:-/tmp}/pic-slash.XXXXXX")
trap 'rm -rf -- "$T"' EXIT HUP INT TERM
fail() { printf 'FAIL: %s\n' "$*" >&2; exit 1; }
mkdir "$T/ws" "$T/home"
export HOME="$T/home"
pic() { "$PIC" --db "$T/j" --workspace "$T/ws" "$@"; }

[ "$(pic trust)" = undecided ] || fail "trust: not undecided at first"
[ "$(pic trust yes)" = trusted ] || fail "trust yes"
[ "$(pic trust)" = trusted ] || fail "trust not kept"
[ "$(pic trust no)" = untrusted ] || fail "trust no"
pic trust maybe 2> /dev/null && fail "trust maybe accepted"
printf 'PASS: the workspace trust decision is stored and changed\n'

[ -z "$(pic scoped-models)" ] || fail "scoped models not empty at first"
pic scoped-models --set anthropic/claude-haiku-5-5 'openai/*' fake/m
[ "$(pic scoped-models | tr '\n' ' ')" = 'anthropic/claude-haiku-5-5 openai/* fake/m ' ] || fail "scoped models order"
pic scoped-models --set fake/m
[ "$(pic scoped-models)" = fake/m ] || fail "scoped models not replaced"
pic scoped-models --clear
[ -z "$(pic scoped-models)" ] || fail "scoped models not cleared"
printf 'PASS: the scoped models are stored in order, replaced and cleared\n'

pic bug 'the footer overlaps <b>' | grep -q 'nothing was sent' || fail "bug: message"
pic bug 'second' > /dev/null
[ "$(pic bug --list | wc -l | tr -d ' ')" = 2 ] || fail "bug: two rows"
pic bug --list | head -1 | grep -q 'the footer overlaps <b>' || fail "bug: text"
printf 'PASS: bug reports are kept locally and listed\n'

cat > "$T/pi.jsonl" <<'JSONL'
{"type":"session","version":3,"id":"abc","timestamp":"2026-01-01T00:00:00.000Z","cwd":"/x"}
{"type":"session_info","id":"n1","parentId":null,"timestamp":"2026-01-01T00:00:00.000Z","name":"imported one"}
{"type":"message","id":"m1","parentId":null,"timestamp":"2026-01-01T00:00:01.000Z","message":{"role":"user","content":"What is 2 + 2 <script>?"}}
{"type":"message","id":"m2","parentId":"m1","timestamp":"2026-01-01T00:00:02.000Z","message":{"role":"assistant","content":[{"type":"thinking","thinking":"hm"},{"type":"text","text":"Let me check."},{"type":"toolCall","id":"c1","name":"bash","arguments":{"command":"echo 4"}}]}}
{"type":"message","id":"m3","parentId":"m2","timestamp":"2026-01-01T00:00:03.000Z","message":{"role":"toolResult","toolCallId":"c1","toolName":"bash","content":[{"type":"text","text":"4"}]}}
{"type":"message","id":"m4","parentId":"m3","timestamp":"2026-01-01T00:00:04.000Z","message":{"role":"assistant","content":[{"type":"text","text":"It is 4."}]}}
{"type":"message","id":"m5","parentId":"m4","timestamp":"2026-01-01T00:00:05.000Z","message":{"role":"user","content":[{"type":"text","text":"And 3 + 3?"}]}}
{"type":"message","id":"m6","parentId":"m5","timestamp":"2026-01-01T00:00:06.000Z","message":{"role":"assistant","content":[{"type":"text","text":"It is 6."}]}}
JSONL
id=$(pic import "$T/pi.jsonl" 2> "$T/err") || fail "import: $(cat "$T/err")"
pic check > /dev/null || fail "import: integrity"
pic sessions | grep -q 'imported one' || fail "import: name"
pic log "$id" | grep -q 'It is 4' || fail "import: answer 1"
pic log "$id" | grep -q 'It is 6' || fail "import: answer 2"
pic log "$id" | grep -q 'And 3 + 3' || fail "import: user 2"
pic import - < "$T/pi.jsonl" > /dev/null 2>&1 || fail "import from stdin"
printf '{"type":"session"}\n' | pic import - 2> /dev/null && fail "import of a file without messages accepted"
pic check > /dev/null || fail "import: integrity after the failed import"
printf 'PASS: a Pi session imports as a conversation (text only), from a file or stdin\n'

pic export --html "$id" "$T/out.html"
grep -q '<!doctype html>' "$T/out.html" || fail "html: doctype"
grep -q 'What is 2 + 2 &lt;script&gt;?' "$T/out.html" || fail "html: user text not escaped"
grep -q 'It is 6.' "$T/out.html" || fail "html: answer"
grep -qE 'src=|href=|<script|@import|url\(' "$T/out.html" && fail "html: external resource or script"
pic export --html "$id" - | cmp -s - "$T/out.html" || fail "html: - differs from the file"
printf 'PASS: a conversation exports as a self-contained HTML page\n'

# The tree: a fork at the first answer, then a request on each branch.
first=$(pic tree --json "$id" | head -1 | sed 's/.*"end":\([0-9]*\).*/\1/')
fork=$(pic fork "$id" --at "$first")
[ "$(pic tree --json "$id" | wc -l | tr -d ' ')" = 2 ] || fail "tree: two requests before the new branch"
pic tree --json "$id" | head -1 | grep -q '"active":true' || fail "tree: first request not active"
pic tree --json "$fork" | grep -q "\"sessions\":\"$fork\"" || fail "tree: the fork's head not shown"
pic tree --json "$id" | grep -q "\"sessions\":\"$id\"" || fail "tree: the original's head not shown"
printf 'PASS: the tree lists requests, the active path and the sessions at their heads\n'
pic submit branch-1 'a second thought' --session "$fork" > /dev/null
pic tree --json "$id" | awk 'END { exit NR == 3 ? 0 : 1 }' || fail "tree: three requests with the branch"
pic tree --json "$id" | grep 'a second thought' | grep -q '"indent":1' || fail "tree: the branch is not indented"
pic tree --json "$id" | grep 'And 3 + 3' | grep -q '"indent":1' || fail "tree: the original continuation is not indented"
pic tree --json "$id" | head -1 | grep -q '"indent":0' || fail "tree: the root is indented"
printf 'PASS: a branch point indents its branches\n'