fix(reconciliation): 修复僵死回收 SQL 并补齐验收缺口
build / build (push) Has been cancelled

- 回收 SQL 占位符改为 $1/$2,消除 pgx 扩展协议 42P18(手动/定时对账 500)
- 直接写入 finding 时归一空 confirmation_state,避免 23514
- 修正 R6/overview 同谓词用例夹具,两条台账各自持有 source version
- 页面顶部统一服务与队列单行状态条,删除 Embedding/LLM 常量卡
- 平台阶段筛选合并为「WeKnora 处理中」,后端支持 stage=weknora
- weknora_url 由测试 WeKnora 源构造,详情与 503 提供跳转链接
- 补 1000/页线上查询、R8 合法收养、weknora 阶段筛选用例
This commit is contained in:
Zhero & Rin
2026-12-01 14:22:06 +08:00
committed by 姚章浩
parent 629694546c
commit e855261b4d
19 changed files with 211 additions and 143 deletions
+1 -1
View File
@@ -145,7 +145,7 @@ const monitorTasksCTE = `WITH history_publications AS (
SELECT * FROM projected WHERE ($1='' OR strpos(lower(title || ' ' || path),lower($1))>0)
AND ($2='' OR source_id=$2) AND ($3='' OR target_scope=$3) AND ($4='' OR action=$4)
AND ($5='' OR ($5='active' AND status NOT IN ('completed','cancelled')) OR status=$5)
AND ($6='' OR stage=$6) AND ($7='' OR id=$7) AND ($10='' OR target_kb=$10)
AND ($6='' OR stage=$6 OR ($6='weknora' AND stage IN ('parsing','indexing'))) AND ($7='' OR id=$7) AND ($10='' OR target_kb=$10)
AND ($11='' OR updated_at>=NULLIF($11,'')::timestamptz) AND ($12='' OR updated_at<=NULLIF($12,'')::timestamptz)
) `
@@ -97,8 +97,8 @@ func (s *Store) ReapStaleReconciliationRuns(ctx context.Context, now time.Time,
return 0, nil
}
tag, err := s.db.Exec(ctx, `UPDATE reconciliation_runs
SET state='failed',finished_at=$2,error_code='stale_timeout'
WHERE state='running' AND started_at < $3`, now, now.Add(-threshold))
SET state='failed',finished_at=$1,error_code='stale_timeout'
WHERE state='running' AND started_at < $2`, now, now.Add(-threshold))
if err != nil {
return 0, fmt.Errorf("reap stale reconciliation runs: %w", err)
}
@@ -222,6 +222,13 @@ WHERE id=$1 AND state='running'`, run.ID, run.FinishedAt, run.LedgerCount, run.K
return ErrReconciliationNotRunning
}
for _, finding := range findings {
// The column default only applies when the insert omits the column; the
// service always fills it, but direct callers may pass "" and must not
// violate the check constraint.
confirmation := finding.ConfirmationState
if confirmation == "" {
confirmation = "confirmed"
}
if _, err := tx.Exec(ctx, `INSERT INTO reconciliation_findings
(id,run_id,finding_type,publication_id,knowledge_id,title,path,source,target_scope,
ledger_state,weknora_parse_status,normalized_state,ledger_sha256,declared_sha256,
@@ -231,7 +238,7 @@ VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,'open'
finding.ID, finding.RunID, finding.Type, finding.PublicationID, finding.DocumentID,
finding.Title, finding.Path, finding.Source, finding.TargetScope, finding.LedgerState,
finding.WeKnoraParseState, finding.NormalizedState, finding.LedgerSHA256, finding.DeclaredSHA256,
finding.WeKnoraFileMD5, finding.EvidenceLevel, finding.ConfirmationState, finding.Detail,
finding.WeKnoraFileMD5, finding.EvidenceLevel, confirmation, finding.Detail,
finding.SuggestedAction, finding.WeKnoraURL, run.FinishedAt); err != nil {
return fmt.Errorf("insert reconciliation finding: %w", err)
}
+20
View File
@@ -336,6 +336,26 @@ func TestClientProvidesPaginatedInventoryChunkAndScopedSearchReads(t *testing.T)
}
}
// Acceptance #16: the reconciliation scan must be one 1000-per-page read, and
// the wire query is the evidence — not just the constant passed to the interface.
func TestListKnowledgeSendsScanPageSizeOnTheWire(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Query().Get("page") != "1" || r.URL.Query().Get("page_size") != "1000" {
t.Fatalf("knowledge list query = %s", r.URL.RawQuery)
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"success":true,"data":[],"total":0,"page":1,"page_size":1000}`))
}))
defer server.Close()
client, err := NewClient(ClientConfig{BaseURL: server.URL, APIKey: "test-api-key", Timeout: time.Second})
if err != nil {
t.Fatal(err)
}
if _, _, err := client.ListKnowledge(context.Background(), "kb-1", 1, 1000); err != nil {
t.Fatal(err)
}
}
func TestClientRejectsRedirectWithoutForwardingAPIKey(t *testing.T) {
var targetHits atomic.Int32
target := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {