test: add bats test suite for lib/ helper scripts

110 tests across 10 test files covering all lib/ scripts:
- archeflow-event.sh: JSONL format, seq numbering, parent fields, validation
- archeflow-memory.sh: add/list/decay/forget/inject/extract commands
- archeflow-git.sh: branch creation, commit format, merge strategies, safety
- archeflow-report.sh: markdown output, summary mode, in-progress handling
- archeflow-progress.sh: progress.md generation, JSON mode, error handling
- archeflow-score.sh: archetype scoring, effectiveness report, validation
- archeflow-dag.sh: DAG rendering, color flags, tree structure
- archeflow-rollback.sh: arg parsing, phase validation, mutual exclusivity
- archeflow-init.sh: template listing, clone from project, arg validation
- archeflow-review.sh: diff modes, stats, branch/commit range review

Includes test_helper.bash (shared setup/teardown with temp git repos)
and scripts/run-tests.sh runner.
This commit is contained in:
2026-04-06 21:20:05 +02:00
parent 6bae80b874
commit 6a49c21bbe
12 changed files with 1195 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
# Tests for archeflow-review.sh — git diff extraction for code review.
#
# Validates: argument parsing, diff modes, stats output, empty diff handling.
setup() {
load test_helper
_common_setup
}
teardown() {
_common_teardown
}
@test "review: --help shows usage" {
run "$LIB_DIR/archeflow-review.sh" --help
[ "$status" -eq 0 ]
[[ "$output" == *"Usage"* ]]
[[ "$output" == *"--branch"* ]]
[[ "$output" == *"--commit"* ]]
}
@test "review: exits 1 when no changes to review" {
run "$LIB_DIR/archeflow-review.sh"
[ "$status" -eq 1 ]
[[ "$output" == *"No changes"* ]]
}
@test "review: shows diff for uncommitted changes" {
echo "new content" > testfile.txt
git add testfile.txt
run "$LIB_DIR/archeflow-review.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"testfile.txt"* ]]
}
@test "review: --stat-only prints stats without diff content" {
echo "stat content" > statfile.txt
git add statfile.txt
run "$LIB_DIR/archeflow-review.sh" --stat-only
[ "$status" -eq 0 ]
# stderr has stats, stdout should be empty (no diff)
# But run captures both, so just check it ran ok
[[ "$output" == *"Review Stats"* ]]
}
@test "review: --branch fails for nonexistent branch" {
run "$LIB_DIR/archeflow-review.sh" --branch nonexistent-branch-xyz
[ "$status" -ne 0 ]
[[ "$output" == *"not found"* ]]
}
@test "review: rejects unknown arguments" {
run "$LIB_DIR/archeflow-review.sh" --unknown
[ "$status" -ne 0 ]
[[ "$output" == *"Unknown argument"* ]]
}
@test "review: --branch shows diff against base" {
# Create a feature branch with changes
git checkout -b feat/test-review --quiet
echo "feature" > feature.txt
git add feature.txt
git commit -m "feat: add feature" --quiet
git checkout main --quiet
run "$LIB_DIR/archeflow-review.sh" --branch feat/test-review
[ "$status" -eq 0 ]
[[ "$output" == *"feature.txt"* ]]
}
@test "review: --commit shows diff for commit range" {
echo "first" > first.txt
git add first.txt
git commit -m "first" --quiet
echo "second" > second.txt
git add second.txt
git commit -m "second" --quiet
run "$LIB_DIR/archeflow-review.sh" --commit HEAD~1..HEAD
[ "$status" -eq 0 ]
[[ "$output" == *"second.txt"* ]]
}