Files
fidc-backtest-engine/scripts/verify-runtime-risk-contracts.sh
T
2026-07-05 19:35:39 +08:00

62 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT_DIR"
PYTHON_BIN="${PYTHON_BIN:-python3}"
fail() {
local message="$1"
local details="${2:-}"
printf '[FAIL] %s\n' "$message" >&2
if [[ -n "$details" ]]; then
printf '%s\n' "$details" >&2
fi
exit 1
}
run_core_test() {
local filter="$1"
local tmp
tmp="$(mktemp)"
printf '[INFO] cargo test -p fidc-core %s\n' "$filter"
if cargo test -p fidc-core "$filter" -- --nocapture 2>&1 | tee "$tmp"; then
local passed_count
passed_count="$(
"$PYTHON_BIN" - "$tmp" <<'PY'
import re
import sys
count = 0
for line in open(sys.argv[1], encoding="utf-8", errors="replace"):
match = re.search(r"test result: ok\. (\d+) passed;", line)
if match:
count += int(match.group(1))
print(count)
PY
)"
rm -f "$tmp"
if [[ "$passed_count" -le 0 ]]; then
fail "cargo test filter matched 0 tests: package=fidc-core filter=${filter}"
fi
return 0
fi
local output
output="$(cat "$tmp")"
rm -f "$tmp"
fail "cargo test failed: package=fidc-core filter=${filter}" "$output"
}
run_core_test eligible_universe_does_not_require_candidate_risk_state_when_selection_risk_is_disabled
run_core_test next_bar_open_eligible_universe_helper_does_not_block_on_decision_day_risk
run_core_test platform_next_open_selection_records_risk_diagnostics_without_filtering
run_core_test next_open_buy_risk_uses_execution_date_not_signal_date
run_core_test next_open_buy_limit_risk_uses_open_not_close
run_core_test next_open_sell_risk_uses_execution_date_not_signal_date
run_core_test next_open_sell_limit_risk_uses_open_not_close
run_core_test next_bar_open_sell_respects_allow_sell_policy_on_execution_day
run_core_test volume_limit_uses_floor_for_odd_lot_sell
run_core_test configurable_upper_limit_buy_filter_can_be_disabled
printf '[OK] fidc-backtest-engine runtime risk contracts passed\n'