|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 5 | +CSEP_BIN="${CSEP_BIN:-csep}" |
| 6 | +PYTHON="${PYTHON:-python3.11}" |
| 7 | +STATE_DIR="${CSEP_SMOKE_STATE_DIR:-}" |
| 8 | +CLEANUP_STATE=0 |
| 9 | + |
| 10 | +if [ -z "$STATE_DIR" ]; then |
| 11 | + STATE_DIR="$(mktemp -d /tmp/csep-runtime-smoke.XXXXXX)" |
| 12 | + CLEANUP_STATE=1 |
| 13 | +fi |
| 14 | + |
| 15 | +cleanup() { |
| 16 | + if [ "$CLEANUP_STATE" = "1" ]; then |
| 17 | + rm -rf "$STATE_DIR" |
| 18 | + fi |
| 19 | +} |
| 20 | +trap cleanup EXIT |
| 21 | + |
| 22 | +log() { |
| 23 | + printf '==> %s\n' "$*" |
| 24 | +} |
| 25 | + |
| 26 | +require_command() { |
| 27 | + if ! command -v "$1" >/dev/null 2>&1; then |
| 28 | + printf 'missing required command: %s\n' "$1" >&2 |
| 29 | + exit 127 |
| 30 | + fi |
| 31 | +} |
| 32 | + |
| 33 | +assert_json() { |
| 34 | + "$PYTHON" - "$@" <<'PY' |
| 35 | +import json |
| 36 | +import sys |
| 37 | +from pathlib import Path |
| 38 | +
|
| 39 | +path = Path(sys.argv[1]) |
| 40 | +kind = sys.argv[2] |
| 41 | +data = json.loads(path.read_text(encoding="utf-8")) |
| 42 | +
|
| 43 | +if kind == "session-start": |
| 44 | + output = data.get("hookSpecificOutput") or {} |
| 45 | + if output.get("hookEventName") != "SessionStart": |
| 46 | + raise SystemExit(f"invalid SessionStart output: {data}") |
| 47 | + if not isinstance(output.get("additionalContext"), str): |
| 48 | + raise SystemExit("SessionStart missing additionalContext") |
| 49 | +elif kind == "archive": |
| 50 | + if data.get("status") != "archived": |
| 51 | + raise SystemExit(f"archive did not complete: {data}") |
| 52 | +elif kind == "recall": |
| 53 | + if data.get("status") != "matched" or int(data.get("count") or 0) < 1: |
| 54 | + raise SystemExit(f"recall did not match: {data}") |
| 55 | +elif kind == "claude-sync": |
| 56 | + if data.get("status") != "completed" or data.get("source") != "claude_code": |
| 57 | + raise SystemExit(f"Claude sync did not complete: {data}") |
| 58 | + if int(data.get("processed_successfully") or 0) < 1: |
| 59 | + raise SystemExit(f"Claude sync archived no sessions: {data}") |
| 60 | +elif kind == "status": |
| 61 | + tool = (data.get("tools") or {}).get("csep") or {} |
| 62 | + missing = [ |
| 63 | + key for key in ("installed_version", "runtime_version", "source_version", "pypi_latest_version") |
| 64 | + if not tool.get(key) |
| 65 | + ] |
| 66 | + if missing: |
| 67 | + raise SystemExit(f"status missing CSEP version fields {missing}: {tool}") |
| 68 | +else: |
| 69 | + raise SystemExit(f"unknown assertion kind: {kind}") |
| 70 | +PY |
| 71 | +} |
| 72 | + |
| 73 | +require_command "$CSEP_BIN" |
| 74 | +require_command "$PYTHON" |
| 75 | +mkdir -p "$STATE_DIR" |
| 76 | + |
| 77 | +log "using state dir: $STATE_DIR" |
| 78 | +log "checking versions" |
| 79 | +"$CSEP_BIN" --version |
| 80 | + |
| 81 | +if [ "${CSEP_SMOKE_SKIP_CONFIG:-0}" != "1" ]; then |
| 82 | + log "validating config" |
| 83 | + "$CSEP_BIN" config validate >/dev/null |
| 84 | +fi |
| 85 | + |
| 86 | +log "checking status version matrix" |
| 87 | +"$CSEP_BIN" status > "$STATE_DIR/status.json" |
| 88 | +assert_json "$STATE_DIR/status.json" status |
| 89 | + |
| 90 | +log "checking SessionStart hook output" |
| 91 | +printf '{"cwd":"%s","session_id":"runtime-smoke-start"}\n' "$ROOT" \ |
| 92 | + | "$CSEP_BIN" session-start --from-stdin --state-dir "$STATE_DIR" \ |
| 93 | + > "$STATE_DIR/session-start.json" |
| 94 | +assert_json "$STATE_DIR/session-start.json" session-start |
| 95 | + |
| 96 | +log "creating smoke transcripts" |
| 97 | +"$PYTHON" - "$STATE_DIR" "$ROOT" <<'PY' |
| 98 | +import json |
| 99 | +import sys |
| 100 | +from pathlib import Path |
| 101 | +
|
| 102 | +state = Path(sys.argv[1]) |
| 103 | +root = Path(sys.argv[2]) |
| 104 | +
|
| 105 | +codex_transcript = state / "codex-smoke.jsonl" |
| 106 | +codex_transcript.write_text( |
| 107 | + "\n".join([ |
| 108 | + json.dumps({"type": "session_meta", "payload": {"id": "runtime-smoke-codex", "cwd": str(root)}}), |
| 109 | + json.dumps({"role": "user", "content": "csep runtime smoke archive needle"}), |
| 110 | + ]) + "\n", |
| 111 | + encoding="utf-8", |
| 112 | +) |
| 113 | +(state / "codex-payload.json").write_text( |
| 114 | + json.dumps({ |
| 115 | + "session_id": "runtime-smoke-codex", |
| 116 | + "cwd": str(root), |
| 117 | + "transcript_path": str(codex_transcript), |
| 118 | + }), |
| 119 | + encoding="utf-8", |
| 120 | +) |
| 121 | +
|
| 122 | +claude_project = state / "claude" / "projects" / "-runtime-smoke" |
| 123 | +claude_project.mkdir(parents=True, exist_ok=True) |
| 124 | +(claude_project / "claude-smoke.jsonl").write_text( |
| 125 | + json.dumps({ |
| 126 | + "type": "user", |
| 127 | + "sessionId": "runtime-smoke-claude", |
| 128 | + "uuid": "runtime-smoke-claude-u1", |
| 129 | + "cwd": str(root), |
| 130 | + "timestamp": "2026-05-17T00:00:00.000Z", |
| 131 | + "message": {"role": "user", "content": "csep runtime smoke claude needle"}, |
| 132 | + }) + "\n", |
| 133 | + encoding="utf-8", |
| 134 | +) |
| 135 | +PY |
| 136 | + |
| 137 | +log "checking archive + recall" |
| 138 | +"$CSEP_BIN" session-archive --from-hook-payload "$STATE_DIR/codex-payload.json" --state-dir "$STATE_DIR" \ |
| 139 | + > "$STATE_DIR/archive.json" |
| 140 | +assert_json "$STATE_DIR/archive.json" archive |
| 141 | +"$CSEP_BIN" recall "runtime smoke archive needle" --cwd "$ROOT" --state-dir "$STATE_DIR" --format json \ |
| 142 | + > "$STATE_DIR/recall-codex.json" |
| 143 | +assert_json "$STATE_DIR/recall-codex.json" recall |
| 144 | + |
| 145 | +log "checking Claude Code sync + recall" |
| 146 | +"$CSEP_BIN" recall sync-claude --root "$STATE_DIR/claude/projects" --state-dir "$STATE_DIR" --limit-files 1 --format json \ |
| 147 | + > "$STATE_DIR/sync-claude.json" |
| 148 | +assert_json "$STATE_DIR/sync-claude.json" claude-sync |
| 149 | +"$CSEP_BIN" recall "runtime smoke claude needle" --cwd "$ROOT" --state-dir "$STATE_DIR" --format json \ |
| 150 | + > "$STATE_DIR/recall-claude.json" |
| 151 | +assert_json "$STATE_DIR/recall-claude.json" recall |
| 152 | + |
| 153 | +log "runtime smoke passed" |
0 commit comments