huskies: merge 1251 story script/check gates duplication and cognitive complexity

This commit is contained in:
Huskies Agent
2026-07-21 16:15:10 +00:00
parent 14331127b8
commit 5c3b433e7d
4 changed files with 42 additions and 4 deletions
+12
View File
@@ -0,0 +1,12 @@
{
"threshold": 10,
"minLines": 10,
"minTokens": 50,
"ignore": [
"**/target/**",
"**/node_modules/**",
"**/dist/**",
"**/*.svg",
"**/flamegraphs/**"
]
}
+7
View File
@@ -0,0 +1,7 @@
# cognitive_complexity is allow-by-default in clippy; script/check enables it
# with `-W clippy::cognitive_complexity`. This threshold is set well above
# clippy's own default (25) to accommodate existing large dispatch functions
# (e.g. Matrix bot command routing) without requiring an unrelated refactor;
# it still gates against genuinely runaway complexity introduced going
# forward.
cognitive-complexity-threshold = 200
+5
View File
@@ -88,6 +88,11 @@ RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
# Claude Code CLI in runtime
RUN npm install -g @anthropic-ai/claude-code
# jscpd — duplication detector used by script/check. Installed in the
# runtime stage (not just the base build stage) so it's available to agents
# running script/check inside the sled, not only on a developer machine.
RUN npm install -g jscpd
# Cargo and Rust toolchain needed at runtime for:
# - rebuild_and_restart (cargo build inside the container)
# - Agent-driven cargo commands (cargo clippy, cargo test, etc.)
+18 -4
View File
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
# Pre-commit quality gate: fmt-check, clippy, cargo check, and doc-coverage.
# Run this before committing to catch fmt drift, clippy warnings, compile
# errors, and missing doc comments without waiting for the full test suite.
# Pre-commit quality gate: fmt-check, clippy, duplication, cargo check, and
# doc-coverage. Run this before committing to catch fmt drift, clippy
# warnings, duplicate code, compile errors, and missing doc comments without
# waiting for the full test suite.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
@@ -11,7 +12,20 @@ echo "=== Checking Rust formatting ==="
cargo fmt --manifest-path "$PROJECT_ROOT/Cargo.toml" --all --check
echo "=== Running cargo clippy ==="
cargo clippy --manifest-path "$PROJECT_ROOT/Cargo.toml" --workspace --all-targets -- -D warnings
# clippy::cognitive_complexity is allow-by-default; -W activates it so that
# -D warnings turns violations into a hard failure. The threshold it's
# measured against lives in clippy.toml (committed, not passed ad hoc).
cargo clippy --manifest-path "$PROJECT_ROOT/Cargo.toml" --workspace --all-targets -- -W clippy::cognitive_complexity -D warnings
echo "=== Checking code duplication (jscpd) ==="
if ! command -v jscpd &>/dev/null; then
echo "FAIL: jscpd is not installed. Install it with 'npm install -g jscpd' before running script/check." >&2
exit 1
fi
# Duplication threshold lives in .jscpd.json (committed, not passed ad hoc).
# jscpd exits non-zero automatically when duplication exceeds that threshold.
jscpd --config "$PROJECT_ROOT/.jscpd.json" \
"$PROJECT_ROOT/server/src" "$PROJECT_ROOT/frontend/src" "$PROJECT_ROOT/crates"
echo "=== Checking doc coverage on changed files ==="
cargo run --manifest-path "$PROJECT_ROOT/Cargo.toml" -p source-map-gen --bin source-map-check --quiet -- --worktree "$PROJECT_ROOT" --base master