fix(reconciliation): 收紧确认页与并发处置
为什么:净室评审发现两处可复发风险——扫描在实例返回小于请求页时可能提前结束;并发重复处置可能各写一条审计。 做什么:扫描以 total 为准继续翻页(total 未知才按短页结束);处置前对 finding 行 FOR UPDATE 并只接受 open;R4 sha256 统一 trim。 验证:go test ./internal/reconciliation ./internal/platform/postgres;make verify 全绿。
This commit is contained in:
@@ -45,10 +45,18 @@ func (s *Service) scanKnowledge(ctx context.Context, kbID string) ([]weknora.Kno
|
||||
out = append(out, item)
|
||||
added++
|
||||
}
|
||||
if len(items) == 0 || added == 0 || len(items) < scanPageSize {
|
||||
if len(items) == 0 || added == 0 {
|
||||
break
|
||||
}
|
||||
if total > 0 && int64(len(seen)) >= total {
|
||||
if total > 0 {
|
||||
if int64(len(seen)) >= total {
|
||||
break
|
||||
}
|
||||
// Keep paging even if the instance returned a smaller page than
|
||||
// requested; only the reported total ends the scan.
|
||||
continue
|
||||
}
|
||||
if len(items) < scanPageSize {
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -383,8 +391,8 @@ func (s *Service) buildFindings(ctx context.Context, run governance.Reconciliati
|
||||
}
|
||||
|
||||
func (s *Service) r4Finding(row governance.ReconciliationLedgerRow, item weknora.Knowledge, normalized string) (governance.ReconciliationFinding, bool) {
|
||||
declared := strings.ToLower(metadataString(item.Metadata, "content_sha256"))
|
||||
ledgerSHA := strings.ToLower(row.SHA256)
|
||||
declared := strings.ToLower(strings.TrimSpace(metadataString(item.Metadata, "content_sha256")))
|
||||
ledgerSHA := strings.ToLower(strings.TrimSpace(row.SHA256))
|
||||
uploadMD5 := normalizeMD5(row.UploadMD5)
|
||||
fileMD5 := normalizeMD5(item.FileHash)
|
||||
evidence := "none"
|
||||
|
||||
Reference in New Issue
Block a user