From 82ed5b3e0bd1ac952b376c574f7d1b5dec89b994 Mon Sep 17 00:00:00 2001 From: boris Date: Sun, 5 Jul 2026 19:35:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EFIDC=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E6=97=B6=E9=A3=8E=E6=8E=A7=E5=90=88=E5=90=8C=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/verify-runtime-risk-contracts.sh | 61 ++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 scripts/verify-runtime-risk-contracts.sh diff --git a/scripts/verify-runtime-risk-contracts.sh b/scripts/verify-runtime-risk-contracts.sh new file mode 100755 index 0000000..f476645 --- /dev/null +++ b/scripts/verify-runtime-risk-contracts.sh @@ -0,0 +1,61 @@ +#!/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'