feat(feishu): 添加飞书入站事件inbox和混合数据库协调功能

- 实现飞书入站事件持久化inbox机制,支持状态管理、租约锁定和重试退避
- 添加混合数据库基线协调工具,确保平台PostgreSQL结构安全对齐
- 增加运行组件心跳检测和readiness就绪检查机制
- 实现app_ticket事件的安全轮换和验证处理
- 添加生产环境运行编排和fail-closed安全机制
- 支持webhook快速确认和长连接独立进程处理
- 完善个人数据擦除时的待处理事件清理功能
```
This commit is contained in:
2026-07-27 17:14:37 +08:00
parent d7db84571d
commit eb8267ed18
61 changed files with 8703 additions and 183 deletions

View File

@@ -21,6 +21,7 @@ from app.modules.ai_memory.models import AIMemoryEntry
from app.modules.audit.models import AuditLog
from app.modules.business.models import MarketWatchlist
from app.modules.feishu_users.constants import FeishuUserRole
from app.modules.feishu_users.identifiers import feishu_audit_identity_hash
from app.modules.feishu_users.models import (
FeishuAdminBootstrapTombstone,
FeishuUser,
@@ -175,6 +176,26 @@ def _seed_personal_data(db: Session, user: FeishuUser) -> None:
request_id=f"request-{user.code}",
)
)
db.add(
AuditLog(
actor=feishu_audit_identity_hash(
user.tenant_key,
user.open_id,
),
source="feishu",
action="webhook_event",
target_type="webhook",
target_id="sha256-event-evidence",
request_payload=json.dumps(
{
"tenant_key": "sha256-tenant-evidence",
"chat_id": "sha256-chat-evidence",
}
),
response_payload=json.dumps({"accepted": True}),
request_id=f"accepted-{user.code}",
)
)
db.commit()
@@ -224,6 +245,10 @@ def test_confirm_erases_all_personal_data_and_anonymizes_audit(
tenant_key = user.tenant_key
open_id = user.open_id
identifiers = (user.code, user.open_id, user.union_id, user.user_id)
accepted_actor = feishu_audit_identity_hash(
user.tenant_key,
user.open_id,
)
principal = FeishuPrincipal.from_user(user)
service = FeishuPersonalDataService(db)
@@ -270,6 +295,7 @@ def test_confirm_erases_all_personal_data_and_anonymizes_audit(
for log in logs
)
assert all(identifier not in serialized_logs for identifier in identifiers)
assert accepted_actor not in serialized_logs
final_log = db.execute(
select(AuditLog).where(AuditLog.action == PERSONAL_DATA_ERASURE_ACTION)
).scalar_one()
@@ -294,6 +320,18 @@ def test_confirm_erases_all_personal_data_and_anonymizes_audit(
assert anonymized_history.request_id is None
assert anonymized_history.status == "success"
anonymized_acceptance = db.execute(
select(AuditLog).where(
AuditLog.action == "webhook_event",
AuditLog.actor == result.anonymous_id,
)
).scalar_one()
assert anonymized_acceptance.target_type is None
assert anonymized_acceptance.target_id is None
assert anonymized_acceptance.request_payload is None
assert anonymized_acceptance.response_payload is None
assert anonymized_acceptance.request_id is None
recreated = FeishuIdentityService(db).resolve_or_register(
tenant_key=tenant_key,
open_id=open_id,