HEL-282: 写库路径事务提交与审计留痕自查修复
同类未提交即 close 回滚、业务与审计拆成两笔事务的路径一并收进可嵌套事务边界。 Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
co-authored by
Cursor
multica-agent
parent
9e0e4a103a
commit
9193a3fce0
@@ -349,6 +349,66 @@ class CoverageGapTests(CalculationBase):
|
||||
).fetchone()
|
||||
self.assertEqual("closed_attested", closed["status"])
|
||||
|
||||
def test_attestation_and_audit_survive_connection_close(self) -> None:
|
||||
"""HEL-282: attestation writes used to skip the change log; review also
|
||||
nested-committed coverage recalculation before the overlap close."""
|
||||
from bank_importer.db import connect as db_connect
|
||||
|
||||
self.add_confirmed_row(
|
||||
self.company_a,
|
||||
account_id=self.account_a["id"],
|
||||
own_account="6222000000000001",
|
||||
at="2026-06-21T10:00:00",
|
||||
)
|
||||
calculation.recalculate_coverage_gaps(self.connection)
|
||||
gap = self.connection.execute(
|
||||
"SELECT * FROM coverage_gaps WHERE status = 'open'"
|
||||
).fetchone()
|
||||
cashier_id = auth.create_user(
|
||||
self.connection, "cashier-close", "CashierA123", "company", self.company_a
|
||||
)
|
||||
cashier = self.connection.execute(
|
||||
"SELECT * FROM users WHERE id = ?", (cashier_id,)
|
||||
).fetchone()
|
||||
att = calculation.submit_no_business_attestation(
|
||||
self.connection,
|
||||
company_id=self.company_a,
|
||||
bank_account_id=self.account_a["id"],
|
||||
gap_start=gap["gap_start"],
|
||||
gap_end=gap["gap_end"],
|
||||
reason="当日账户无资金往来",
|
||||
evidence=None,
|
||||
actor=cashier,
|
||||
)
|
||||
calculation.review_no_business_attestation(
|
||||
self.connection, att["id"], "approve", "审核通过", self.admin
|
||||
)
|
||||
att_id = att["id"]
|
||||
self.connection.close()
|
||||
fresh = db_connect(self.db_path)
|
||||
try:
|
||||
row = fresh.execute(
|
||||
"SELECT status FROM no_business_attestations WHERE id = ?", (att_id,)
|
||||
).fetchone()
|
||||
actions = [
|
||||
item["action"]
|
||||
for item in fresh.execute(
|
||||
"""
|
||||
SELECT action FROM audit_log
|
||||
WHERE action LIKE 'attestation_%'
|
||||
ORDER BY id
|
||||
"""
|
||||
).fetchall()
|
||||
]
|
||||
closed = fresh.execute(
|
||||
"SELECT status FROM coverage_gaps WHERE id = ?", (gap["id"],)
|
||||
).fetchone()
|
||||
finally:
|
||||
fresh.close()
|
||||
self.assertEqual("approved", row["status"])
|
||||
self.assertEqual(["attestation_submit", "attestation_approve"], actions)
|
||||
self.assertEqual("closed_attested", closed["status"])
|
||||
|
||||
|
||||
class BalanceBasisTests(CalculationBase):
|
||||
def setUp(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user