-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_tests.sh
More file actions
executable file
·142 lines (123 loc) · 6.36 KB
/
Copy pathrun_tests.sh
File metadata and controls
executable file
·142 lines (123 loc) · 6.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env bash
# Test runner for loop.
# 1. loop-test.lisp — hermetic golden (no LLM, no disk, no clock).
# 2. integrity check — runs the REAL persistence path under a THROWAWAY $HOME
# and proves a session only ADDS loop.* keys, never altering pre-existing
# memory. The real ~/.rusty/memory.lisp is never touched.
set -u
RUSTY="${RUSTY:-rusty}"
if ! command -v "$RUSTY" >/dev/null 2>&1; then
echo "error: '$RUSTY' not found on PATH." >&2
echo "Install it: git clone https://github.com/TheLakeMan/rusty && cd rusty && cargo install --path . --bin rusty --root ~/.local" >&2
exit 1
fi
cd "$(dirname "$0")"
fail=0
run_test() {
local test_file="$1" expected="$2" label="$3"
if "$RUSTY" "$test_file" 2>&1 | diff - "$expected" >/dev/null 2>&1; then
echo "✅ $test_file ($label)"
else
echo "❌ $test_file ($label)"
"$RUSTY" "$test_file" 2>&1 | diff - "$expected" | head -20
fail=1
fi
}
run_test loop-test.lisp expected_loop.txt "memory vessel — deterministic, no LLM"
# ── Integrity check: a real session must not alter pre-existing memory ─────────
# Seeds a throwaway $HOME/.rusty/memory.lisp with identity lines that are NOT
# loop's, drives a genuine 3-turn session on disk, and asserts the seeded block
# is byte-identical afterward and every added line is loop.*-namespaced.
integrity_check() {
local label="integrity — real session only adds loop.* keys (throwaway HOME)"
local th; th="$(mktemp -d "${TMPDIR:-/tmp}/loop-integrity-XXXXXX")"
case "$th" in /tmp/*|"${TMPDIR%/}"/*) ;; *) echo "❌ $label (unsafe tmp: $th)"; fail=1; return;; esac
mkdir -p "$th/.rusty"
local mem="$th/.rusty/memory.lisp"
cat > "$mem" <<'SEED'
(define my-name "Nick")
(define brother "In memory of my brother.")
(define favorite-number "7")
SEED
local seed_lines; seed_lines="$(wc -l < "$mem")"
local before; before="$(cat "$mem")"
local out; out="$(HOME="$th" "$RUSTY" loop-integrity-drive.lisp 2>&1)"
local ok=1
# (a) the session actually ran the real path
printf '%s\n' "$out" | grep -q "DRIVE-OK" || { echo " drive did not complete"; ok=0; }
# (b) the seeded identity block is byte-identical and still at the top
[ "$(head -n "$seed_lines" "$mem")" = "$before" ] || { echo " pre-existing memory was altered"; ok=0; }
# (c) every line loop added is loop.*-namespaced (nothing else was written)
local added; added="$(tail -n +"$((seed_lines + 1))" "$mem" | grep -c -vE '^\(define loop\.' || true)"
[ "$added" -eq 0 ] || { echo " $added non-loop line(s) written to memory"; ok=0; }
# (d) transcripts landed under the session's own responses dir
[ "$(ls "$th/.loop/responses/" 2>/dev/null | wc -l)" -eq 3 ] || { echo " expected 3 response files"; ok=0; }
rm -rf "$th"
if [ "$ok" -eq 1 ]; then echo "✅ $label"; else echo "❌ $label"; fail=1; fi
}
integrity_check
# ── Hash check: the integrity report is honest, and it BITES ───────────────────
# Drives a real session on disk, then asks (loop-integrity id) three things:
# an untouched session reports "intact"; an EDITED transcript reports "changed";
# a DELETED one reports "changed" too. The last two are the point — a check that
# always said "intact" would satisfy the first assertion forever.
hash_check() {
local label="integrity hashes — intact when untouched, changed when tampered"
local th; th="$(mktemp -d "${TMPDIR:-/tmp}/loop-hash-XXXXXX")"
case "$th" in /tmp/*|"${TMPDIR%/}"/*) ;; *) echo "❌ $label (unsafe tmp: $th)"; fail=1; return;; esac
mkdir -p "$th/.rusty"
HOME="$th" "$RUSTY" loop-integrity-drive.lisp >/dev/null 2>&1
verdict() { HOME="$th" "$RUSTY" loop-integrity-verify.lisp 2>&1 \
| grep '^VERDICT ' | head -1 | cut -d' ' -f2; }
local ok=1 v
# (a) an untouched session vouches for every response it wrote
v="$(verdict)"
[ "$v" = "intact" ] || { echo " untouched session reported '$v', expected intact"; ok=0; }
# (b) edit one stored transcript — one byte is enough
local victim; victim="$(ls "$th"/.loop/responses/*.txt 2>/dev/null | head -1)"
if [ -z "$victim" ]; then
echo " no transcript to tamper with"; ok=0
else
printf 'x' >> "$victim"
v="$(verdict)"
[ "$v" = "changed" ] || { echo " edited transcript reported '$v', expected changed"; ok=0; }
# (c) delete it outright — a vanished transcript is a change, not a silence
rm -f "$victim"
v="$(verdict)"
[ "$v" = "changed" ] || { echo " deleted transcript reported '$v', expected changed"; ok=0; }
fi
rm -rf "$th"
if [ "$ok" -eq 1 ]; then echo "✅ $label"; else echo "❌ $label"; fail=1; fi
}
hash_check
# ── Package check: loop is a valid, cwd-independent Rusty package ──────────────
# Copies loop into a throwaway $HOME/.rusty/packages/loop (where pkg would put
# it), then runs the probe from an UNRELATED cwd. Proves the manifest is
# well-formed and that loading the package entry (loop-pkg.lisp) brings the whole
# engine up despite Rusty's cwd-relative `load` — the reason the package needs an
# absolute-path entry rather than reusing loop.lisp. No pkg.lisp, LLM, or network.
pkg_entry_check() {
local label="package — manifest valid + entry loads from a foreign cwd"
local repo; repo="$(pwd)"
local th; th="$(mktemp -d "${TMPDIR:-/tmp}/loop-pkg-XXXXXX")"
case "$th" in /tmp/*|"${TMPDIR%/}"/*) ;; *) echo "❌ $label (unsafe tmp: $th)"; fail=1; return;; esac
local dest="$th/.rusty/packages/loop"
mkdir -p "$dest"
cp package.lisp loop-pkg.lisp loop-core.lisp loop-questions.lisp loop-soul.lisp "$dest/"
# Run from $th (a foreign cwd): loop-core.lisp is NOT resolvable by bare name
# here, so bare relative loads would fail — only absolute-path loading works.
local out; out="$(cd "$th" && HOME="$th" "$RUSTY" "$repo/loop-pkg-probe.lisp" 2>&1)"
local ok=1
printf '%s\n' "$out" | grep -q '^MANIFEST-OK$' || { echo " manifest not well-formed"; ok=0; }
printf '%s\n' "$out" | grep -q '^PKG-ENTRY-OK$' || { echo " package entry did not load the engine"; ok=0; }
printf '%s\n' "$out" | grep -q '^SELFCHECK-GUARDED-OK$' || { echo " loop-self-check did not degrade without pkg.lisp"; ok=0; }
rm -rf "$th"
if [ "$ok" -eq 1 ]; then echo "✅ $label"; else echo "❌ $label"; fail=1; fi
}
pkg_entry_check
if [ "$fail" -eq 0 ]; then
echo "🎉 ALL PASSED"
else
echo "SOME TESTS FAILED"
fi
exit "$fail"