Repository navigation
Expand file tree
/
Copy pathcheck.sh
More file actions
executable file
·161 lines (147 loc) · 6.08 KB
/
Copy pathcheck.sh
File metadata and controls
executable file
·161 lines (147 loc) · 6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
# ANSI High-Contrast Professional Palette (Matching Topo Core & install.sh)
if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then
PURPLE='\033[1;95m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[1;31m'
GRAY='\033[38;5;244m'
NC='\033[0m' # No Color
else
PURPLE=''
GREEN=''
YELLOW=''
RED=''
GRAY=''
NC=''
fi
AUTO_FIX=0
if [ "$1" == "--fix" ]; then
AUTO_FIX=1
echo -e "${PURPLE}🛠️ Auto-fix mode enabled!${NC} ${GRAY}Tools will attempt to fix issues automatically.${NC}\n"
else
echo -e "${PURPLE}▶ Starting Local Pre-commit Checks for Topo...${NC}"
echo -e "${GRAY}💡 Hint: Run './check.sh --fix' to automatically fix linting errors.${NC}\n"
fi
echo -e "${PURPLE}☉ 1. Formatting Code...${NC}"
# Plain ./check.sh asks the same question CI asks (--check); ./check.sh --fix is
# the mode that rewrites files. It used to format unconditionally, so a run that
# said "✓ Ruff format" had just made the change CI would have failed on, and the
# commit that followed was only clean because the check itself had edited it.
if [ $AUTO_FIX -eq 1 ]; then
FORMAT_CMD="ruff format src tests"
CARGO_FMT_CMD="cargo fmt --manifest-path topo-core/Cargo.toml"
else
FORMAT_CMD="ruff format --check src tests"
CARGO_FMT_CMD="cargo fmt --manifest-path topo-core/Cargo.toml --check"
fi
if ! OUT=$($FORMAT_CMD 2>&1); then
echo -e "${RED}❌ Ruff format failed:${NC}\n$OUT"
echo -e "${GRAY} Run './check.sh --fix' to apply the formatting.${NC}"
exit 1
fi
echo -e " ${GREEN}✓${NC} ${GRAY}Ruff format${NC}"
if ! OUT=$($CARGO_FMT_CMD 2>&1); then
echo -e "${RED}❌ Cargo fmt failed:${NC}\n$OUT"
echo -e "${GRAY} Run './check.sh --fix' to apply the formatting.${NC}"
exit 1
fi
echo -e " ${GREEN}✓${NC} ${GRAY}Cargo fmt${NC}"
echo -e " ${GREEN}✓${NC} ${GRAY}Formatting complete.${NC}\n"
echo -e "${PURPLE}☉ 2. Running Python Linters...${NC}"
if [ $AUTO_FIX -eq 1 ]; then
RUFF_CMD="ruff check --fix src tests"
else
RUFF_CMD="ruff check src tests"
fi
if ! OUT=$($RUFF_CMD 2>&1); then
echo -e "${RED}❌ Ruff check failed:${NC}\n$OUT"
exit 1
fi
echo -e " ${GREEN}✓${NC} ${GRAY}Ruff check${NC}"
if ! OUT=$(mypy --check-untyped-defs src/ 2>&1); then
echo -e "${RED}❌ Mypy type check failed:${NC}\n$OUT"
exit 1
fi
echo -e " ${GREEN}✓${NC} ${GRAY}Mypy type check${NC}"
if command -v tach &> /dev/null; then
if ! OUT=$(tach check 2>&1); then
echo -e "${RED}❌ Tach module check failed:${NC}\n$OUT"
exit 1
fi
echo -e " ${GREEN}✓${NC} ${GRAY}Tach module boundary check${NC}"
else
echo -e " ${YELLOW}⚠️${NC} ${GRAY}Tach not installed; module check SKIPPED (pip install -r requirements-dev.txt).${NC}"
fi
if command -v vulture &> /dev/null; then
if ! OUT=$(vulture src/ 2>&1); then
echo -e "${RED}❌ Vulture dead code check failed:${NC}\n$OUT"
exit 1
fi
echo -e " ${GREEN}✓${NC} ${GRAY}Vulture dead code check${NC}"
else
echo -e " ${YELLOW}⚠️${NC} ${GRAY}Vulture not installed; dead code check SKIPPED (pip install -r requirements-dev.txt).${NC}"
fi
echo -e " ${GREEN}✓${NC} ${GRAY}Python linting complete.${NC}\n"
echo -e "${PURPLE}☉ 3. Running Rust Linters...${NC}"
if [ $AUTO_FIX -eq 1 ]; then
CLIPPY_CMD="cargo clippy --quiet --manifest-path topo-core/Cargo.toml --fix --allow-dirty --allow-no-vcs -- -D warnings"
else
CLIPPY_CMD="cargo clippy --quiet --manifest-path topo-core/Cargo.toml -- -D warnings"
fi
if ! OUT=$($CLIPPY_CMD 2>&1); then
echo -e "${RED}❌ Cargo clippy failed:${NC}\n$OUT"
exit 1
fi
echo -e " ${GREEN}✓${NC} ${GRAY}Cargo clippy${NC}"
echo -e " ${GREEN}✓${NC} ${GRAY}Rust linting complete.${NC}\n"
echo -e "${PURPLE}☉ 4. Verifying the bundled Rust engine...${NC}"
# Verification only: this step used to overwrite src/core/bin/topo-core-<host>
# with a host `cargo build --release`, i.e. a glibc-dynamic binary in place of
# the musl-static one every other machine has to run. packaging/build-engine.sh
# is the only thing allowed to write there; here we just ask whether what is
# committed still matches topo-core/ (per topo-core/engine.stamp).
if ! OUT=$(packaging/build-engine.sh --verify 2>&1); then
echo -e "${RED}❌ Bundled Rust engine check failed:${NC}\n$OUT"
exit 1
fi
echo -e " ${GREEN}✓${NC} ${GRAY}src/core/bin/topo-core-* match topo-core/engine.stamp${NC}"
echo -e " ${GREEN}✓${NC} ${GRAY}Bundled Rust engine verification complete.${NC}\n"
echo -e "${PURPLE}☉ 5. Running ShellCheck...${NC}"
if ! OUT=$(find . -type f -name '*.sh' -exec shellcheck {} + 2>&1); then
echo -e "${RED}❌ ShellCheck failed:${NC}\n$OUT"
exit 1
fi
echo -e " ${GREEN}✓${NC} ${GRAY}Shell scripts validated${NC}"
echo -e " ${GREEN}✓${NC} ${GRAY}Shell script linting complete.${NC}\n"
echo -e "${PURPLE}☉ 6. Running Tests...${NC}"
if [ -t 1 ]; then echo -e " ${GRAY}↓ Running Python application tests (pytest)...${NC}"; fi
if ! OUT=$(pytest -q -p no:tach 2>&1); then
echo -e "${RED}❌ Python tests failed:${NC}\n$OUT"
exit 1
fi
if [ -t 1 ]; then printf "\033[1A\033[K"; fi
PY_COUNT=$(echo "$OUT" | grep -oE '[0-9]+ passed' | head -n 1)
echo -e " ${GREEN}✓${NC} ${GRAY}${PY_COUNT:-all passed} Python application tests (pytest)${NC}"
if [ -t 1 ]; then echo -e " ${GRAY}↓ Running Rust core engine tests (cargo test)...${NC}"; fi
if ! OUT=$(cargo test --quiet --manifest-path topo-core/Cargo.toml 2>&1); then
echo -e "${RED}❌ Rust engine tests failed:${NC}\n$OUT"
exit 1
fi
if [ -t 1 ]; then printf "\033[1A\033[K"; fi
RS_COUNT=$(printf '%s\n' "$OUT" | awk '
/test result: ok/ {
for (i = 1; i <= NF; i++) {
if ($(i + 1) == "passed;") {
total += $i
found = 1
}
}
}
END { if (found) print total " passed" }
')
echo -e " ${GREEN}✓${NC} ${GRAY}${RS_COUNT:-all passed} Rust core engine tests (cargo test)${NC}"
echo -e " ${GREEN}✓${NC} ${GRAY}All test suites passed successfully.${NC}\n"
echo -e " ✅${NC} All checks passed successfully! 🎉${NC}\n"