Add unreflected-logs: find session logs pending reflection

Scans all projects for session logs not yet processed by /reflect-logs,
using .reflection-state.json to track reflected status.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Paul O'Reilly
2026-03-17 11:14:34 +13:00
parent 77af82c88c
commit 57b4c0a2bb
3 changed files with 362 additions and 0 deletions

109
tests/test-unreflected-logs.sh Executable file
View File

@@ -0,0 +1,109 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
SCRIPT="$SCRIPT_DIR/../scripts/unreflected-logs"
RED='\033[0;31m'
GREEN='\033[0;32m'
RESET='\033[0m'
PASS=0
FAIL=0
assert_exit() {
local desc="$1" expected="$2"
shift 2
local actual
set +e
"$@" >/dev/null 2>&1
actual=$?
set -e
if [[ "$actual" -eq "$expected" ]]; then
echo -e "${GREEN}PASS${RESET}: $desc"
PASS=$((PASS + 1))
else
echo -e "${RED}FAIL${RESET}: $desc (expected exit $expected, got $actual)"
FAIL=$((FAIL + 1))
fi
}
assert_contains() {
local desc="$1" pattern="$2"
shift 2
local output
set +e
output=$("$@" 2>&1)
set -e
if echo "$output" | grep -qF "$pattern"; then
echo -e "${GREEN}PASS${RESET}: $desc"
PASS=$((PASS + 1))
else
echo -e "${RED}FAIL${RESET}: $desc (output missing: '$pattern')"
echo " Got: $output"
FAIL=$((FAIL + 1))
fi
}
# Setup temp directory structure
TMPDIR="$(mktemp -d)"
trap 'rm -rf "$TMPDIR"' EXIT
# Project with all logs reflected
mkdir -p "$TMPDIR/proj-a/memory/log"
echo "# log 1" > "$TMPDIR/proj-a/memory/log/2026-03-12.100000.md"
cat > "$TMPDIR/proj-a/.reflection-state.json" <<'JSON'
{"version": 1, "processed": {"log/2026-03-12.100000.md": "abc123"}}
JSON
# Project with unreflected logs
mkdir -p "$TMPDIR/proj-b/memory/log"
echo "# log 1" > "$TMPDIR/proj-b/memory/log/2026-03-12.100000.md"
echo "# log 2" > "$TMPDIR/proj-b/memory/log/2026-03-13.100000.md"
cat > "$TMPDIR/proj-b/.reflection-state.json" <<'JSON'
{"version": 1, "processed": {"log/2026-03-12.100000.md": "abc123"}}
JSON
# Project with no reflection state file
mkdir -p "$TMPDIR/proj-c/memory/log"
echo "# log 1" > "$TMPDIR/proj-c/memory/log/2026-03-14.100000.md"
# Project with empty log dir
mkdir -p "$TMPDIR/proj-d/memory/log"
# --- Tests ---
echo "=== unreflected-logs tests ==="
echo
# Help flag
assert_exit "--help exits 0" 0 "$SCRIPT" --help
assert_contains "--help shows usage" "Usage:" "$SCRIPT" --help
# Dryrun
assert_contains "--dryrun lists projects" "[dryrun]" "$SCRIPT" --dryrun "$TMPDIR"
assert_exit "--dryrun always exits 0" 0 "$SCRIPT" --dryrun "$TMPDIR"
# Detects unreflected logs
assert_exit "exits 1 when unreflected logs exist" 1 "$SCRIPT" "$TMPDIR"
assert_contains "shows unreflected log filename" "2026-03-13.100000.md" "$SCRIPT" "$TMPDIR"
# Shows project with no state file as unreflected
assert_contains "missing state file = unreflected" "2026-03-14.100000.md" "$SCRIPT" "$TMPDIR"
# Shows reflected project count
assert_contains "shows reflected project count" "1 projects have all logs reflected" "$SCRIPT" "$TMPDIR"
# No projects found
EMPTY="$(mktemp -d)"
assert_contains "no projects message" "No projects with session logs" "$SCRIPT" "$EMPTY"
assert_exit "no projects exits 0" 0 "$SCRIPT" "$EMPTY"
rmdir "$EMPTY"
# All reflected (only proj-a)
assert_exit "all reflected exits 0" 0 "$SCRIPT" "$TMPDIR/proj-a"
echo
echo "---"
echo -e "Results: ${GREEN}$PASS passed${RESET}, ${RED}$FAIL failed${RESET}"
[[ $FAIL -eq 0 ]]