# Tests for archeflow-rollback.sh — post-merge test and phase rollback. # # Validates: argument parsing, mutual exclusivity, phase validation, test-cmd config reading. setup() { load test_helper _common_setup } teardown() { _common_teardown } @test "rollback: exits with error when called with no args" { run "$LIB_DIR/archeflow-rollback.sh" [ "$status" -ne 0 ] } @test "rollback: rejects mutually exclusive --to and --test-cmd" { run "$LIB_DIR/archeflow-rollback.sh" test-run --to plan --test-cmd "true" [ "$status" -eq 2 ] [[ "$output" == *"mutually exclusive"* ]] } @test "rollback: rejects invalid phase names" { run "$LIB_DIR/archeflow-rollback.sh" test-run --to invalid-phase [ "$status" -eq 2 ] [[ "$output" == *"Invalid phase"* ]] } @test "rollback: accepts valid phase names (plan, do, check)" { # This will fail because no git branch exists, but should NOT fail on phase validation run "$LIB_DIR/archeflow-rollback.sh" test-run --to plan # Should fail later (archeflow-git.sh rollback) not on phase validation [[ "$output" != *"Invalid phase"* ]] } @test "rollback: exits 2 when no test command available" { run "$LIB_DIR/archeflow-rollback.sh" test-run [ "$status" -eq 2 ] [[ "$output" == *"No test command"* ]] } @test "rollback: reads test_command from config.yaml" { mkdir -p .archeflow echo 'test_command: "echo ok"' > .archeflow/config.yaml # HEAD won't have archeflow in its message, but the script just warns and proceeds run "$LIB_DIR/archeflow-rollback.sh" test-run # It should pick up the command and try to run it (test should pass -> exit 0) [ "$status" -eq 0 ] [[ "$output" == *"Tests passed"* ]] } @test "rollback: rejects unknown options" { run "$LIB_DIR/archeflow-rollback.sh" test-run --unknown-flag [ "$status" -eq 2 ] [[ "$output" == *"Unknown option"* ]] }