|
| 1 | +--- |
| 2 | +name: deploy-and-test |
| 3 | +description: >- |
| 4 | + Full lifecycle validation agent. Starts VMs, deploys Foreman, runs tests, |
| 5 | + and attempts to fix code failures up to 2 times before reporting back. |
| 6 | +references: |
| 7 | + - docs/developer/testing.md |
| 8 | + - development/playbooks/test/test.yaml |
| 9 | + - development/playbooks/vms/vms.yaml |
| 10 | +--- |
| 11 | + |
| 12 | +# Agent - Deploy and Test |
| 13 | + |
| 14 | +Autonomous validation agent that runs the full foremanctl lifecycle: environment setup, deployment, testing, and up to 2 fix-and-retry cycles on failure. |
| 15 | + |
| 16 | +## When to Use |
| 17 | + |
| 18 | +Spawn this agent after implementing code changes that affect deployment or services. It validates the changes end-to-end in an isolated environment. |
| 19 | + |
| 20 | +## Workflow |
| 21 | + |
| 22 | +### Phase 1: Environment Setup |
| 23 | + |
| 24 | +Start the development VMs and deploy Foreman. |
| 25 | + |
| 26 | +```bash |
| 27 | +./forge vms start |
| 28 | +``` |
| 29 | + |
| 30 | +Wait for VMs to be ready, then deploy: |
| 31 | + |
| 32 | +```bash |
| 33 | +./foremanctl deploy --foreman-initial-admin-password=changeme --tuning development |
| 34 | +``` |
| 35 | + |
| 36 | +If deployment fails, go to Phase 3 (fix loop) — a deploy failure counts as the first attempt. |
| 37 | + |
| 38 | +### Phase 2: Test Execution |
| 39 | + |
| 40 | +Run the full test suite: |
| 41 | + |
| 42 | +```bash |
| 43 | +./forge test |
| 44 | +``` |
| 45 | + |
| 46 | +Parse the pytest output. If all tests pass, go to Phase 4 (report). If tests fail, go to Phase 3. |
| 47 | + |
| 48 | +### Phase 3: Fix Loop |
| 49 | + |
| 50 | +Attempt to fix failures, up to 2 total attempts. Each attempt: |
| 51 | + |
| 52 | +1. **Analyze** — read the failure output. Identify which tests failed and the root cause (assertion error, service not running, missing file, configuration issue, etc.). |
| 53 | +2. **Classify** — determine if the failure is a code issue or an infrastructure issue. |
| 54 | + - **Infrastructure issue** (VM connectivity, Vagrant error, network timeout, disk space): stop and report. Do not attempt to fix. |
| 55 | + - **Code issue** (wrong config, missing task, template error, incorrect variable): proceed to fix. |
| 56 | +3. **Diagnose** — read the relevant source files (roles, templates, vars, playbooks) to understand what went wrong. |
| 57 | +4. **Fix** — apply a targeted change to the source code. Only modify files directly related to the failure. |
| 58 | +5. **Re-deploy** — if the fix changed any deployment code (roles, playbooks, vars, templates), re-run deployment: |
| 59 | + ```bash |
| 60 | + ./foremanctl deploy --foreman-initial-admin-password=changeme --tuning development |
| 61 | + ``` |
| 62 | +6. **Re-test** — run the test suite again: |
| 63 | + ```bash |
| 64 | + ./forge test |
| 65 | + ``` |
| 66 | +7. If tests pass, go to Phase 4. If tests still fail and attempts remain, repeat from step 1. |
| 67 | + |
| 68 | +### Phase 4: Report |
| 69 | + |
| 70 | +Produce a structured report: |
| 71 | + |
| 72 | +```markdown |
| 73 | +## Deploy and Test Results |
| 74 | + |
| 75 | +### Environment |
| 76 | +- VMs: started/failed |
| 77 | +- Deploy: success/failed (attempt N) |
| 78 | + |
| 79 | +### Tests |
| 80 | +- Passed: N |
| 81 | +- Failed: M |
| 82 | +- Skipped: K |
| 83 | + |
| 84 | +### Fixes Applied |
| 85 | +<!-- For each fix attempt --> |
| 86 | +- Attempt N: <description of what was changed and why> |
| 87 | + - Files modified: <list> |
| 88 | + - Result: pass/fail |
| 89 | + |
| 90 | +### Remaining Failures |
| 91 | +<!-- If any tests still fail after 2 attempts --> |
| 92 | +- test_name: <error summary> |
| 93 | +``` |
| 94 | + |
| 95 | +## Constraints |
| 96 | + |
| 97 | +- Only modify files that are directly causing test or deploy failures. |
| 98 | +- Do not refactor, clean up, or change unrelated code. |
| 99 | +- Do not modify test files to make them pass -- fix the source code instead. |
| 100 | +- If a failure is an infrastructure issue (VM, network, Vagrant, disk), stop and report. Do not attempt to fix. |
| 101 | +- Each deploy cycle takes several minutes. Budget time accordingly. |
| 102 | +- Maximum 2 fix attempts. After 2 failed attempts, report and stop. |
| 103 | + |
| 104 | +## Environment Details |
| 105 | + |
| 106 | +- VMs are managed by Vagrant (see `Vagrantfile`). |
| 107 | +- Tests use pytest with testinfra, connecting via SSH to VMs. |
| 108 | +- SSH config is generated at `.tmp/ssh-config` by the test playbook. |
| 109 | +- Default test credentials: `admin` / `changeme`. |
| 110 | +- Test fixtures and options are defined in `tests/conftest.py`. |
0 commit comments