Files
claude-mode/tests/cli/test_sessions.sh
T
smoidoandClaude Opus 5 b514e00745 README down to what a user needs; the rest into docs/
The README had grown to 1,010 lines of user docs and design notes in one file,
and had gone stale: it still showed the old numbered menu, set up only three
providers, and listed preflight checks and a file layout that predate the last
three releases. It now carries install, first run, the full command
reference, the providers at a glance, troubleshooting and a docs index.

docs/:
- providers.md    presets, defaults, the model cache, context windows, each
                  provider (OpenRouter's cost guard and guardrail check are
                  written up for the first time), adding a provider
- live-sessions.md  what a switch does to running sessions, and repair
- design.md       why settings.json, why keys stay out of it (and the vault
                  per platform), the preflight checks as they are now
- bar-widget.md   the widget as it is now: providers from health.json, every
                  server provider's settings, the restart after an upgrade
- architecture.md the pieces, every file on disk and who writes it, the
                  contracts between them, where to change what
- development.md  running the tests, the conventions the code follows,
                  working on the widget, releasing
CONTRIBUTING.md points at it.

Also:
- The per-project session listing used awk, which the CLI avoids because it
  is missing from minimal images; it uses the script's own TSV helpers now,
  and tests/static.sh fails on any awk in the CLI.
- tests/static.sh checks every relative Markdown link and #anchor.
- A unit test pins the managed env keys between cm-json.py and
  claude-mode.ps1, which only a comment kept in step before.
- test_sessions covers the per-project listing, which nothing ran.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-15 01:52:03 +03:00

64 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Broken transcripts: the scan, dismissing and restoring, the age rule, repair.
. "$(dirname "$0")/../lib.sh"
# The fixture project is filed under the slug of a real directory, so the
# per-project listing (run from inside it) finds it the way Claude Code would.
work="$SB/work"
mkdir -p "$work"
proj="$CLAUDE_CONFIG_DIR/projects/$(printf '%s' "$work" | sed 's|[^a-zA-Z0-9]|-|g')"
mkdir -p "$proj"
transcript() { # <session-id> [age-in-hours]
printf '%s\n' \
'{"type":"assistant","message":{"id":"msg_1","model":"claude-opus-5","content":[{"type":"text","text":"hi"}]}}' \
'{"type":"assistant","message":{"id":"gen-1-a","model":"deepseek/x","content":[{"type":"text","text":"yo"}]}}' \
> "$proj/$1.jsonl"
python3 -c 'import os, sys, time; t = time.time() - float(sys.argv[2]) * 3600; os.utime(sys.argv[1], (t, t))' \
"$proj/$1.jsonl" "${2:-0}"
}
transcript aaaa-new
transcript bbbb-old 240
transcript dddd-fix 1
printf '%s\n' '{"type":"assistant","message":{"id":"msg_1"}}' > "$proj/cccc-ok.jsonl"
ids() { # <broken|ignored> - the session ids in that list of the scan
"$CM" repair-session --json "${@:2}" | python3 -c '
import json, sys
print(" ".join(x["sessionId"] for x in json.load(sys.stdin)[sys.argv[1]]))' "$1"
}
expect_eq "$(ids broken)" 'aaaa-new dddd-fix' 'broken transcripts are found'
expect_eq "$(ids ignored)" 'bbbb-old' 'one untouched for 10 days is hidden'
expect_eq "$(ids broken --max-age 0)" 'aaaa-new bbbb-old dddd-fix' '--max-age 0 shows all'
run_cm repair-session --ignore aaaa-new
expect_out 'hidden aaaa-new' 'a session is dismissed'
expect_eq "$(ids broken)" 'dddd-fix' 'and leaves the broken list'
run_cm repair-session --all
expect_out '2 hidden: 1 ignored, 1 older than 7 days' 'hidden sessions are always counted'
run_cm repair-session --ignored
expect_out 'still broken' 'the dismissed list reconciles against the disk'
OUT="$(cd "$work" && "$CM" repair-session 2>&1 | sed "s/${ESC}\[[0-9;]*m//g")"
expect_out 'cccc-ok' 'the per-project listing shows every transcript here'
expect_out '(hidden: ignored)' 'and marks a dismissed one'
expect_out '(hidden: older than 7 days)' 'and an age-hidden one'
run_cm repair-session --ignore zzzz
expect_rc 1 'an unknown session cannot be dismissed'
run_cm repair-session --unignore aaaa-new
expect_eq "$(ids broken)" 'aaaa-new dddd-fix' 'restoring brings it back'
run_cm repair-session --ignore dddd-fix
run_cm repair-session dddd-fix --apply
expect_rc 0 'a broken session is repaired'
expect_eq "$(ls "$proj" | grep -c 'dddd-fix.jsonl.pre-repair-backup')" 1 'the original is backed up'
expect_eq "$(ids ignored)" 'bbbb-old' 'a repair clears its dismissal'
run_cm repair-session --ignore bbbb-old
rm -f "$proj/bbbb-old.jsonl"
run_cm repair-session --ignore aaaa-new
expect_out 'forgot 1 whose transcript no longer exists' 'entries for deleted transcripts are pruned'
run_cm repair-session --unignore-all
expect_out 'restored every dismissed session' 'unignore-all empties the list'
finish