#!/bin/bash set -uxo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" cd /workspace git config --global --add safe.directory /workspace mkdir -p /logs/verifier git checkout 8dcabe8aeec49304e32a513c551ff1256163b3c4 -- tests/test_helpers.py || true git apply --verbose --reject - <<'EOF_R2E_TEST_PATCH' diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 8adb91f..56e334f 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -119,6 +119,39 @@ class TestTransactionType: Decimal("4085.662"), ) == (TransactionType.GIFT_IN, None) + def test_stp(self): + # Systematic Transfer Plan legs must classify as SWITCH_OUT (source, + # negative units) / SWITCH_IN (target, positive units) regardless of + # how the RTA words them. CAMS spells it out ("Systematic Transfer + # Plan Switch …", already caught by the "switch" keyword); KFintech + # prints it letter-spaced as "S T P In/Out", which previously fell + # through to PURCHASE / REDEMPTION. (discussion #141) + assert get_transaction_type( + "Systematic Transfer Plan Switch Out - To SBI Small Cap Fund Dir Growth-", + Decimal("-5.938"), + ) == (TransactionType.SWITCH_OUT, None) + assert get_transaction_type( + "Systematic Transfer Plan Switch In - From SBI Liquid Fund Direct Growth-", + Decimal("126.972"), + ) == (TransactionType.SWITCH_IN, None) + # KFintech, letter-spaced. + assert get_transaction_type( + "S T P Out (To Axis Mid Cap Fund - Direct Growth F.No:91064932471)", + Decimal("-24.933"), + ) == (TransactionType.SWITCH_OUT, None) + assert get_transaction_type( + "S T P In (From Axis Liquid Fund - Direct Growth F.No:91064932471)", + Decimal("571.574"), + ) == (TransactionType.SWITCH_IN, None) + + def test_sip_not_misread_as_stp(self): + # A genuine SIP must stay PURCHASE_SIP — the STP detection must not + # swallow "Systematic Investment" or the "SIP" token. + assert get_transaction_type( + "Systematic Investment-Instalment No 12", + Decimal("10"), + ) == (TransactionType.PURCHASE_SIP, None) + def test_dividends(self): assert get_transaction_type( "IDCW Reinvestment @ Rs.2.00 per unit", EOF_R2E_TEST_PATCH R2E_APPLY_RC=$? if [ "$R2E_APPLY_RC" -ne 0 ]; then echo "0.000000" > /logs/verifier/reward.txt printf '%s' '{"reward": 0.0, "resolved": false, "parse_status": "test_patch_apply_failed"}' > /logs/verifier/reward-details.json echo "R2E: test_patch failed to apply (rc=$R2E_APPLY_RC) — failing closed" >&2 exit 0 fi ( python -m pytest -v tests/test_helpers.py ) > /logs/verifier/test_output.log 2>&1 TEST_EXIT_CODE=$? cat /logs/verifier/test_output.log python3 "$SCRIPT_DIR/verifier.py" --log /logs/verifier/test_output.log --f2p "$SCRIPT_DIR/f2p.json" --p2p "$SCRIPT_DIR/p2p.json" --test-cmds 'python -m pytest -v tests/test_helpers.py' --exit-code "$TEST_EXIT_CODE" --out-dir /logs/verifier || { [ "$TEST_EXIT_CODE" -eq 0 ] && echo "1.0" > /logs/verifier/reward.txt || echo "0.0" > /logs/verifier/reward.txt; } git checkout 8dcabe8aeec49304e32a513c551ff1256163b3c4 -- tests/test_helpers.py || true exit 0