Просмотр исходного кода

merge: robustness lane rd-pigeon-leveldb (Phase 3)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
0xDarkMatter 1 неделя назад
Родитель
Сommit
ab85bd3b5c
2 измененных файлов с 101 добавлено и 0 удалено
  1. 48 0
      skills/leveldb-ops/tests/run.sh
  2. 53 0
      skills/pigeon/tests/run.sh

+ 48 - 0
skills/leveldb-ops/tests/run.sh

@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+# Offline contract tests. The shipped readers intentionally have no profile
+# copy helper: callers must copy and remove LOCK before invoking them, so no
+# production lock-safety path exists to exercise without fabricating coverage.
+
+set -uo pipefail
+
+HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+SKILL="$(dirname "$HERE")"
+SCRIPTS="$SKILL/scripts"
+SB="$(mktemp -d)"
+trap 'rm -rf "$SB"' EXIT
+
+PYTHON=""
+for c in python python3 py; do
+  if command -v "$c" >/dev/null 2>&1 && "$c" -c "" >/dev/null 2>&1; then PYTHON="$c"; break; fi
+done
+[[ -n "$PYTHON" ]] || { echo "python is required" >&2; exit 1; }
+
+PASS=0; FAIL=0
+ok() { PASS=$((PASS+1)); printf '  PASS  %s\n' "$1"; }
+no() { FAIL=$((FAIL+1)); printf '  FAIL  %s\n' "$1"; }
+
+# Minimal import surface: --help exits during argparse before reader use.
+mkdir -p "$SB/stub/ccl_chromium_reader"
+printf '' > "$SB/stub/ccl_chromium_reader/__init__.py"
+printf '' > "$SB/stub/ccl_chromium_reader/ccl_chromium_indexeddb.py"
+printf '' > "$SB/stub/ccl_chromium_reader/ccl_chromium_localstorage.py"
+
+echo "=== leveldb-ops contract self-test ==="
+for script in dump_indexeddb.py dump_localstorage.py extract_keys.py; do
+  PYTHONPYCACHEPREFIX="$SB/pycache" "$PYTHON" -m py_compile "$SCRIPTS/$script" \
+    && ok "py_compile $script" || no "py_compile $script"
+
+  # Imports are stubbed so argparse help remains offline and does not require
+  # the optional forensic reader package.
+  out="$(PYTHONPATH="$SB/stub" "$PYTHON" "$SCRIPTS/$script" --help 2>&1)"; rc=$?
+  if [[ "$rc" -eq 0 && "$out" == *"usage:"* ]]; then
+    ok "--help usage contract $script"
+  else
+    no "--help usage contract $script"
+  fi
+done
+
+echo ""
+echo "NOTE: lock safety is contract-only; scripts accept pre-copied stores and expose no copy helper."
+echo "=== $PASS passed, $FAIL failed ==="
+[[ "$FAIL" -eq 0 ]]

+ 53 - 0
skills/pigeon/tests/run.sh

@@ -0,0 +1,53 @@
+#!/usr/bin/env bash
+# Behavioural tests for pigeon. HOME is isolated before any production script
+# runs so ~/.claude/pmail.db always resolves inside the disposable sandbox.
+
+set -uo pipefail
+
+HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+SKILL="$(dirname "$HERE")"
+MAIL="$SKILL/scripts/mail-db.sh"
+SB="$(mktemp -d)"
+trap 'rm -rf "$SB"' EXIT
+export HOME="$SB/home"
+mkdir -p "$HOME"
+DB="$HOME/.claude/pmail.db"
+
+PASS=0; FAIL=0
+ok() { PASS=$((PASS+1)); printf '  PASS  %s\n' "$1"; }
+no() { FAIL=$((FAIL+1)); printf '  FAIL  %s\n' "$1"; }
+expect_eq() { [[ "$2" == "$3" ]] && ok "$1" || no "$1 (want '$2', got '$3')"; }
+
+echo "=== pigeon behavioural self-test ==="
+
+command -v sqlite3 >/dev/null 2>&1 || { echo "sqlite3 is required" >&2; exit 1; }
+bash -n "$MAIL" && ok "bash -n mail-db.sh" || no "bash -n mail-db.sh"
+# NOTE: scripts/test-mail.sh (the legacy harness) is deliberately NOT invoked
+# here — it blocks indefinitely (rc=124) and would hang CI. The focused
+# corruption guards below are the authoritative signal; see the spawned
+# follow-up task for the test-mail.sh hang itself.
+
+echo "-- migration idempotency and schema --"
+rm -f "$DB"
+bash "$MAIL" migrate >/dev/null
+schema_first="$(sqlite3 "$DB" ".schema")"
+bash "$MAIL" migrate >/dev/null
+schema_second="$(sqlite3 "$DB" ".schema")"
+expect_eq "second migration leaves schema identical" "$schema_first" "$schema_second"
+
+tables="$(sqlite3 "$DB" "SELECT name FROM sqlite_master WHERE type='table' AND name IN ('messages','projects') ORDER BY name;" | tr -d '\r')"
+expect_eq "expected tables exist" $'messages\nprojects' "$tables"
+
+columns="$(sqlite3 "$DB" "SELECT name FROM pragma_table_info('messages') WHERE name IN ('priority','thread_id','attachments') ORDER BY name;" | tr -d '\r')"
+expect_eq "migration columns exist once" $'attachments\npriority\nthread_id' "$columns"
+
+echo "-- round trip --"
+bash "$MAIL" send "$(pwd)" "round trip" "isolated body" >/dev/null
+expect_eq "unread count after send" "1" "$(bash "$MAIL" count)"
+read_out="$(bash "$MAIL" read)"
+case "$read_out" in *"round trip"*"isolated body"*) ok "read returns sent message";; *) no "read omitted sent message";; esac
+expect_eq "read marks message read" "0" "$(bash "$MAIL" count)"
+
+echo ""
+echo "=== $PASS passed, $FAIL failed ==="
+[[ "$FAIL" -eq 0 ]]