70 lines
5.1 KiB
Bash
Executable file
70 lines
5.1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Template smoke test: run the deterministic scripts against the fixture KB and
|
|
# compare with the golden output. Exit non-zero on any drift.
|
|
#
|
|
# tests/smoke.sh # check
|
|
# tests/smoke.sh --update # regenerate the golden files after an intended change
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
FIX=tests/fixtures/minimal-kb
|
|
TODAY=2026-09-24
|
|
LINT=.agents/skills/ckb-lint/scripts/lint_report.py
|
|
RETR=.agents/skills/ckb-retrieve/scripts/retrieve_candidates.py
|
|
SAVE=.agents/skills/ckb-add-conversation/scripts/save_conversation.py
|
|
TMP=$(mktemp -d); trap 'rm -rf "$TMP"' EXIT
|
|
|
|
QUICK=.agents/skills/ckb-lint/scripts/lint_quick.sh
|
|
( cd "$FIX" && python3 "../../../$LINT" --json --today "$TODAY" ) > "$TMP/lint.json"
|
|
# The no-Python fallback must agree with the reference on the three counts it covers.
|
|
( cd "$FIX" && python3 "../../../$LINT" --quick --today "$TODAY" || true ) > "$TMP/quick.py.txt"
|
|
( cd "$FIX" && bash "../../../$QUICK" --today "$TODAY" || true ) | sed 's/ (fallback:.*//' > "$TMP/quick.sh.txt"
|
|
python3 "$RETR" "how many times does Atlas retry a failed batch" --root "$FIX" --today "$TODAY" --json > "$TMP/retrieve.json"
|
|
# Conversation rendering must be stable: same fixture transcript, same Markdown.
|
|
mkdir -p "$TMP/conv" && python3 "$SAVE" --from tests/fixtures/conversation/session.jsonl --root "$TMP/conv" --today "$TODAY" --author "Fixture User <fixture@example.com>" > /dev/null
|
|
cp "$TMP"/conv/raw/saved-conversations/"$TODAY"/*.md "$TMP/conversation.md"
|
|
# A title set with --set-title must win over the transcript's own title and rename the saved pair.
|
|
mkdir -p "$TMP/titled" && ENC=$(python3 -c "import re,sys;print(re.sub(r'[^A-Za-z0-9]','-',sys.argv[1]))" "$(cd "$TMP/titled" && pwd -P)") \
|
|
&& mkdir -p "$TMP/cfg/projects/$ENC" && cp tests/fixtures/conversation/session.jsonl "$TMP/cfg/projects/$ENC/"
|
|
( cd "$TMP/titled" && CLAUDE_CONFIG_DIR="$TMP/cfg" python3 "$OLDPWD/$SAVE" --today "$TODAY" --author "Fixture User <fixture@example.com>" >/dev/null \
|
|
&& CLAUDE_CONFIG_DIR="$TMP/cfg" python3 "$OLDPWD/$SAVE" --set-title "Smoke Title" >/dev/null \
|
|
&& CLAUDE_CONFIG_DIR="$TMP/cfg" python3 "$OLDPWD/$SAVE" --today "$TODAY" --author "Fixture User <fixture@example.com>" >/dev/null )
|
|
ls "$TMP/titled/raw/saved-conversations/$TODAY" > "$TMP/titled.txt"
|
|
# Routines: due list is deterministic for the fixture; edits touch only the routine's own lines.
|
|
ROUT=.agents/skills/ckb-routine/scripts/routines.py
|
|
( python3 "$ROUT" --due --root "$FIX" --today "$TODAY" || true ) > "$TMP/routines-due.txt"
|
|
cp "$FIX/ckb.yaml" "$TMP/ckb.yaml"
|
|
python3 "$ROUT" --root "$TMP" --mark weekly-lint --today "$TODAY" >/dev/null
|
|
python3 "$ROUT" --root "$TMP" --add --name smoke --do "Lint" --every 2w >/dev/null
|
|
python3 "$ROUT" --root "$TMP" --remove smoke >/dev/null
|
|
|
|
if [[ "${1:-}" == "--update" ]]; then
|
|
cp "$TMP/lint.json" tests/expected/lint.json
|
|
cp "$TMP/retrieve.json" tests/expected/retrieve.json
|
|
cp "$TMP/conversation.md" tests/expected/conversation.md
|
|
cp "$TMP/routines-due.txt" tests/expected/routines-due.txt
|
|
echo "golden files updated"; exit 0
|
|
fi
|
|
|
|
fail=0
|
|
for f in lint retrieve; do
|
|
if ! diff -u "tests/expected/$f.json" "$TMP/$f.json"; then echo "DRIFT: $f"; fail=1; fi
|
|
done
|
|
if ! diff -u tests/expected/conversation.md "$TMP/conversation.md"; then echo "DRIFT: conversation"; fail=1; fi
|
|
[[ "$(cat "$TMP/titled.txt")" == $'smoke-title_0f1e2d3c.jsonl\nsmoke-title_0f1e2d3c.md' ]] || { echo "set-title: unexpected files: $(cat "$TMP/titled.txt")"; fail=1; }
|
|
grep -q '^# Smoke Title$' "$TMP/titled/raw/saved-conversations/$TODAY/smoke-title_0f1e2d3c.md" || { echo "set-title: heading not applied"; fail=1; }
|
|
if ! diff -u tests/expected/routines-due.txt "$TMP/routines-due.txt"; then echo "DRIFT: routines-due"; fail=1; fi
|
|
[[ "$(diff "$FIX/ckb.yaml" "$TMP/ckb.yaml" | grep -c '^[<>]')" == "2" ]] || { echo "routines: --mark/--add/--remove changed more than the last_run line"; diff "$FIX/ckb.yaml" "$TMP/ckb.yaml"; fail=1; }
|
|
grep -q 'last_run: 2026-09-24' "$TMP/ckb.yaml" || { echo "routines: --mark did not stamp today"; fail=1; }
|
|
if ! diff -u "$TMP/quick.py.txt" "$TMP/quick.sh.txt"; then echo "DRIFT: lint_quick.sh disagrees with lint_report.py --quick"; fail=1; fi
|
|
top=$(python3 -c "import json;print(json.load(open('$TMP/retrieve.json'))['candidates'][0]['path'])")
|
|
[[ "$top" == "wiki/entities/atlas-retry-policy.md" ]] || { echo "retrieve: expected atlas-retry-policy first, got $top"; fail=1; }
|
|
# Session start in one call: the fixture has one due routine and a clean wiki.
|
|
START=.agents/skills/ckb-lint/scripts/session_start.py
|
|
python3 "$START" --root "$FIX" --today "$TODAY" --no-git > "$TMP/start.txt" || { echo "session_start.py failed"; fail=1; }
|
|
grep -q '^ckb check: clean' "$TMP/start.txt" || { echo "session_start: no clean check line"; fail=1; }
|
|
grep -q '^routines: DUE weekly-lint' "$TMP/start.txt" || { echo "session_start: due routine missing"; fail=1; }
|
|
grep -q '^announce: yes' "$TMP/start.txt" || { echo "session_start: announce line missing"; fail=1; }
|
|
# mcp module: what a remote client may read and write (no MCP SDK needed).
|
|
python3 tests/mcp_policy.py "$FIX" || fail=1
|
|
[[ $fail -eq 0 ]] && echo "smoke: OK"
|
|
exit $fail
|