56 lines
1.6 KiB
Bash
56 lines
1.6 KiB
Bash
|
|
#!/bin/sh
|
||
|
|
# Verifies the learn -> persist -> auto-apply cycle for f().
|
||
|
|
# Run from the repo root: sh test/test_f.sh
|
||
|
|
set -e
|
||
|
|
|
||
|
|
WORKDIR=$(mktemp -d)
|
||
|
|
trap 'rm -rf "$WORKDIR"' EXIT
|
||
|
|
cp src/f.sh "$WORKDIR/f.sh"
|
||
|
|
cd "$WORKDIR"
|
||
|
|
|
||
|
|
fail=0
|
||
|
|
|
||
|
|
# 1. First call: command fails, we supply a fix, command succeeds after retry.
|
||
|
|
printf 'echo hello > needs-fix.txt\n' > fixinput.txt
|
||
|
|
out=$(. ./f.sh; f cat needs-fix.txt < fixinput.txt)
|
||
|
|
if [ "$out" != "hello" ]; then
|
||
|
|
echo "FAIL: expected 'hello' from first (learning) call, got: $out"
|
||
|
|
fail=1
|
||
|
|
else
|
||
|
|
echo "PASS: first call learns the fix and succeeds"
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [ ! -f p ]; then
|
||
|
|
echo "FAIL: expected p to be created with the learned fix"
|
||
|
|
fail=1
|
||
|
|
else
|
||
|
|
echo "PASS: fix persisted to p"
|
||
|
|
fi
|
||
|
|
|
||
|
|
grep -qF 'cat needs-fix.txt=echo hello > needs-fix.txt' p || {
|
||
|
|
echo "FAIL: p does not contain the expected key=fix line"
|
||
|
|
fail=1
|
||
|
|
}
|
||
|
|
|
||
|
|
# 2. Second call, fresh subshell (simulates a new terminal): fix auto-applies,
|
||
|
|
# no prompt needed even though needs-fix.txt was removed again.
|
||
|
|
rm -f needs-fix.txt
|
||
|
|
out2=$(. ./f.sh && f cat needs-fix.txt < /dev/null)
|
||
|
|
if [ "$out2" != "hello" ]; then
|
||
|
|
echo "FAIL: expected learned fix to auto-apply on second call, got: $out2"
|
||
|
|
fail=1
|
||
|
|
else
|
||
|
|
echo "PASS: learned fix auto-applies on a fresh call with no prompt"
|
||
|
|
fi
|
||
|
|
|
||
|
|
# 3. A command that already succeeds should run once, untouched, no prompt.
|
||
|
|
out3=$(. ./f.sh && f echo already-fine < /dev/null)
|
||
|
|
if [ "$out3" != "already-fine" ]; then
|
||
|
|
echo "FAIL: expected passthrough for already-succeeding command"
|
||
|
|
fail=1
|
||
|
|
else
|
||
|
|
echo "PASS: already-succeeding commands pass through untouched"
|
||
|
|
fi
|
||
|
|
|
||
|
|
exit $fail
|