# LSFX Mock 随机命中规则后端验证记录

## 执行命令

```bash
cd lsfx-mock-server
python3 -m pytest tests/test_file_service.py -k "rule_hit_plan or persist_rule_hit_plan" -v
python3 -m pytest tests/test_statement_service.py -k "rule_plan_should_only_include or withdraw_cnt_samples" -v
python3 -m pytest tests/test_statement_service.py -k "follow_rule_hit_plan or fixed_total_count_200 or cached_result" -v
python3 -m pytest tests/integration/test_full_workflow.py -k "same_rule_subset or share_same_primary_binding" -v
python3 -m pytest tests/test_file_service.py tests/test_statement_service.py tests/test_api.py tests/integration/test_full_workflow.py -v

cd ..
bin/mysql_utf8_exec.sh sql/migration/2026-03-20-lsfx-mock-random-hit-rule-purchase-baseline.sql
python3 - <<'PY'
import pymysql
from pathlib import Path
import re

text = Path('ruoyi-admin/src/main/resources/application-dev.yml').read_text(encoding='utf-8')
match = re.search(r"url:\s*jdbc:mysql://(?P<host>[^:/?#]+):(?P<port>\d+)/(?P<db>[^?\n]+).*?\n\s*username:\s*(?P<user>[^\n]+)\n\s*password:\s*(?P<pwd>[^\n]+)", text, re.S)
conn = pymysql.connect(
    host=match.group('host'),
    port=int(match.group('port')),
    user=match.group('user').strip(),
    password=match.group('pwd').strip(),
    database=match.group('db').strip(),
    charset='utf8mb4',
    cursorclass=pymysql.cursors.DictCursor,
)
with conn, conn.cursor() as cursor:
    cursor.execute("""
        SELECT COUNT(1) AS cnt
        FROM ccdi_purchase_transaction
        WHERE purchase_id = 'LSFXMOCKPUR001'
          AND actual_amount > 100000
    """)
    print(cursor.fetchone()['cnt'])
PY
```

## 执行时间与结果
- 2026-03-20 14:50 CST 完成目标回归：
  `python3 -m pytest tests/test_file_service.py tests/test_statement_service.py tests/test_api.py tests/integration/test_full_workflow.py -v`
- 回归结果：`38 passed, 20 warnings in 4.20s`
- warnings 为现有 `pydantic` 与 `httpx` 弃用提示，本次改动未新增失败或 error。

## SQL 基线脚本执行结果
- 执行命令：`bin/mysql_utf8_exec.sh sql/migration/2026-03-20-lsfx-mock-random-hit-rule-purchase-baseline.sql`
- 执行结果：脚本执行成功，无报错输出。
- 脚本内容采用“先删后插”的幂等方式，避免重复执行造成脏数据。

## 采购基线查询结果
- 执行前查询：
  `SELECT COUNT(1) FROM ccdi_purchase_transaction WHERE purchase_id = 'LSFXMOCKPUR001'`
  返回 `0`
- 执行后查询：
  `SELECT purchase_id, actual_amount, supplier_name FROM ccdi_purchase_transaction WHERE purchase_id = 'LSFXMOCKPUR001'`
  返回：
  - `purchase_id = LSFXMOCKPUR001`
  - `actual_amount = 186000.00`
  - `supplier_name = 兰溪市联调供应链有限公司`
- 最终门槛校验：
  `SELECT COUNT(1) ... WHERE purchase_id = 'LSFXMOCKPUR001' AND actual_amount > 100000`
  返回 `1`

## 是否发现回归
- 未发现本次改动引入的功能回归。
- `FileService` 的规则命中计划生成、`statement_rule_samples.py` 的按规则子集装配、`StatementService` 的缓存稳定性、端到端接口链路均已通过验证。
- 本次验证未启动额外前后端常驻进程，因此无需执行进程清理。
