ace-test 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.ace-defaults/nav/protocols/agent-sources/ace-test.yml +19 -0
- data/.ace-defaults/nav/protocols/guide-sources/ace-test.yml +19 -0
- data/.ace-defaults/nav/protocols/tmpl-sources/ace-test.yml +11 -0
- data/.ace-defaults/nav/protocols/wfi-sources/ace-test.yml +19 -0
- data/CHANGELOG.md +169 -0
- data/LICENSE +21 -0
- data/README.md +40 -0
- data/Rakefile +12 -0
- data/handbook/agents/mock.ag.md +164 -0
- data/handbook/agents/profile-tests.ag.md +132 -0
- data/handbook/agents/test.ag.md +99 -0
- data/handbook/guides/SUMMARY.md +95 -0
- data/handbook/guides/embedded-testing-guide.g.md +261 -0
- data/handbook/guides/mocking-patterns.g.md +464 -0
- data/handbook/guides/quick-reference.g.md +46 -0
- data/handbook/guides/test-driven-development-cycle/meta-documentation.md +26 -0
- data/handbook/guides/test-driven-development-cycle/ruby-application.md +18 -0
- data/handbook/guides/test-driven-development-cycle/ruby-gem.md +19 -0
- data/handbook/guides/test-driven-development-cycle/rust-cli.md +18 -0
- data/handbook/guides/test-driven-development-cycle/rust-wasm-zed.md +19 -0
- data/handbook/guides/test-driven-development-cycle/typescript-nuxt.md +18 -0
- data/handbook/guides/test-driven-development-cycle/typescript-vue.md +19 -0
- data/handbook/guides/test-layer-decision.g.md +261 -0
- data/handbook/guides/test-mocking-patterns.g.md +414 -0
- data/handbook/guides/test-organization.g.md +140 -0
- data/handbook/guides/test-performance.g.md +353 -0
- data/handbook/guides/test-responsibility-map.g.md +220 -0
- data/handbook/guides/test-review-checklist.g.md +231 -0
- data/handbook/guides/test-suite-health.g.md +337 -0
- data/handbook/guides/testable-code-patterns.g.md +315 -0
- data/handbook/guides/testing/ruby-rspec-config-examples.md +120 -0
- data/handbook/guides/testing/ruby-rspec.md +87 -0
- data/handbook/guides/testing/rust.md +52 -0
- data/handbook/guides/testing/test-maintenance.md +364 -0
- data/handbook/guides/testing/typescript-bun.md +47 -0
- data/handbook/guides/testing/vue-firebase-auth.md +546 -0
- data/handbook/guides/testing/vue-vitest.md +236 -0
- data/handbook/guides/testing-philosophy.g.md +82 -0
- data/handbook/guides/testing-strategy.g.md +151 -0
- data/handbook/guides/testing-tdd-cycle.g.md +146 -0
- data/handbook/guides/testing.g.md +170 -0
- data/handbook/skills/as-test-create-cases/SKILL.md +24 -0
- data/handbook/skills/as-test-fix/SKILL.md +26 -0
- data/handbook/skills/as-test-improve-coverage/SKILL.md +22 -0
- data/handbook/skills/as-test-optimize/SKILL.md +34 -0
- data/handbook/skills/as-test-performance-audit/SKILL.md +34 -0
- data/handbook/skills/as-test-plan/SKILL.md +34 -0
- data/handbook/skills/as-test-review/SKILL.md +34 -0
- data/handbook/skills/as-test-verify-suite/SKILL.md +45 -0
- data/handbook/templates/e2e-sandbox-checklist.template.md +289 -0
- data/handbook/templates/test-case.template.md +56 -0
- data/handbook/templates/test-performance-audit.template.md +132 -0
- data/handbook/templates/test-responsibility-map.template.md +92 -0
- data/handbook/templates/test-review-checklist.template.md +163 -0
- data/handbook/workflow-instructions/test/analyze-failures.wf.md +120 -0
- data/handbook/workflow-instructions/test/create-cases.wf.md +675 -0
- data/handbook/workflow-instructions/test/fix.wf.md +120 -0
- data/handbook/workflow-instructions/test/improve-coverage.wf.md +370 -0
- data/handbook/workflow-instructions/test/optimize.wf.md +368 -0
- data/handbook/workflow-instructions/test/performance-audit.wf.md +17 -0
- data/handbook/workflow-instructions/test/plan.wf.md +323 -0
- data/handbook/workflow-instructions/test/review.wf.md +16 -0
- data/handbook/workflow-instructions/test/verify-suite.wf.md +343 -0
- data/lib/ace/test/version.rb +7 -0
- data/lib/ace/test.rb +10 -0
- metadata +152 -0
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
---
|
|
2
|
+
doc-type: guide
|
|
3
|
+
title: Test Maintenance Guide
|
|
4
|
+
purpose: Test maintenance and reliability
|
|
5
|
+
ace-docs:
|
|
6
|
+
last-updated: 2026-01-23
|
|
7
|
+
last-checked: 2026-03-21
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Test Maintenance Guide
|
|
11
|
+
|
|
12
|
+
This guide provides best practices and workflows for maintaining a reliable test suite in the Coding Agent Tools project.
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
Test maintenance is crucial for ensuring a trustworthy development process. This guide covers:
|
|
17
|
+
- Identifying and fixing flaky tests
|
|
18
|
+
- Optimizing slow tests
|
|
19
|
+
- Tracking test reliability metrics
|
|
20
|
+
- Migration strategies for deprecated tools
|
|
21
|
+
|
|
22
|
+
## Test Reliability Tracking
|
|
23
|
+
|
|
24
|
+
### Automatic Tracking
|
|
25
|
+
|
|
26
|
+
The test suite automatically tracks execution metrics for all tests:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Run tests with reliability tracking enabled (default)
|
|
30
|
+
bundle exec rspec
|
|
31
|
+
|
|
32
|
+
# View reliability report after test run
|
|
33
|
+
SHOW_RELIABILITY_REPORT=1 bundle exec rspec
|
|
34
|
+
|
|
35
|
+
# Disable tracking if needed
|
|
36
|
+
DISABLE_TEST_TRACKING=1 bundle exec rspec
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Manual Analysis
|
|
40
|
+
|
|
41
|
+
Use the `test-reliability` CLI tool to analyze test metrics:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# Generate comprehensive report
|
|
45
|
+
bin/test-reliability report
|
|
46
|
+
|
|
47
|
+
# Show only flaky tests
|
|
48
|
+
bin/test-reliability flaky
|
|
49
|
+
|
|
50
|
+
# Show slow tests (default threshold: 1s)
|
|
51
|
+
bin/test-reliability slow
|
|
52
|
+
|
|
53
|
+
# Show slow tests with custom threshold
|
|
54
|
+
bin/test-reliability slow --threshold 0.5
|
|
55
|
+
|
|
56
|
+
# Export data as JSON
|
|
57
|
+
bin/test-reliability report --format json
|
|
58
|
+
|
|
59
|
+
# Clear tracking data
|
|
60
|
+
bin/test-reliability clear
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Identifying Flaky Tests
|
|
64
|
+
|
|
65
|
+
### What Makes a Test Flaky?
|
|
66
|
+
|
|
67
|
+
Flaky tests are tests that fail intermittently without code changes. Common causes:
|
|
68
|
+
- Race conditions
|
|
69
|
+
- Time-dependent logic
|
|
70
|
+
- External dependencies
|
|
71
|
+
- Shared state between tests
|
|
72
|
+
- Random data generation
|
|
73
|
+
|
|
74
|
+
### Detection Strategy
|
|
75
|
+
|
|
76
|
+
1. **Automatic Detection**: Tests with 20-80% failure rate are flagged as flaky
|
|
77
|
+
2. **Manual Verification**: Run suspected flaky tests multiple times:
|
|
78
|
+
```bash
|
|
79
|
+
# Run specific test 10 times
|
|
80
|
+
for i in {1..10}; do bundle exec rspec path/to/spec.rb:line; done
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Fixing Flaky Tests
|
|
84
|
+
|
|
85
|
+
1. **Add Retry Logic**: For known flaky tests, add retry metadata:
|
|
86
|
+
```ruby
|
|
87
|
+
it 'handles network timeouts', retry: 2 do
|
|
88
|
+
# Test that occasionally fails due to network issues
|
|
89
|
+
end
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
2. **Fix Root Causes**:
|
|
93
|
+
- Use deterministic test data
|
|
94
|
+
- Mock time-dependent operations
|
|
95
|
+
- Ensure proper test isolation
|
|
96
|
+
- Add explicit waits for async operations
|
|
97
|
+
|
|
98
|
+
## Optimizing Slow Tests
|
|
99
|
+
|
|
100
|
+
### Identifying Slow Tests
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# Run tests with profiling
|
|
104
|
+
bundle exec rspec --profile 10
|
|
105
|
+
|
|
106
|
+
# Use test-reliability tool
|
|
107
|
+
bin/test-reliability slow --threshold 0.5
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Optimization Strategies
|
|
111
|
+
|
|
112
|
+
1. **Reduce Timeout Values**: For timeout tests, use minimal values:
|
|
113
|
+
```ruby
|
|
114
|
+
# Before: Takes 2+ seconds
|
|
115
|
+
it 'times out long-running commands' do
|
|
116
|
+
result = execute('sleep 2', timeout: 1)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# After: Takes ~1 second
|
|
120
|
+
it 'times out long-running commands' do
|
|
121
|
+
result = execute('sleep 1.1', timeout: 1)
|
|
122
|
+
end
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
2. **Use Faster Test Doubles**:
|
|
126
|
+
```ruby
|
|
127
|
+
# Before: Real HTTP request
|
|
128
|
+
response = client.get('https://api.example.com/data')
|
|
129
|
+
|
|
130
|
+
# After: Stubbed response
|
|
131
|
+
allow(client).to receive(:get).and_return(mock_response)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
3. **Batch Similar Tests**: Group related assertions to reduce setup overhead
|
|
135
|
+
|
|
136
|
+
4. **Use Composite Helpers**: Reduce 6-7 level nesting to single helper calls
|
|
137
|
+
(See [Test Performance - Composite Test Helpers](guide://test-performance))
|
|
138
|
+
|
|
139
|
+
5. **Apply E2E Rule**: Keep ONE E2E test per file, convert rest to mocked versions
|
|
140
|
+
(See [Test Performance - E2E Test Strategy](guide://test-performance))
|
|
141
|
+
|
|
142
|
+
6. **Stub at Correct Layer**: Use `with_empty_git_diff` for DiffOrchestrator stubbing
|
|
143
|
+
(See [Mocking Patterns - DiffOrchestrator Stubbing](guide://mocking-patterns))
|
|
144
|
+
|
|
145
|
+
7. **Stub Sleep in Retry Tests**: Avoid 1-2s delays per sleep call
|
|
146
|
+
(See [Test Performance - Sleep Stubbing](guide://test-performance))
|
|
147
|
+
|
|
148
|
+
8. **Watch for Zombie Mocks**: Stubs that don't match actual code paths run real operations
|
|
149
|
+
(See [Test Performance - Zombie Mocks](guide://test-performance))
|
|
150
|
+
|
|
151
|
+
## Ruby 3.4.2 Compatibility
|
|
152
|
+
|
|
153
|
+
### VCR Migration
|
|
154
|
+
|
|
155
|
+
VCR is currently disabled for Ruby 3.4.2 due to compatibility issues. To migrate existing VCR cassettes:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
# Convert VCR cassette to WebMock stubs
|
|
159
|
+
ruby spec/support/vcr_migration_helper.rb spec/cassettes/old_test.yml
|
|
160
|
+
|
|
161
|
+
# This creates spec/cassettes/old_test_webmock.rb
|
|
162
|
+
# Include it in your spec:
|
|
163
|
+
require_relative '../cassettes/old_test_webmock'
|
|
164
|
+
|
|
165
|
+
before do
|
|
166
|
+
setup_webmock_stubs
|
|
167
|
+
end
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Keyword Arguments
|
|
171
|
+
|
|
172
|
+
Ruby 3.4.2 enforces stricter keyword argument separation:
|
|
173
|
+
|
|
174
|
+
```ruby
|
|
175
|
+
# Before (Ruby 2.x style)
|
|
176
|
+
def method(opts = {})
|
|
177
|
+
value = opts[:key]
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# After (Ruby 3.x style)
|
|
181
|
+
def method(**opts)
|
|
182
|
+
value = opts[:key]
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# Or with explicit keywords
|
|
186
|
+
def method(key: nil)
|
|
187
|
+
value = key
|
|
188
|
+
end
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## Test Suite Health Metrics
|
|
192
|
+
|
|
193
|
+
### Key Metrics to Track
|
|
194
|
+
|
|
195
|
+
1. **Overall Success Rate**: Should be > 99%
|
|
196
|
+
2. **Flaky Test Count**: Should be < 1% of total tests
|
|
197
|
+
3. **Average Execution Time**: Full suite should run in < 2 minutes
|
|
198
|
+
4. **Slow Test Count**: < 5% of tests should take > 1 second
|
|
199
|
+
|
|
200
|
+
### Regular Maintenance Tasks
|
|
201
|
+
|
|
202
|
+
#### Daily
|
|
203
|
+
- Review CI failures for flaky tests
|
|
204
|
+
- Fix any broken tests immediately
|
|
205
|
+
|
|
206
|
+
#### Weekly
|
|
207
|
+
- Run `bin/test-reliability report` to identify trends
|
|
208
|
+
- Address top 3 slowest tests
|
|
209
|
+
- Fix or mark flaky tests for investigation
|
|
210
|
+
|
|
211
|
+
#### Monthly
|
|
212
|
+
- Full test suite audit
|
|
213
|
+
- Update deprecated testing patterns
|
|
214
|
+
- Review and update test documentation
|
|
215
|
+
|
|
216
|
+
## Best Practices
|
|
217
|
+
|
|
218
|
+
### Writing Reliable Tests
|
|
219
|
+
|
|
220
|
+
1. **Isolation**: Each test should be independent
|
|
221
|
+
```ruby
|
|
222
|
+
before(:each) do
|
|
223
|
+
# Reset state
|
|
224
|
+
DatabaseCleaner.start
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
after(:each) do
|
|
228
|
+
DatabaseCleaner.clean
|
|
229
|
+
end
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
2. **Deterministic Data**: Avoid randomness
|
|
233
|
+
```ruby
|
|
234
|
+
# Bad
|
|
235
|
+
let(:user) { create(:user, age: rand(18..65)) }
|
|
236
|
+
|
|
237
|
+
# Good
|
|
238
|
+
let(:user) { create(:user, age: 25) }
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
3. **Clear Assertions**: Be specific about expectations
|
|
242
|
+
```ruby
|
|
243
|
+
# Bad
|
|
244
|
+
expect(result).to be_truthy
|
|
245
|
+
|
|
246
|
+
# Good
|
|
247
|
+
expect(result.success?).to be true
|
|
248
|
+
expect(result.message).to eq('Operation completed')
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Test Organization
|
|
252
|
+
|
|
253
|
+
1. **Descriptive Names**: Test names should explain the behavior
|
|
254
|
+
```ruby
|
|
255
|
+
# Bad
|
|
256
|
+
it 'works' do
|
|
257
|
+
|
|
258
|
+
# Good
|
|
259
|
+
it 'returns error when timeout exceeds maximum allowed value' do
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
2. **Logical Grouping**: Use contexts to organize related tests
|
|
263
|
+
```ruby
|
|
264
|
+
context 'with valid input' do
|
|
265
|
+
it 'processes successfully' do
|
|
266
|
+
|
|
267
|
+
context 'with invalid input' do
|
|
268
|
+
it 'raises ArgumentError' do
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
3. **Shared Examples**: DRY up common test patterns
|
|
272
|
+
```ruby
|
|
273
|
+
shared_examples 'a timeout handler' do
|
|
274
|
+
it 'respects the timeout value' do
|
|
275
|
+
# Common timeout behavior
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Troubleshooting
|
|
281
|
+
|
|
282
|
+
### Common Issues
|
|
283
|
+
|
|
284
|
+
1. **"No such file or directory" errors**
|
|
285
|
+
- Ensure test files use absolute paths or proper fixtures
|
|
286
|
+
- Check for missing test data files
|
|
287
|
+
|
|
288
|
+
2. **Timeout failures in CI**
|
|
289
|
+
- CI environments may be slower
|
|
290
|
+
- Consider increasing timeouts for CI: `timeout * (ENV['CI'] ? 2 : 1)`
|
|
291
|
+
|
|
292
|
+
3. **Database connection errors**
|
|
293
|
+
- Ensure proper cleanup between tests
|
|
294
|
+
- Check for connection pool exhaustion
|
|
295
|
+
|
|
296
|
+
### Debug Techniques
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
# Run with debug output
|
|
300
|
+
DEBUG=1 bundle exec rspec
|
|
301
|
+
|
|
302
|
+
# Run with seed for reproducibility
|
|
303
|
+
bundle exec rspec --seed 12345
|
|
304
|
+
|
|
305
|
+
# Run in documentation format for clarity
|
|
306
|
+
bundle exec rspec --format documentation
|
|
307
|
+
|
|
308
|
+
# Run with backtrace for errors
|
|
309
|
+
bundle exec rspec --backtrace
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
## Migration Guides
|
|
313
|
+
|
|
314
|
+
### From VCR to WebMock
|
|
315
|
+
|
|
316
|
+
1. Identify specs using VCR:
|
|
317
|
+
```bash
|
|
318
|
+
grep -r "vcr: true" spec/
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
2. Convert each cassette:
|
|
322
|
+
```bash
|
|
323
|
+
ruby spec/support/vcr_migration_helper.rb spec/cassettes/[cassette].yml
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
3. Update the spec:
|
|
327
|
+
```ruby
|
|
328
|
+
# Remove
|
|
329
|
+
it 'makes API call', vcr: true do
|
|
330
|
+
|
|
331
|
+
# Add
|
|
332
|
+
require_relative '../cassettes/[cassette]_webmock'
|
|
333
|
+
|
|
334
|
+
before do
|
|
335
|
+
setup_webmock_stubs
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
it 'makes API call' do
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Updating Timeout Tests
|
|
342
|
+
|
|
343
|
+
For tests that check timeout behavior:
|
|
344
|
+
|
|
345
|
+
1. Use integer timeout values (Ruby 3.4.2 requirement)
|
|
346
|
+
2. Ensure sleep duration exceeds timeout
|
|
347
|
+
3. Consider reducing timeouts for faster execution
|
|
348
|
+
|
|
349
|
+
```ruby
|
|
350
|
+
# Template for timeout tests
|
|
351
|
+
it 'handles timeout correctly' do
|
|
352
|
+
# Minimum reliable timeout test
|
|
353
|
+
result = execute('sleep 1.5', timeout: 1)
|
|
354
|
+
expect(result.success?).to be false
|
|
355
|
+
expect(result.stderr).to include('timed out')
|
|
356
|
+
end
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
## Resources
|
|
360
|
+
|
|
361
|
+
- [RSpec Best Practices](https://www.betterspecs.org/)
|
|
362
|
+
- [Ruby 3.0 Keyword Arguments](https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/)
|
|
363
|
+
- [WebMock Documentation](https://github.com/bblimke/webmock)
|
|
364
|
+
- [Test Reliability Tracker Source](../../spec/support/test_reliability_tracker.rb)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
doc-type: guide
|
|
3
|
+
title: TypeScript (Bun) Testing Guide
|
|
4
|
+
purpose: Bun TypeScript testing reference
|
|
5
|
+
ace-docs:
|
|
6
|
+
last-updated: 2026-01-23
|
|
7
|
+
last-checked: 2026-03-21
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# TypeScript (Bun) Testing Guide
|
|
11
|
+
|
|
12
|
+
This guide outlines testing best practices when using TypeScript with the Bun runtime.
|
|
13
|
+
|
|
14
|
+
## 1. Test Framework
|
|
15
|
+
|
|
16
|
+
Use `bun test` with built-in expect API.
|
|
17
|
+
|
|
18
|
+
## 2. Directory Structure
|
|
19
|
+
|
|
20
|
+
```text
|
|
21
|
+
project-root/
|
|
22
|
+
└── tests/
|
|
23
|
+
└── utils.test.ts
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Use `.test.ts` naming convention.
|
|
27
|
+
|
|
28
|
+
## 3. Assertions & Mocks
|
|
29
|
+
|
|
30
|
+
- Use Bun’s built-in `mockModule` for mocking imports.
|
|
31
|
+
- Prefer `vi.fn()` equivalents for spies (coming soon in Bun).
|
|
32
|
+
|
|
33
|
+
## 4. Coverage
|
|
34
|
+
|
|
35
|
+
`bun test --coverage` generates LCOV.
|
|
36
|
+
|
|
37
|
+
## 5. Running Tests
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
bun test
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Use `--watch` during development.
|
|
44
|
+
|
|
45
|
+
## 6. CI Integration
|
|
46
|
+
|
|
47
|
+
Ensure installing bun and running `bun test --coverage`.
|