feat: add archeflow-rollback.sh for post-merge test failure auto-revert

This commit is contained in:
2026-04-04 07:34:43 +02:00
parent 34f101c166
commit 7f99d52a09
3 changed files with 99 additions and 23 deletions

View File

@@ -219,6 +219,32 @@ The helper script reads this config if it exists. All values have sensible defau
---
## Post-Merge Rollback
After merging, the run skill validates the merge by running the project's test suite. If tests fail, the merge is automatically reverted.
### Script
```bash
./lib/archeflow-rollback.sh <run_id> [--test-cmd <cmd>]
```
**Behavior:**
1. Reads `test_command` from `.archeflow/config.yaml` (or uses `--test-cmd` override)
2. Runs the test suite with a 5-minute timeout
3. If tests pass: exits 0 (merge is good)
4. If tests fail: runs `git revert --no-edit HEAD`, emits a `decision` event, exits 1
5. Verifies HEAD is an ArcheFlow merge commit before reverting (warning if not, proceeds anyway)
**Integration with run skill:** Called in section 4c (All Approved) after `archeflow-git.sh merge`. If it returns non-zero, the orchestrator cycles back with "integration test failure" feedback or reports to the user if max cycles are reached.
**Configuration:** Set `test_command` in `.archeflow/config.yaml`:
```yaml
test_command: "npm test" # or "pytest", "cargo test", etc.
```
---
## Safety Rules
These rules are inherited from `archeflow:orchestration` and reinforced here:

View File

@@ -380,30 +380,19 @@ If all reviewers approved (and completion criteria met, if defined):
./lib/archeflow-git.sh merge "$RUN_ID" --no-ff
```
4. **Post-merge test validation:**
4. **Post-merge test validation** (using the auto-rollback script):
```bash
# Read test_command from config
TEST_CMD=$(grep -E "^test_command:" .archeflow/config.yaml | sed 's/^test_command:\s*//' | tr -d '"' || true)
if [[ -n "$TEST_CMD" ]]; then
echo "Running post-merge tests: $TEST_CMD"
if ! bash -c "$TEST_CMD"; then
echo "Post-merge tests FAILED — reverting merge..."
git revert --no-edit HEAD
# Emit decision event for the revert
./lib/archeflow-event.sh "$RUN_ID" decision act "" \
'{"what":"post_merge_test","chosen":"revert","rationale":"test suite failed after merge"}' "$SEQ_CHECK_TO_ACT"
# If cycles remain, cycle back with integration test failure feedback
if [[ "$CYCLE" -lt "$MAX_CYCLES" ]]; then
echo "Cycling back with integration test failure feedback..."
# Build act-feedback.md with "integration test failure on main" as top finding
# Continue to step 4d (Issues Found)
else
echo "Max cycles reached. Reporting failure to user."
# Continue to step 4e (Max Cycles Reached)
fi
# Run tests and auto-revert if they fail
if ! ./lib/archeflow-rollback.sh "$RUN_ID"; then
# Rollback script already reverted HEAD and emitted decision event
# If cycles remain, cycle back with integration test failure feedback
if [[ "$CYCLE" -lt "$MAX_CYCLES" ]]; then
echo "Cycling back with integration test failure feedback..."
# Build act-feedback.md with "integration test failure on main" as top finding
# Continue to step 4d (Issues Found)
else
echo "Max cycles reached. Reporting failure to user."
# Continue to step 4e (Max Cycles Reached)
fi
fi
```