Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,071 changes: 1,034 additions & 37 deletions Cargo.lock

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,36 @@ name = "rustwave-cli"
path = "src/main.rs"

[dependencies]
# — existing —
clap = { version = "4", features = ["derive"] }
hound = "3"
eframe = "0.31"

# — NEW: async runtime (required for axum) —
tokio = { version = "1", features = ["full"] }

# — NEW: HTTP server —
axum = { version = "0.7", features = ["multipart"] }
tower = "0.4"
tower-http = { version = "0.5", features = ["cors", "limit"] }

# — NEW: HTTP client (forward WAV to Broadcaster) —
reqwest = { version = "0.12", features = ["multipart", "json"] }

# — NEW: serialisation —
serde = { version = "1", features = ["derive"] }
serde_json = "1"

# — NEW: UUID generation for tx_id / queued_id —
uuid = { version = "1", features = ["v4", "serde"] }

# — NEW: logging / tracing —
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
tracing-appender = "0.2"

# — NEW: in-memory byte buffers (WAV bytes without temp files) —
bytes = "1"

# — NEW: error propagation in run_server —
anyhow = "1"
172 changes: 99 additions & 73 deletions dev-check-strict.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# dev-check.sh — full Rust quality gate
# dev-check.sh — full Rust quality gate (macOS)
# Runs: fmt · fix · clippy (pedantic+nursery) · tests · audit · deny · dupes
# Produces per-file clustered clippy reports in clippy_reports/

Expand All @@ -8,10 +8,21 @@ set -Eeuo pipefail
# ─── Colours ──────────────────────────────────────────────────────────────────

if [[ -t 1 ]]; then
RED='\033[0;31m'; YELLOW='\033[0;33m'; GREEN='\033[0;32m'
CYAN='\033[0;36m'; BOLD='\033[1m'; DIM='\033[2m'; RESET='\033[0m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
BOLD='\033[1m'
DIM='\033[2m'
RESET='\033[0m'
else
RED=''; YELLOW=''; GREEN=''; CYAN=''; BOLD=''; DIM=''; RESET=''
RED=''
YELLOW=''
GREEN=''
CYAN=''
BOLD=''
DIM=''
RESET=''
fi

# ─── Globals ──────────────────────────────────────────────────────────────────
Expand All @@ -29,7 +40,9 @@ SUMMARY_FILE="$REPORT_DIR/summary.txt"

# ─── Helpers ──────────────────────────────────────────────────────────────────

command_exists() { command -v "$1" >/dev/null 2>&1; }
has_cmd() {
type -P "$1" >/dev/null 2>&1
}

step() {
echo ""
Expand All @@ -38,44 +51,52 @@ step() {

pass() {
echo -e " ${GREEN}✓${RESET} $1"
(( PASS_COUNT++ )) || true
PASS_COUNT=$(( PASS_COUNT + 1 ))
}

fail() {
echo -e " ${RED}✗${RESET} $1"
(( FAIL_COUNT++ )) || true
FAIL_COUNT=$(( FAIL_COUNT + 1 ))
FAILED_STEPS+=("$1")
}

skip() {
echo -e " ${DIM}–${RESET} $1 ${DIM}(skipped — tool not installed)${RESET}"
(( SKIP_COUNT++ )) || true
SKIP_COUNT=$(( SKIP_COUNT + 1 ))
}

warn() { echo -e " ${YELLOW}⚠${RESET} $1"; }

require_tool() {
local tool="$1" install_hint="$2"
if ! command_exists "$tool"; then
echo -e "${RED}Error:${RESET} required tool '${BOLD}$tool${RESET}' is not installed."
echo -e " Install with: ${DIM}$install_hint${RESET}"
exit 1
fi
warn() {
echo -e " ${YELLOW}⚠${RESET} $1"
}

optional_tool() {
local tool="$1" install_hint="$2"
if ! command_exists "$tool"; then
warn "'$tool' not installed — step will be skipped."
warn "Install with: $install_hint"
fi
die() {
echo -e "${RED}Error:${RESET} $1"
echo -e " Install with: ${DIM}$2${RESET}"
exit 1
}

elapsed() {
local secs=$(( SECONDS - SCRIPT_START ))
printf '%dm%02ds' $(( secs / 60 )) $(( secs % 60 ))
}

# ─── Strip cargo noise from clippy output ─────────────────────────────────────

filter_clippy() {
grep -Ev \
'^[[:space:]]*(Compiling|Checking|Downloading|Updating|Fresh|Finished|Blocking|Locking|Dirty|Scraping|Running|Doctest)[[:space:]]' \
| grep -Ev \
'^[[:space:]]*= note: `#\[' \
| grep -Ev \
'^warning: [0-9]+ warning(s)? emitted' \
| grep -Ev \
'^error: aborting due to' \
| grep -Ev \
'^[[:space:]]*= note: for more information' \
| sed '/^[[:space:]]*$/d' \
|| true
}

# ─── Header ───────────────────────────────────────────────────────────────────

echo -e "${BOLD}"
Expand All @@ -84,30 +105,44 @@ echo "║ Rust Full Quality Gate Check ║"
echo "╚══════════════════════════════════════════════════╝"
echo -e "${RESET}"

# ─── CPU cores ────────────────────────────────────────────────────────────────
# ─── CPU cores (macOS-aware) ──────────────────────────────────────────────────

if command_exists sysctl; then
export CARGO_BUILD_JOBS; CARGO_BUILD_JOBS=$(sysctl -n hw.ncpu 2>/dev/null || echo 4)
elif command_exists nproc; then
export CARGO_BUILD_JOBS; CARGO_BUILD_JOBS=$(nproc)
else
export CARGO_BUILD_JOBS=4
fi
export CARGO_BUILD_JOBS
CARGO_BUILD_JOBS=$(sysctl -n hw.logicalcpu 2>/dev/null || echo 4)
echo -e " ${DIM}Using ${BOLD}${CARGO_BUILD_JOBS}${RESET}${DIM} CPU cores${RESET}"

# ─── Required tools ───────────────────────────────────────────────────────────

step "Verifying required tools"

require_tool "cargo" "https://rustup.rs"
require_tool "rustfmt" "rustup component add rustfmt"
require_tool "clippy-driver" "rustup component add clippy"
if ! has_cmd cargo; then
die "required tool 'cargo' is not installed." "https://rustup.rs"
fi

if ! has_cmd rustfmt; then
die "required tool 'rustfmt' is not installed." "rustup component add rustfmt"
fi

# clippy-driver is not always on PATH on macOS — check via cargo subcommand instead
if ! cargo clippy --version >/dev/null 2>&1; then
die "required tool 'clippy' is not installed." "rustup component add clippy"
fi

pass "cargo · rustfmt · clippy all present"

optional_tool "cargo-audit" "cargo install cargo-audit"
optional_tool "cargo-deny" "cargo install cargo-deny"
optional_tool "cargo-udeps" "cargo install cargo-udeps"
optional_tool "cargo-msrv" "cargo install cargo-msrv"
# Optional tools — warn but do not exit
if ! has_cmd cargo-audit; then
warn "'cargo-audit' not installed — step will be skipped. cargo install cargo-audit"
fi
if ! has_cmd cargo-deny; then
warn "'cargo-deny' not installed — step will be skipped. cargo install cargo-deny"
fi
if ! has_cmd cargo-udeps; then
warn "'cargo-udeps' not installed — step will be skipped. cargo install cargo-udeps"
fi
if ! has_cmd cargo-msrv; then
warn "'cargo-msrv' not installed — step will be skipped. cargo install cargo-msrv"
fi

# ─── Prepare report directory ─────────────────────────────────────────────────

Expand All @@ -118,7 +153,11 @@ mkdir -p "$CLUSTER_DIR"

if [[ "${1:-}" == "--update" ]]; then
step "Updating dependency index"
if cargo update 2>&1; then pass "cargo update"; else fail "cargo update"; fi
if cargo update 2>&1; then
pass "cargo update"
else
fail "cargo update"
fi
fi

# ─── 1. Format ────────────────────────────────────────────────────────────────
Expand All @@ -131,7 +170,6 @@ else
fail "cargo fmt --all"
fi

# Verify nothing was left dirty (useful in CI)
if git diff --quiet 2>/dev/null; then
pass "No unstaged format changes"
else
Expand All @@ -153,42 +191,25 @@ fi
step "3 · Lint (cargo clippy — pedantic + nursery)"

CLIPPY_FLAGS=(
# Hard errors
"-D" "warnings"

# Pedantic: correctness, performance, style improvements
"-W" "clippy::pedantic"

# Nursery: newer lints, some may be noisy — catches subtle bugs early
"-W" "clippy::nursery"

# Catch common correctness bugs missed by the default set
"-W" "clippy::correctness"
"-W" "clippy::suspicious"
"-W" "clippy::complexity"
"-W" "clippy::perf"

# Panic/unwrap hygiene — forces explicit error handling
"-W" "clippy::unwrap_used"
"-W" "clippy::expect_used"
"-W" "clippy::panic"
"-W" "clippy::todo"
"-W" "clippy::unimplemented"
"-W" "clippy::unreachable"

# Index panic risk
"-W" "clippy::indexing_slicing"

# Integer overflow in casts
"-W" "clippy::cast_possible_truncation"
"-W" "clippy::cast_possible_wrap"
"-W" "clippy::cast_sign_loss"
"-W" "clippy::cast_precision_loss"

# Arithmetic that can panic
"-W" "clippy::arithmetic_side_effects"

# Formatting / style discipline
"-W" "clippy::format_collect"
"-W" "clippy::uninlined_format_args"
"-W" "clippy::redundant_closure_for_method_calls"
Expand All @@ -209,6 +230,7 @@ CLIPPY_CMD=(
cargo clippy
--all-targets
--all-features
--message-format=short
--
"${CLIPPY_FLAGS[@]}"
)
Expand All @@ -217,14 +239,17 @@ echo -e " ${DIM}Running: ${CLIPPY_CMD[*]}${RESET}"
echo ""

CLIPPY_EXIT=0
"${CLIPPY_CMD[@]}" 2>&1 | tee "$RAW_FILE" || CLIPPY_EXIT=$?
"${CLIPPY_CMD[@]}" 2>&1 \
| filter_clippy \
| tee "$RAW_FILE" \
|| CLIPPY_EXIT=${PIPESTATUS[0]}

# ── Cluster clippy output by source file ─────────────────────────────────────
# ── Cluster clippy output by source file ─────────────────────────────────────

echo ""
echo -e " ${DIM}Clustering clippy output by file...${RESET}"

OUTFILE=""
CURRENT_OUTFILE=""
while IFS= read -r line; do
if [[ $line =~ ([a-zA-Z0-9_/.-]+\.rs):[0-9]+:[0-9]+ ]]; then
FILE="${BASH_REMATCH[1]}"
Expand All @@ -234,16 +259,16 @@ while IFS= read -r line; do
else
CLUSTER=$(echo "$DIR" | tr '/' '_')
fi
OUTFILE="$CLUSTER_DIR/${CLUSTER}.txt"
CURRENT_OUTFILE="$CLUSTER_DIR/${CLUSTER}.txt"
{
echo ""
echo "----------------------------------------"
echo "FILE: $FILE"
echo "----------------------------------------"
} >> "$OUTFILE"
} >> "$CURRENT_OUTFILE"
fi
if [[ -n "$OUTFILE" ]]; then
echo "$line" >> "$OUTFILE"
if [[ -n "$CURRENT_OUTFILE" ]]; then
echo "$line" >> "$CURRENT_OUTFILE"
fi
done < "$RAW_FILE"

Expand Down Expand Up @@ -273,7 +298,6 @@ TEST_EXIT=0
cargo test --all --all-features 2>&1 || TEST_EXIT=$?

if [[ $TEST_EXIT -eq 0 ]]; then
PASSED=$(grep -oP '\d+(?= passed)' <<< "$(cargo test --all --all-features 2>&1)" | tail -1 || echo "?")
pass "All tests passed"
else
fail "Test suite failed (exit $TEST_EXIT)"
Expand All @@ -283,7 +307,7 @@ fi

step "5 · Security audit (cargo audit)"

if command_exists cargo-audit; then
if has_cmd cargo-audit; then
AUDIT_EXIT=0
cargo audit 2>&1 || AUDIT_EXIT=$?
if [[ $AUDIT_EXIT -eq 0 ]]; then
Expand All @@ -299,7 +323,7 @@ fi

step "6 · Dependency policy (cargo deny)"

if command_exists cargo-deny; then
if has_cmd cargo-deny; then
DENY_EXIT=0
cargo deny check 2>&1 || DENY_EXIT=$?
if [[ $DENY_EXIT -eq 0 ]]; then
Expand All @@ -315,7 +339,7 @@ fi

step "7 · Unused dependencies (cargo udeps)"

if command_exists cargo-udeps; then
if has_cmd cargo-udeps; then
UDEPS_EXIT=0
cargo +nightly udeps --all-targets 2>&1 || UDEPS_EXIT=$?
if [[ $UDEPS_EXIT -eq 0 ]]; then
Expand All @@ -331,7 +355,7 @@ fi

step "8 · Minimum supported Rust version (cargo msrv)"

if command_exists cargo-msrv; then
if has_cmd cargo-msrv; then
MSRV_EXIT=0
cargo msrv verify 2>&1 || MSRV_EXIT=$?
if [[ $MSRV_EXIT -eq 0 ]]; then
Expand All @@ -350,8 +374,8 @@ step "9 · Duplicate dependencies (cargo tree -d)"
DUPES=$(cargo tree -d 2>&1 || true)
if echo "$DUPES" | grep -q '\['; then
warn "Duplicate crate versions detected:"
echo "$DUPES" | grep '^\[' | sort -u | while read -r line; do
echo -e " ${YELLOW}$line${RESET}"
echo "$DUPES" | grep '^\[' | sort -u | while IFS= read -r line; do
echo -e " ${YELLOW}${line}${RESET}"
done
else
pass "No duplicate crate versions"
Expand Down Expand Up @@ -382,7 +406,9 @@ TOTAL_SECS=$(( SECONDS - SCRIPT_START ))
if [[ ${#FAILED_STEPS[@]} -gt 0 ]]; then
echo ""
echo "Failed steps:"
for s in "${FAILED_STEPS[@]}"; do echo " - $s"; done
for s in "${FAILED_STEPS[@]}"; do
echo " - $s"
done
fi
} | tee "$SUMMARY_FILE"

Expand All @@ -407,4 +433,4 @@ else
echo ""
echo -e " ${DIM}Reports saved to: $REPORT_DIR/${RESET}"
exit 1
fi
fi
Loading