-
Notifications
You must be signed in to change notification settings - Fork 2
Expert Plugins
smattymatty edited this page Aug 25, 2025
·
1 revision
For professionals who know what they're doing and need tools that keep up.
Expert plugins follow these principles:
- No interruptions: Get out of the way
- Fast execution: Minimal overhead
- Direct control: Exact commands, predictable results
- Actionable output: What failed and where
# Set expert profile
mercury-test --profile expert
# All subsequent runs use expert mode
mercury-test# mercury_config.toml
[mercury]
profile = "expert"
[profiles.expert]
plugins.enabled = ["discovery"] # Minimal plugins
educational_mode = false
verbosity = "low"
auto_fix_trivial = true
output_format = "concise"Expert mode only loads essential plugins:
# Expert mode startup
Loading plugins: discovery (10ms)
Total startup time: 45ms
# vs Student mode startup
Loading plugins: discovery, wizard, learn, hints (350ms)
Loading educational content... (200ms)
Total startup time: 580msIn expert mode, discovery is optimized for speed:
# First run: finds and caches
$ mercury-test
Found Django project: /home/dev/project/manage.py (cached)
# Subsequent runs: instant
$ mercury-test
Using cached: /home/dev/project/manage.py (0ms)# Expert mode - concise
$ mercury-test
No Django project found
# vs Student mode - educational
$ mercury-test
❌ Could not find valid manage.py
💡 Suggestions:
• Make sure you're in a Django project directory
• Try: mercury-test --search-deep
📚 Learn about Django project structure...Experts use precise test targeting:
# Run specific test methods
mercury-test users.tests.UserModelTest.test_user_creation
# Run with specific settings
mercury-test --parallel 8 --keepdb --reverse
# Pattern matching
mercury-test -k "performance" --failfastExpert output is dense and scannable:
$ mercury-test api.tests
PERFORMANCE REPORT
══════════════════════════════════════
api.tests.UserAPITest
test_list_users 0.045s 12q 23MB PASS
test_create_user 0.023s 3q 18MB PASS
test_bulk_create ⚠0.234s 89q 45MB SLOW
test_search_users ⚠0.567s 234q 67MB N+1
Summary: 3/4 passed, 2 performance issues
Total: 0.869s, 338 queries, 153MB
Run with --details for breakdown
Key:
- Time, queries (q), memory (MB)
- Visual indicators (⚠) for issues
- One-line summary
- Optional details flag
Experts use manual monitoring for precise control:
from django_mercury import DjangoPerformanceAPITestCase
from django_mercury import monitor_django_view
class ExpertPerformanceTest(DjangoPerformanceAPITestCase):
"""Expert-level performance testing with assertions."""
@classmethod
def setUpClass(cls):
super().setUpClass()
# Custom thresholds for this test suite
cls.set_performance_thresholds({
'response_time_ms': 50, # Strict: 50ms max
'query_count_max': 5, # Strict: 5 queries max
'memory_overhead_mb': 10, # Strict: 10MB max
})
def test_api_performance(self):
"""Test with specific performance assertions."""
with monitor_django_view("user_list") as monitor:
response = self.client.get('/api/users/')
# Precise assertions
self.assertResponseTimeLess(monitor, 50)
self.assertQueriesLess(monitor, 5)
self.assertNoNPlusOne(monitor)
self.assertMemoryEfficient(monitor)
# Custom business logic assertions
self.assertCacheHitRatio(monitor, 0.8) # 80% cache hits
self.assertDatabaseTime(monitor, 20) # 20ms max in DBExperts often create team-specific plugins:
# plugins/plugin_team_standards.py
from django_mercury.cli.plugins.base import MercuryPlugin
class TeamStandardsPlugin(MercuryPlugin):
"""Enforce team-specific performance standards."""
name = "team_standards"
priority = 50
audiences = ["expert"] # Only for expert mode
def post_test_hook(self, args, result, elapsed):
"""Check against team standards."""
if elapsed > 60: # Team rule: test suite under 60s
print(f"⚠️ Test suite too slow: {elapsed:.1f}s (limit: 60s)")
# Check for specific anti-patterns
self._check_serializer_performance()
self._check_api_pagination()
self._check_database_connections()Enable in config:
[profiles.expert]
plugins.enabled = ["discovery", "team_standards"]
[plugins.team_standards]
max_suite_time = 60
max_api_response_time = 100
require_pagination_over = 100Track performance over time:
# Record performance baseline
mercury-test --record-baseline
# Compare against baseline
mercury-test --compare-baseline
Performance changes since baseline:
api.tests.UserListView: +12ms (↑ 15%) ⚠️
api.tests.ProductSearch: -8ms (↓ 10%) ✅
api.tests.OrderCreate: No change
# Export metrics for CI
mercury-test --export-metrics=json > metrics.jsonDeep profiling when needed:
# Profile specific test with cProfile
mercury-test users.tests.SlowTest --profile
# Generate flame graph
mercury-test users.tests --flame-graph
# SQL query analysis
mercury-test --sql-analysis users.tests# .github/workflows/performance.yml
name: Performance Tests
on: [push, pull_request]
jobs:
performance:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run Mercury Performance Tests
run: |
mercury-test --profile expert \
--parallel 4 \
--export-metrics=json \
--fail-on-regression
- name: Upload Performance Report
uses: actions/upload-artifact@v2
with:
name: performance-metrics
path: mercury-metrics.json# .git/hooks/pre-commit
#!/bin/bash
# Run quick performance check
mercury-test --profile expert --quick --fail-fast
if [ $? -ne 0 ]; then
echo "Performance tests failed. Commit aborted."
exit 1
fi#!/usr/bin/env python
"""Continuous performance monitoring."""
import subprocess
import json
from datetime import datetime
def run_performance_suite():
"""Run performance tests and collect metrics."""
result = subprocess.run(
['mercury-test', '--profile', 'expert', '--export-metrics=json'],
capture_output=True,
text=True
)
metrics = json.loads(result.stdout)
# Alert on regressions
for test, data in metrics['tests'].items():
if data['response_time_ms'] > data['threshold']:
send_alert(f"Performance regression in {test}")
# Store for trending
store_metrics(metrics)
if __name__ == '__main__':
run_performance_suite()# Absolutely minimal - just discovery
[mercury]
profile = "expert"
[profiles.expert]
plugins.enabled = ["discovery"][mercury]
profile = "expert"
[profiles.expert]
plugins.enabled = ["discovery", "profiler", "sql_analyzer"]
output_format = "json"
export_metrics = true
fail_on_regression = true
[performance]
baseline_file = ".mercury/baseline.json"
regression_threshold = 0.1 # 10% slower = regression
track_queries = true
track_memory = true[mercury]
profile = "expert"
[profiles.expert]
plugins.enabled = ["discovery", "ci_reporter"]
output_format = "junit"
parallel_workers = "auto"
fail_fast = true
[ci]
artifact_path = "test-results/"
metrics_path = "performance-metrics/"
alert_webhook = "${SLACK_WEBHOOK}"# ~/.bashrc or ~/.zshrc
alias mt='mercury-test --profile expert'
alias mtp='mercury-test --profile expert --parallel 8'
alias mtf='mercury-test --profile expert --failfast'
alias mtd='mercury-test --profile expert --debug-sql'# conftest.py
import pytest
from django_mercury import monitor_django_view
@pytest.fixture
def perf_monitor():
"""Quick performance monitoring fixture."""
def _monitor(name="test"):
return monitor_django_view(name)
return _monitor
# Usage in tests
def test_api(perf_monitor):
with perf_monitor("api_call") as m:
response = client.get('/api/')
assert m.metrics.response_time < 100# Test multiple apps efficiently
for app in users products orders; do
mercury-test $app --parallel 4 &
done
wait# One-liner regression check
mercury-test --profile expert --compare-baseline || echo "REGRESSION DETECTED"# Export to different formats for analysis
mercury-test --export-metrics=json > metrics.json
mercury-test --export-metrics=csv > metrics.csv
mercury-test --export-metrics=prometheus > metrics.promWhen you need automation:
- CI/CD pipelines
- Automated monitoring
- AI-assisted development
- Batch processing
| Expert Mode | Agent Mode |
|---|---|
| Human-readable output | JSON/structured output |
| Interactive options | Non-interactive |
| Terminal colors | No formatting |
| Manual control | Automation-friendly |
Experts often contribute:
- Performance optimization plugins
- CI/CD integrations
- Profiling tools
- Database analyzers
- Blog about optimizations
- Share configs
- Contribute benchmarks
- Mentor juniors
- Need automation? See Agent Plugins
- Want to teach? Check Student Plugins
- Build custom plugins? See Plugin Development
Expert mode: Because sometimes you just need to get things done.