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

40
tests/test_helper.bash Normal file
View File

@@ -0,0 +1,40 @@
# test_helper.bash — Shared setup/teardown for ArcheFlow bats tests.
#
# Usage in .bats files:
# setup() { load test_helper; _common_setup; }
# teardown() { _common_teardown; }
#
# Provides:
# - BATS_TEST_TMPDIR: unique temp directory per test
# - Mock .archeflow/ structure via a git repo
# - LIB_DIR: path to the lib/ scripts under test
LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../lib" && pwd)"
_common_setup() {
# Create a unique temp directory for this test
BATS_TEST_TMPDIR="$(mktemp -d)"
export BATS_TEST_TMPDIR
# Work inside the temp dir so scripts create .archeflow/ there
cd "$BATS_TEST_TMPDIR"
# Initialize a minimal git repo (many scripts need it)
git init --quiet
git config user.email "test@test.com"
git config user.name "Test User"
# Disable commit signing in tests (global config may have it enabled)
git config commit.gpgsign false
git config tag.gpgsign false
# Create an initial commit so HEAD exists
echo "init" > README.md
git add README.md
git commit -m "init" --quiet
}
_common_teardown() {
# Return to a safe directory before cleanup
cd /tmp
rm -rf "$BATS_TEST_TMPDIR"
}