chore: initial release v0.1.0

Runtime-agnostic oneshot broadcast channel for Rust.
This commit is contained in:
swaits committed 2025-10-13 19:36:37 -06:00
commit e8e55b7676
64 files changed
+23966

No files matched your search

+124
View File
@@ -0,0 +1,124 @@
#!/usr/bin/env python3
"""
Generate mutation testing trend report from mutation_history.json
"""
import json
import sys
from datetime import datetime
from pathlib import Path
def load_history(history_file: Path) -> list:
"""Load mutation testing history from JSON file."""
if not history_file.exists():
print(f"❌ History file not found: {history_file}")
sys.exit(1)
with open(history_file) as f:
return json.load(f)
def format_timestamp(ts: str) -> str:
"""Format ISO timestamp to readable date."""
dt = datetime.fromisoformat(ts.replace('Z', '+00:00'))
return dt.strftime('%Y-%m-%d %H:%M')
def print_summary(history: list) -> None:
"""Print summary statistics."""
if not history:
print("No mutation testing history found.")
return
latest = history[-1]
stats = latest['stats']
print("\n" + "=" * 70)
print(" MUTATION TESTING SUMMARY")
print("=" * 70)
print(f"\nLatest Run: {format_timestamp(latest['timestamp'])}")
print(f"Git Branch: {latest['git_branch']}")
print(f"Git Commit: {latest['git_commit'][:8]}")
print(f"\nCurrent Score: {stats['score']}%")
print(f" Total Mutants: {stats['total_mutants']}")
print(f" Viable: {stats['viable']}")
print(f" Caught: {stats['caught']}")
print(f" Missed: {stats['missed']}")
print(f" Timeout: {stats['timeout']}")
print(f" Unviable: {stats['unviable']}")
def print_trend(history: list, limit: int = 10) -> None:
"""Print mutation score trend."""
if len(history) < 2:
print("\n📊 Not enough history for trend analysis (need at least 2 runs)")
return
print(f"\n📈 TREND (last {min(limit, len(history))} runs):")
print("-" * 70)
print(f"{'Date':<17} {'Branch':<15} {'Score':<8} {'Caught/Viable':<15} {'Change'}")
print("-" * 70)
recent = history[-limit:] if len(history) > limit else history
prev_score = None
for entry in recent:
stats = entry['stats']
score = stats['score']
date = format_timestamp(entry['timestamp'])
branch = entry['git_branch'][:14]
caught_viable = f"{stats['caught']}/{stats['viable']}"
# Calculate change
if prev_score is not None:
change = score - prev_score
if change > 0:
change_str = f"+{change:.1f}% ⬆"
elif change < 0:
change_str = f"{change:.1f}% ⬇"
else:
change_str = "0.0% ➡"
else:
change_str = "-"
print(f"{date:<17} {branch:<15} {score:>6.1f}% {caught_viable:<15} {change_str}")
prev_score = score
def print_statistics(history: list) -> None:
"""Print overall statistics."""
if not history:
return
scores = [entry['stats']['score'] for entry in history]
avg_score = sum(scores) / len(scores)
min_score = min(scores)
max_score = max(scores)
print("\n📊 STATISTICS:")
print("-" * 70)
print(f"Total Runs: {len(history)}")
print(f"Average Score: {avg_score:.2f}%")
print(f"Min Score: {min_score:.2f}%")
print(f"Max Score: {max_score:.2f}%")
print(f"Score Range: {max_score - min_score:.2f}%")
def main():
"""Main entry point."""
history_file = Path("mutation_history.json")
if len(sys.argv) > 1:
history_file = Path(sys.argv[1])
history = load_history(history_file)
print_summary(history)
print_trend(history, limit=10)
print_statistics(history)
print("\n" + "=" * 70 + "\n")
if __name__ == "__main__":
main()
+140
View File
@@ -0,0 +1,140 @@
#!/usr/bin/env bash
# Track mutation testing scores over time
set -euo pipefail
# Configuration
HISTORY_FILE="mutation_history.json"
TEMP_FILE="mutants.out/outcomes.json"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo "🧬 Running mutation testing..."
echo ""
# Run mutation tests
if ! cargo mutants --no-shuffle --test-tool nextest --output-json; then
echo ""
echo -e "${RED}❌ Mutation testing failed${NC}"
exit 1
fi
echo ""
echo "📊 Analyzing results..."
# Check if outcomes.json exists
if [ ! -f "$TEMP_FILE" ]; then
echo -e "${RED}❌ No mutation results found${NC}"
exit 1
fi
# Extract stats from outcomes.json using jq
TOTAL_MUTANTS=$(jq '[.outcomes[] | select(.scenario != "Baseline")] | length' "$TEMP_FILE")
CAUGHT=$(jq '[.outcomes[] | select(.scenario != "Baseline") | select(.summary == "CaughtMutant")] | length' "$TEMP_FILE")
MISSED=$(jq '[.outcomes[] | select(.scenario != "Baseline") | select(.summary == "MissedMutant")] | length' "$TEMP_FILE")
TIMEOUT=$(jq '[.outcomes[] | select(.scenario != "Baseline") | select(.summary == "Timeout")] | length' "$TEMP_FILE")
UNVIABLE=$(jq '[.outcomes[] | select(.scenario != "Baseline") | select(.summary == "Unviable")] | length' "$TEMP_FILE")
# Calculate viable mutants (total - unviable)
VIABLE=$((TOTAL_MUTANTS - UNVIABLE))
# Calculate mutation score (caught / viable * 100)
if [ "$VIABLE" -eq 0 ]; then
SCORE=0
else
SCORE=$(echo "scale=2; $CAUGHT * 100 / $VIABLE" | bc)
fi
# Get current timestamp and git info
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
GIT_COMMIT=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
# Create history entry
ENTRY=$(cat <<EOF
{
"timestamp": "$TIMESTAMP",
"git_commit": "$GIT_COMMIT",
"git_branch": "$GIT_BRANCH",
"stats": {
"total_mutants": $TOTAL_MUTANTS,
"viable": $VIABLE,
"caught": $CAUGHT,
"missed": $MISSED,
"timeout": $TIMEOUT,
"unviable": $UNVIABLE,
"score": $SCORE
}
}
EOF
)
# Initialize history file if it doesn't exist
if [ ! -f "$HISTORY_FILE" ]; then
echo "[]" > "$HISTORY_FILE"
fi
# Append entry to history
jq ". += [$ENTRY]" "$HISTORY_FILE" > "${HISTORY_FILE}.tmp"
mv "${HISTORY_FILE}.tmp" "$HISTORY_FILE"
# Display results
echo ""
echo "═══════════════════════════════════════════════════════"
echo " MUTATION TESTING RESULTS"
echo "═══════════════════════════════════════════════════════"
echo ""
echo "Total mutants: $TOTAL_MUTANTS"
echo "├─ Viable: $VIABLE"
echo "├─ Caught: $CAUGHT ($(echo "scale=1; $CAUGHT * 100 / $VIABLE" | bc)%)"
echo "├─ Missed: $MISSED"
echo "├─ Timeout: $TIMEOUT"
echo "└─ Unviable: $UNVIABLE"
echo ""
# Color the score based on value
if (( $(echo "$SCORE >= 90" | bc -l) )); then
COLOR=$GREEN
STATUS="✅ EXCELLENT"
elif (( $(echo "$SCORE >= 80" | bc -l) )); then
COLOR=$YELLOW
STATUS="⚠️ GOOD"
else
COLOR=$RED
STATUS="❌ NEEDS IMPROVEMENT"
fi
echo -e "${COLOR}Mutation Score: ${SCORE}% ${STATUS}${NC}"
echo ""
# Show previous score if available
PREV_SCORE=$(jq -r '.[-2].stats.score // empty' "$HISTORY_FILE" 2>/dev/null || echo "")
if [ -n "$PREV_SCORE" ]; then
DIFF=$(echo "scale=2; $SCORE - $PREV_SCORE" | bc)
if (( $(echo "$DIFF > 0" | bc -l) )); then
echo -e "${GREEN}⬆ Improved by ${DIFF}% from previous run${NC}"
elif (( $(echo "$DIFF < 0" | bc -l) )); then
echo -e "${RED}⬇ Decreased by ${DIFF#-}% from previous run${NC}"
else
echo "➡ No change from previous run"
fi
echo ""
fi
echo "═══════════════════════════════════════════════════════"
echo ""
echo "📝 Results saved to: $HISTORY_FILE"
echo "🔬 Full report: mutants.out/"
echo ""
# Exit with failure if score is below threshold
THRESHOLD=85
if (( $(echo "$SCORE < $THRESHOLD" | bc -l) )); then
echo -e "${RED}⚠️ Mutation score ($SCORE%) is below threshold ($THRESHOLD%)${NC}"
exit 1
fi
echo -e "${GREEN}✅ Mutation testing passed!${NC}"