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

81
tests/archeflow-init.bats Normal file
View File

@@ -0,0 +1,81 @@
# Tests for archeflow-init.sh — project initialization from templates.
#
# Validates: usage output, --list, --from (clone), and argument parsing.
setup() {
load test_helper
_common_setup
}
teardown() {
_common_teardown
}
@test "init: shows usage when called with no args" {
run "$LIB_DIR/archeflow-init.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"Usage"* ]]
[[ "$output" == *"bundle-name"* ]]
}
@test "init: --list shows template listing without errors" {
run "$LIB_DIR/archeflow-init.sh" --list
[ "$status" -eq 0 ]
[[ "$output" == *"Templates"* ]]
[[ "$output" == *"Bundles"* ]]
}
@test "init: --from fails when source has no .archeflow dir" {
local source_dir
source_dir=$(mktemp -d)
run "$LIB_DIR/archeflow-init.sh" --from "$source_dir"
[ "$status" -ne 0 ]
[[ "$output" == *"No .archeflow/"* ]]
rm -rf "$source_dir"
}
@test "init: --from clones setup from another project" {
# Create a source project with .archeflow structure
local source_dir
source_dir=$(mktemp -d)
mkdir -p "$source_dir/.archeflow/teams" "$source_dir/.archeflow/workflows"
echo "name: test-team" > "$source_dir/.archeflow/teams/test.yaml"
echo "name: test-workflow" > "$source_dir/.archeflow/workflows/test.yaml"
echo "bundle: test" > "$source_dir/.archeflow/config.yaml"
run "$LIB_DIR/archeflow-init.sh" --from "$source_dir"
[ "$status" -eq 0 ]
[ -f ".archeflow/teams/test.yaml" ]
[ -f ".archeflow/workflows/test.yaml" ]
[ -f ".archeflow/config.yaml" ]
rm -rf "$source_dir"
}
@test "init: --from skips events and artifacts directories" {
local source_dir
source_dir=$(mktemp -d)
mkdir -p "$source_dir/.archeflow/events" "$source_dir/.archeflow/artifacts"
mkdir -p "$source_dir/.archeflow/teams"
echo "name: test" > "$source_dir/.archeflow/teams/t.yaml"
echo '{"test":true}' > "$source_dir/.archeflow/events/run.jsonl"
echo "artifact" > "$source_dir/.archeflow/artifacts/test.txt"
run "$LIB_DIR/archeflow-init.sh" --from "$source_dir"
[ "$status" -eq 0 ]
[ ! -f ".archeflow/events/run.jsonl" ]
[ ! -f ".archeflow/artifacts/test.txt" ]
[[ "$output" == *"skipped events"* ]]
rm -rf "$source_dir"
}
@test "init: rejects unknown options" {
run "$LIB_DIR/archeflow-init.sh" --nonexistent
[ "$status" -ne 0 ]
[[ "$output" == *"Unknown option"* ]]
}
@test "init: --save fails with no .archeflow directory" {
run "$LIB_DIR/archeflow-init.sh" --save test-save
[ "$status" -ne 0 ]
[[ "$output" == *"No .archeflow/"* ]]
}