|
| 1 | +#!/usr/bin/env bash |
| 2 | +# shellcheck shell=bash |
| 3 | +# |
| 4 | +# Resuming a session whose id is not a UUID (#573), in Classic and in Next. |
| 5 | +# `--session-id` takes any string, and the history keeps it as given. Two |
| 6 | +# sessions are saved, one with the 2-byte id `ab` and one with |
| 7 | +# `日本語セッション`, whose byte 8 falls inside its third character. A fresh |
| 8 | +# launch resumes each with `/session resume <id>`, which replaced `/resume`. |
| 9 | +# The app keeps running and shows the resumed transcript; Next also shows the |
| 10 | +# shortened id in its status. A fake |
| 11 | +# `claude` answers each turn at once; no network or model. Classic shows the |
| 12 | +# status row only before its first turn, so there only the transcript and the |
| 13 | +# running process are checked. |
| 14 | + |
| 15 | +register_case tc_resume_short_session_id |
| 16 | + |
| 17 | +_rss_fake_claude() { |
| 18 | + cat >"$1" <<'FAKE' |
| 19 | +#!/bin/sh |
| 20 | +# Fake `claude`: answer once and finish. |
| 21 | +cat >/dev/null & |
| 22 | +printf '%s\n' '{"type":"system","subtype":"init","session_id":"fake","model":"fake-model"}' |
| 23 | +printf '%s\n' '{"type":"assistant","message":{"model":"fake-model","content":[{"type":"text","text":"fake answer"}]}}' |
| 24 | +printf '%s\n' '{"type":"result","subtype":"success","is_error":false,"usage":{"input_tokens":3,"output_tokens":1}}' |
| 25 | +FAKE |
| 26 | + chmod +x "$1" |
| 27 | +} |
| 28 | + |
| 29 | +# One saved session: start with the id, answer one prompt, quit. |
| 30 | +_rss_save() { # renderer, id, prompt |
| 31 | + if tui_start --session-id "$2"; then |
| 32 | + tui_type "$3"; tui_keys Enter |
| 33 | + if wait_for "fake answer" 15; then _pass "$1: session $2 answers" |
| 34 | + else _fail "$1: session $2 answers" "$(tui_capture)"; fi |
| 35 | + tui_keys C-c; sleep 0.3; tui_keys C-c |
| 36 | + sleep 1 |
| 37 | + fi |
| 38 | + tui_stop |
| 39 | +} |
| 40 | + |
| 41 | +# Resume one saved session in a fresh launch, so each id is tried on a |
| 42 | +# running app. |
| 43 | +_rss_resume() { # renderer, id, prompt of that session |
| 44 | + local r="$1" id="$2" prompt="$3" running |
| 45 | + if ! tui_start; then return 0; fi |
| 46 | + running="$(_tmux display-message -p -t "$TUI_SESSION" '#{pane_current_command}')" |
| 47 | + tui_type "/session resume $id"; sleep 0.3; tui_keys Enter |
| 48 | + if wait_for "$prompt" 10; then _pass "$r: /session resume $id shows that session's transcript" |
| 49 | + else _fail "$r: /session resume $id shows that session's transcript" "$(tui_capture)"; fi |
| 50 | + sleep 0.5 |
| 51 | + assert_eq "$(_tmux display-message -p -t "$TUI_SESSION" '#{pane_current_command}')" \ |
| 52 | + "$running" "$r: the app is still running after /session resume $id" |
| 53 | + assert_absent "$(tui_capture)" "panicked" "$r: /session resume $id does not panic" |
| 54 | + if [ "$r" = next ]; then |
| 55 | + if wait_for "Resumed session $id." 5; then _pass "$r: the status names session $id" |
| 56 | + else _fail "$r: the status names session $id" "$(tui_capture)"; fi |
| 57 | + fi |
| 58 | + tui_stop |
| 59 | +} |
| 60 | + |
| 61 | +_rss_journey() { # renderer |
| 62 | + local r="$1" scratch |
| 63 | + scratch="$(mktemp -d)" |
| 64 | + mkdir -p "$scratch/home/.coven-code" "$scratch/bin" "$scratch/project" |
| 65 | + printf '%s\n' '{"hasCompletedOnboarding": true}' >"$scratch/home/.coven-code/settings.json" |
| 66 | + _rss_fake_claude "$scratch/bin/claude" |
| 67 | + |
| 68 | + local saved_prefix="$TUI_LAUNCH_PREFIX" saved_boot="$TUI_BOOT_STRING" var ui="" |
| 69 | + TUI_LAUNCH_PREFIX="cd $(printf '%q' "$scratch/project") && env" |
| 70 | + for var in ANTHROPIC_API_KEY ANTHROPIC_BASE_URL OPENAI_API_KEY COVEN_CODE_PROVIDER \ |
| 71 | + COVEN_CODE_API_BASE COVEN_CODE_HOME COVEN_CODE_TEST_HOME COVEN_PARENT \ |
| 72 | + COVEN_DAEMON_SOCKET COVEN_CODE_UI; do |
| 73 | + TUI_LAUNCH_PREFIX+=" -u $var" |
| 74 | + done |
| 75 | + if [ "$r" = next ]; then ui="COVEN_CODE_UI=next"; TUI_BOOT_STRING="preview" |
| 76 | + else TUI_BOOT_STRING="Coven v"; fi |
| 77 | + # shellcheck disable=SC2086 # an empty selector adds nothing |
| 78 | + TUI_LAUNCH_PREFIX+=" $(printf '%q ' "HOME=$scratch/home" "COVEN_HOME=$scratch/home/.coven" \ |
| 79 | + "COVEN_CODE_CLAUDE_BIN=$scratch/bin/claude" $ui)" |
| 80 | + |
| 81 | + _rss_save "$r" ab "alpha question" |
| 82 | + _rss_save "$r" "日本語セッション" "beta question" |
| 83 | + |
| 84 | + _rss_resume "$r" ab "alpha question" |
| 85 | + _rss_resume "$r" "日本語セッション" "beta question" |
| 86 | + |
| 87 | + TUI_LAUNCH_PREFIX="$saved_prefix" |
| 88 | + TUI_BOOT_STRING="$saved_boot" |
| 89 | + rm -rf "$scratch" |
| 90 | +} |
| 91 | + |
| 92 | +tc_resume_short_session_id() { |
| 93 | + describe "/session resume of a short or non-ASCII session id does not panic" |
| 94 | + if ! have_tmux; then _skip "tmux not installed"; return 0; fi |
| 95 | + _rss_journey classic |
| 96 | + _rss_journey next |
| 97 | +} |
0 commit comments