0df0e3cb1e
发布作业详情在目标仍被维护时返回 maintenance(持有作业、入口状态、目标身份、 备注、是否已释放)与 next_step;作业本身继续带 operation_id/attempt_epoch/预备份/ 目标快照与错误说明,能定位到"哪个意图、哪份基线、哪个目标"。 不提供强制成功/强制开门入口:缺归属证据的收尾保持维护锁定,按预备份与校验证据 人工核验后再放行(用户已接受的可用性边界)。页面同时提示发布/恢复后旧分页游标 失效、需要刷新重新分页。
76 lines
2.9 KiB
Go
76 lines
2.9 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"knowledge-governance/internal/governance"
|
|
postgresstore "knowledge-governance/internal/platform/postgres"
|
|
)
|
|
|
|
type r13HeldDetailStore struct {
|
|
fakeLibraryStore
|
|
maintenance *postgresstore.LibraryMaintenance
|
|
job governance.LibraryJob
|
|
}
|
|
|
|
func (s *r13HeldDetailStore) LibraryJob(_ context.Context, id string) (governance.LibraryJob, error) {
|
|
job := s.job
|
|
job.ID = id
|
|
return job, nil
|
|
}
|
|
|
|
func (s *r13HeldDetailStore) LibraryMaintenanceOf(context.Context, string) (*postgresstore.LibraryMaintenance, error) {
|
|
return s.maintenance, nil
|
|
}
|
|
|
|
// 已接受的边界:缺归属证据的作业停在 held,页面/接口必须给出可核对的 job/operation/目标
|
|
// 与阻断原因,并且**不能**提供"强制成功/强制开门"的动作。
|
|
func TestR13HeldJobDetailExplainsManualRecovery(t *testing.T) {
|
|
store := &r13HeldDetailStore{maintenance: &postgresstore.LibraryMaintenance{
|
|
Scope: "internal", OwnerJobID: "job-held", State: "needs_restore",
|
|
IngressState: "open", TargetIdentity: "scope=internal", Note: "内容已验证,但收尾未完成",
|
|
Services: []string{"app"},
|
|
}}
|
|
store.job = governance.LibraryJob{
|
|
Scope: "internal", Kind: governance.LibraryJobSync, State: governance.LibraryJobFailed,
|
|
Stage: "finalize", OperationID: "op-r13", AttemptEpoch: 2,
|
|
SnapshotID: "backup-r13", TargetSnapshotID: "target-r13",
|
|
Error: "内容已验证,但收尾未完成", Recovery: "预备份保留;按归档人工核验",
|
|
}
|
|
request := httptest.NewRequest(http.MethodGet, "/api/v1/library/jobs/job-held", nil)
|
|
request.SetPathValue("id", "job-held")
|
|
recorder := httptest.NewRecorder()
|
|
libraryJobDetailHandler(recorder, request, Config{Store: store})
|
|
if recorder.Code != http.StatusOK {
|
|
t.Fatalf("status = %d body=%s", recorder.Code, recorder.Body.String())
|
|
}
|
|
var body map[string]any
|
|
if err := json.Unmarshal(recorder.Body.Bytes(), &body); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
job, _ := body["job"].(map[string]any)
|
|
if job["operation_id"] != "op-r13" || job["attempt_epoch"] != float64(2) ||
|
|
job["snapshot_id"] != "backup-r13" || job["target_snapshot_id"] != "target-r13" {
|
|
t.Fatalf("作业身份/证据不完整:%v", job)
|
|
}
|
|
maintenance, _ := body["maintenance"].(map[string]any)
|
|
if maintenance["held"] != true || maintenance["owner_is_job"] != true || maintenance["state"] != "needs_restore" {
|
|
t.Fatalf("维护状态没有暴露:%v", maintenance)
|
|
}
|
|
step, _ := body["next_step"].(string)
|
|
if !strings.Contains(step, "维护") || !strings.Contains(step, "人工") {
|
|
t.Fatalf("下一步没有指向人工核验:%q", step)
|
|
}
|
|
raw := strings.ToLower(recorder.Body.String())
|
|
for _, banned := range []string{"force_success", "force-open", "force_open", "ignore_unknown", "skip_verify"} {
|
|
if strings.Contains(raw, banned) {
|
|
t.Fatalf("诊断接口出现了强制动作:%s", banned)
|
|
}
|
|
}
|
|
}
|