|
| 1 | +# Freebuff E2E Tests |
| 2 | + |
| 3 | +End-to-end tests for the Freebuff CLI binary. Tests verify that the compiled binary works correctly by interacting with it via tmux. |
| 4 | + |
| 5 | +## Architecture |
| 6 | + |
| 7 | +Two testing approaches are supported: |
| 8 | + |
| 9 | +### 1. Direct tmux tests (fast, deterministic) |
| 10 | + |
| 11 | +Use the `FreebuffSession` class to start the binary in tmux, send commands, capture output, and assert directly. |
| 12 | + |
| 13 | +```typescript |
| 14 | +import { describe, test, expect, afterEach } from 'bun:test' |
| 15 | +import { FreebuffSession, requireFreebuffBinary } from '../utils' |
| 16 | + |
| 17 | +describe('My Feature', () => { |
| 18 | + let session: FreebuffSession | null = null |
| 19 | + |
| 20 | + afterEach(async () => { |
| 21 | + if (session) await session.stop() |
| 22 | + session = null |
| 23 | + }) |
| 24 | + |
| 25 | + test('works correctly', async () => { |
| 26 | + const binary = requireFreebuffBinary() |
| 27 | + session = await FreebuffSession.start(binary) |
| 28 | + |
| 29 | + await session.send('/help') |
| 30 | + const output = await session.capture(2) |
| 31 | + |
| 32 | + expect(output).toContain('Shortcuts') |
| 33 | + }, 60_000) |
| 34 | +}) |
| 35 | +``` |
| 36 | + |
| 37 | +### 2. SDK agent-driven tests (AI-powered verification) |
| 38 | + |
| 39 | +Use the Codebuff SDK to run a testing agent that interacts with Freebuff via custom tmux tools. The agent reasons about the CLI output and verifies complex behaviors. |
| 40 | + |
| 41 | +```typescript |
| 42 | +import { describe, test, expect, afterEach } from 'bun:test' |
| 43 | +import { CodebuffClient } from '@codebuff/sdk' |
| 44 | +import { freebuffTesterAgent } from '../agent/freebuff-tester' |
| 45 | +import { createFreebuffTmuxTools, requireFreebuffBinary } from '../utils' |
| 46 | + |
| 47 | +describe('Agent Test', () => { |
| 48 | + let cleanup: (() => Promise<void>) | null = null |
| 49 | + |
| 50 | + afterEach(async () => { |
| 51 | + if (cleanup) await cleanup() |
| 52 | + cleanup = null |
| 53 | + }) |
| 54 | + |
| 55 | + test('verifies startup', async () => { |
| 56 | + const apiKey = process.env.CODEBUFF_API_KEY |
| 57 | + if (!apiKey) return // Skip if no API key |
| 58 | + |
| 59 | + const binary = requireFreebuffBinary() |
| 60 | + const tmuxTools = createFreebuffTmuxTools(binary) |
| 61 | + cleanup = tmuxTools.cleanup |
| 62 | + |
| 63 | + const client = new CodebuffClient({ apiKey }) |
| 64 | + const result = await client.run({ |
| 65 | + agent: freebuffTesterAgent.id, |
| 66 | + prompt: 'Start Freebuff and verify the branding is correct.', |
| 67 | + agentDefinitions: [freebuffTesterAgent], |
| 68 | + customToolDefinitions: tmuxTools.tools, |
| 69 | + handleEvent: () => {}, |
| 70 | + }) |
| 71 | + |
| 72 | + expect(result.output.type).not.toBe('error') |
| 73 | + }, 180_000) |
| 74 | +}) |
| 75 | +``` |
| 76 | + |
| 77 | +## Prerequisites |
| 78 | + |
| 79 | +- **tmux** must be installed: `brew install tmux` (macOS) or `sudo apt-get install tmux` (Ubuntu) |
| 80 | +- **Freebuff binary** must be built: `bun freebuff/cli/build.ts 0.0.0-dev` |
| 81 | +- **SDK built** (for agent tests): `cd sdk && bun run build` |
| 82 | +- **CODEBUFF_API_KEY** (for agent tests only): Set this environment variable |
| 83 | + |
| 84 | +## Running Tests |
| 85 | + |
| 86 | +### Build the binary first |
| 87 | + |
| 88 | +```bash |
| 89 | +bun freebuff/cli/build.ts 0.0.0-dev |
| 90 | +``` |
| 91 | + |
| 92 | +### Run all tests |
| 93 | + |
| 94 | +```bash |
| 95 | +bun test freebuff/e2e/tests/ |
| 96 | +``` |
| 97 | + |
| 98 | +### Run a specific test |
| 99 | + |
| 100 | +```bash |
| 101 | +bun test freebuff/e2e/tests/version.e2e.test.ts |
| 102 | +bun test freebuff/e2e/tests/startup.e2e.test.ts |
| 103 | +bun test freebuff/e2e/tests/help-command.e2e.test.ts |
| 104 | +bun test freebuff/e2e/tests/agent-startup.e2e.test.ts |
| 105 | +``` |
| 106 | + |
| 107 | +### Use a custom binary path |
| 108 | + |
| 109 | +```bash |
| 110 | +FREEBUFF_BINARY=/path/to/freebuff bun test freebuff/e2e/tests/ |
| 111 | +``` |
| 112 | + |
| 113 | +## Adding New Tests |
| 114 | + |
| 115 | +1. Create a new file in `freebuff/e2e/tests/` with the naming convention `<feature>.e2e.test.ts` |
| 116 | +2. Add the test name to `.github/workflows/freebuff-e2e.yml` matrix: |
| 117 | + |
| 118 | +```yaml |
| 119 | +matrix: |
| 120 | + test: |
| 121 | + - version |
| 122 | + - startup |
| 123 | + - help-command |
| 124 | + - agent-startup |
| 125 | + - your-new-test # <-- add here |
| 126 | +``` |
| 127 | +
|
| 128 | +3. The test will automatically run in parallel with other tests in CI. |
| 129 | +
|
| 130 | +## CI Workflow |
| 131 | +
|
| 132 | +The `.github/workflows/freebuff-e2e.yml` workflow: |
| 133 | + |
| 134 | +1. **Builds** the Freebuff binary once (linux-x64) |
| 135 | +2. **Runs each test file in parallel** via GitHub Actions matrix strategy |
| 136 | +3. **Uploads tmux session logs** on failure for debugging |
| 137 | + |
| 138 | +Triggers: |
| 139 | +- **Nightly** at 6:00 AM PT |
| 140 | +- **Manual** via workflow_dispatch |
| 141 | + |
| 142 | +## Utilities Reference |
| 143 | + |
| 144 | +### `FreebuffSession` |
| 145 | + |
| 146 | +| Method | Description | |
| 147 | +|--------|-------------| |
| 148 | +| `FreebuffSession.start(binaryPath)` | Start binary in tmux, returns session | |
| 149 | +| `session.send(text)` | Send text input (presses Enter) | |
| 150 | +| `session.sendKey(key)` | Send special key (e.g. `'C-c'`, `'Escape'`) | |
| 151 | +| `session.capture(waitSec?)` | Capture terminal output | |
| 152 | +| `session.captureLabeled(label, waitSec?)` | Capture and save to session logs | |
| 153 | +| `session.waitForText(pattern, timeoutMs?)` | Poll until text appears | |
| 154 | +| `session.stop()` | Stop session and clean up | |
| 155 | + |
| 156 | +### `createFreebuffTmuxTools(binaryPath)` |
| 157 | + |
| 158 | +Creates SDK custom tools for agent-driven testing: |
| 159 | +- `start_freebuff` - Launch the CLI |
| 160 | +- `send_to_freebuff` - Send text input |
| 161 | +- `capture_freebuff_output` - Capture terminal output |
| 162 | +- `stop_freebuff` - Stop and clean up |
| 163 | + |
| 164 | +### Helper functions |
| 165 | + |
| 166 | +| Function | Description | |
| 167 | +|----------|-------------| |
| 168 | +| `requireFreebuffBinary()` | Get binary path, throws if not found | |
| 169 | +| `getFreebuffBinaryPath()` | Get binary path (may not exist) | |
0 commit comments