mihomo-kit/tools/test.sh
Sam Latsin 2557a9aa49 mihomo-kit: config kit for mihomo on nikki and FlClash
Templates + router script + browser constructor that build mihomo
profiles (router home/street, mobile) with optional OpenVPN (TOTP)
and Tailscale, one-command installer and maintenance commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 00:57:28 +03:00

32 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
# Render every fixture with router/mihomo-kit.sh and web/engine.js, diff them,
# and (if MIHOMO points to a mihomo binary) validate with `mihomo -t`.
# tools/test.sh parity only
# MIHOMO=/path/to/mihomo tools/test.sh
set -u
cd "$(dirname "$0")/.."
out=$(mktemp -d)
fail=0
for f in tests/fixtures/*.env; do
n=$(basename "$f" .env)
[ "$n" = common ] && continue
sh router/mihomo-kit.sh render tests/fixtures/common.env "$f" > "$out/$n.sh.yaml" || { echo "FAIL $n: sh render"; fail=1; continue; }
sh -c 'set -a; . tests/fixtures/common.env; . "$1"; node tools/render.js' _ "$f" > "$out/$n.js.yaml" || { echo "FAIL $n: js render"; fail=1; continue; }
if ! diff -u "$out/$n.sh.yaml" "$out/$n.js.yaml"; then
echo "FAIL $n: sh and js differ"
fail=1
continue
fi
if [ -n "${MIHOMO:-}" ]; then
mkdir -p "$out/home"
# geosite needs a download: drop those rules for the syntax check
sed '/GEOSITE/d; /rule-set:ru-inside/d' "$out/$n.sh.yaml" > "$out/home/$n.yaml"
if ! "$MIHOMO" -t -d "$out/home" -f "$out/home/$n.yaml" >"$out/$n.log" 2>&1; then
echo "FAIL $n: mihomo -t"; tail -3 "$out/$n.log"; fail=1; continue
fi
fi
echo "ok $n"
done
rm -rf "$out"
exit $fail