Refactor large Rust integration tests
Deploy / deploy (push) Successful in 1m35s
CI / Rust Checks (push) Failing after 5m44s
CI / UI Checks (push) Has been skipped
CI / Frontend E2E (push) Has been skipped
CI / Deployment Manifests (push) Has been skipped

This commit is contained in:
github-ops
2026-06-21 07:12:33 +00:00
parent d01c8e1f1a
commit a31862aeeb
23 changed files with 6119 additions and 5284 deletions
+48 -16
View File
@@ -4,6 +4,7 @@ set -euo pipefail
ROOT_DIR="${CRANK_RUST_HEALTH_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
DEFAULT_MAX_LINES="${CRANK_RUST_HEALTH_DEFAULT_MAX_LINES:-1000}"
INLINE_TEST_MAX_LINES="${CRANK_RUST_HEALTH_INLINE_TEST_MAX_LINES:-$(( DEFAULT_MAX_LINES / 2 ))}"
# Existing debt baseline. New files must stay under DEFAULT_MAX_LINES. These
# files are allowed to exist, but CI fails if they grow further.
@@ -37,22 +38,53 @@ done < <(
-name '*.rs' -print | sort
)
echo "Rust code health: checking new large inline test modules"
echo "Rust code health: checking large inline test modules"
while IFS=: read -r file line _; do
rel="${file#"$ROOT_DIR"/}"
if [[ -n "${FILE_LIMITS[$rel]:-}" ]]; then
continue
fi
lines="$(wc -l < "$file" | tr -d ' ')"
if (( lines > DEFAULT_MAX_LINES / 2 )); then
echo "error: $rel contains inline tests and has $lines lines; move integration-style tests to tests/" >&2
status=1
fi
done < <(
grep -RIn --include='*.rs' '^[[:space:]]*mod tests[[:space:]]*{' \
"$ROOT_DIR/apps" "$ROOT_DIR/crates" || true
)
if ! python3 - "$ROOT_DIR" "$INLINE_TEST_MAX_LINES" <<'PY'
from pathlib import Path
import sys
root = Path(sys.argv[1])
limit = int(sys.argv[2])
status = 0
def scan_roots():
for base_name in ("apps", "crates"):
base = root / base_name
if base.exists():
yield from base.rglob("*.rs")
for path in sorted(scan_roots()):
parts = set(path.relative_to(root).parts)
if "target" in parts or "node_modules" in parts or "tests" in parts:
continue
lines = path.read_text(encoding="utf-8").splitlines()
for index, line in enumerate(lines):
if line.strip() != "mod tests {":
continue
brace_depth = 0
end_index = len(lines) - 1
for cursor in range(index, len(lines)):
brace_depth += lines[cursor].count("{") - lines[cursor].count("}")
if cursor > index and brace_depth == 0:
end_index = cursor
break
module_lines = end_index - index + 1
if module_lines > limit:
rel = path.relative_to(root)
print(
f"error: {rel} contains inline tests at line {index + 1} "
f"with {module_lines} lines; limit is {limit}; "
"move integration-style tests to tests/",
file=sys.stderr,
)
status = 1
raise SystemExit(status)
PY
then
status=1
fi
if (( status != 0 )); then
cat >&2 <<'EOF'
@@ -62,7 +94,7 @@ Rust code health failed.
Rules:
- new Rust files must stay at or below 1000 lines;
- existing large files are pinned to the current baseline and must not grow;
- large inline test modules are forbidden outside the legacy allowlist;
- large inline test modules are forbidden, including in legacy large files;
- when touching a large file, extract modules or move integration-style tests to tests/.
EOF