From bf7f5fa03c75752f237735ada53e808e3d19a397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E7=AB=A0=E6=B5=A9?= Date: Mon, 2 Nov 2026 18:56:55 +0800 Subject: [PATCH] =?UTF-8?q?test(library):=20P1=20=E7=94=A8=E5=8F=AA?= =?UTF-8?q?=E8=AF=BB=E5=8F=AF=E7=94=A8=E6=80=A7=E6=8A=95=E5=BD=B1=E6=A0=B8?= =?UTF-8?q?=E5=AF=B9=E6=81=A2=E5=A4=8D=E5=90=8E=E4=B8=9A=E5=8A=A1=E5=87=86?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为什么:POST /api/v1/library/restores 是"新建恢复作业"的入口,恢复后重复 POST 会制造第二次恢复;原任务的"同一受保护入口 409→200"应映射到零写副作用的 GET /library/restore-availability:held 时报维护原因且 allowed=false,恢复后 维护原因消失。不重复 POST,也不放宽权限。 --- .../formal_maintenance_recovery_r38_test.go | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/internal/releaseadapter/v071/formal_maintenance_recovery_r38_test.go b/internal/releaseadapter/v071/formal_maintenance_recovery_r38_test.go index 8046c88..2b153a3 100644 --- a/internal/releaseadapter/v071/formal_maintenance_recovery_r38_test.go +++ b/internal/releaseadapter/v071/formal_maintenance_recovery_r38_test.go @@ -1365,6 +1365,21 @@ UPDATE knowledge_bases SET embedding_model_id='r38-model',vector_store_id='r38-v t.Fatalf("entry while held => %d %v, want 409 library_target_in_maintenance", code, blocked) } save("16-entry-409.json", map[string]any{"http": code, "body": blocked}) + // POST /library/restores 是"新建恢复作业"的入口:恢复后再 POST 会创建新作业, + // 不能为凑 409→200 而制造第二次恢复。同一业务准入改用零写副作用的 + // GET /library/restore-availability(页面判断"这份快照现在能不能恢复"的投影)。 + availabilityPath := "/api/v1/library/restore-availability?scope=internal&snapshot_id=" + backupID + code, availabilityHeld := api.do(t, http.MethodGet, availabilityPath, nil) + if code != http.StatusOK { + t.Fatalf("restore availability while held => %d %v", code, availabilityHeld) + } + heldReasons, _ := availabilityHeld["reasons"].([]any) + heldMaintenanceReason := r38HasReason(heldReasons, "维护") + if availabilityHeld["allowed"] != false || !heldMaintenanceReason { + t.Fatalf("availability while held = %v", availabilityHeld) + } + save("16a-availability-held.json", map[string]any{"http": code, "body": availabilityHeld, + "maintenance_reason": heldMaintenanceReason}) code, mismatch := api.do(t, http.MethodPost, "/api/v1/library/maintenance/recover", map[string]any{"scope": "internal", "window_job_id": "some-other-window"}) if code != http.StatusConflict || mismatch["code"] != "library_window_mismatch" { @@ -1493,6 +1508,17 @@ FROM library_index_restore_dispatch WHERE index_name=$1 AND document_id='chunk-t } save("21-ingress.json", map[string]any{"ingress": os.Getenv("KG_R38_INGRESS"), "http": 200, "open": true, "maintenance_http": openMaintenance}) + code, availabilityRecovered := api.do(t, http.MethodGet, availabilityPath, nil) + if code != http.StatusOK { + t.Fatalf("restore availability after recovery => %d %v", code, availabilityRecovered) + } + recoveredReasons, _ := availabilityRecovered["reasons"].([]any) + recoveredMaintenanceReason := r38HasReason(recoveredReasons, "维护") + if recoveredMaintenanceReason { + t.Fatalf("availability still reports maintenance after recovery: %v", availabilityRecovered) + } + save("21a-availability-recovered.json", map[string]any{"http": code, "body": availabilityRecovered, + "maintenance_reason": recoveredMaintenanceReason, "post_entry": "not repeated: POST /restores creates a new job"}) // ---------- 5) 三个真实存储的全量恢复 ---------- afterPG := universeDump(t, fx.pool) @@ -1855,11 +1881,13 @@ FROM library_index_restore_dispatch WHERE index_name=$1 AND document_id='chunk-t "pg_restore_branch": pgBranch, "pg_early_restore_branch": earlyBranch, "window_job": job.ID, "publish_queue": queueID, "recovery_queue": recoveryQueueID, "backup": backupID, "scope": "internal", "instance": cfg.LibraryTargetInstance, - "held": map[string]any{"journal": "held/restore_blocked", "maintenance": "needs_restore", "entry_http": 409}, + "held": map[string]any{"journal": "held/restore_blocked", "maintenance": "needs_restore", "entry_http": 409, + "availability_maintenance_reason": true}, "recovered": map[string]any{"journal": "recovered", "maintenance_released": true, "entry_http": 200, "pg_rows_restored": true, "object_versions_restored": true, "es_source_restored": true, "receipts": len(receipts), "deliveries": len(deliveries), "recover_operations": recoverOps, - "object_delete_markers_equal": true}, + "object_delete_markers_equal": true, "availability_maintenance_reason": recoveredMaintenanceReason, + "availability_allowed": availabilityRecovered["allowed"], "availability_reasons": recoveredReasons}, "es_refusals": refused, "object_refusals": objectRefused, "object_forwarded_mutations": objectForwarded, "publish_entry": "store.CreateLibraryDispatch (publish API entry not proven)", "object_wire_events_after": len(objectEventsAfter), @@ -1877,6 +1905,15 @@ FROM library_index_restore_dispatch WHERE index_name=$1 AND document_id='chunk-t // ---------- 观察辅助 ---------- +func r38HasReason(reasons []any, needle string) bool { + for _, reason := range reasons { + if text, ok := reason.(string); ok && strings.Contains(text, needle) { + return true + } + } + return false +} + func objectInventoryR38(t *testing.T, ctx context.Context, fx *writeSetFixture) *s3.ListObjectVersionsOutput { t.Helper() out := &s3.ListObjectVersionsOutput{}