Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 58d0483d44 | |||
| bb64c32654 |
@@ -29,6 +29,7 @@
|
||||
/release-diag
|
||||
/worker
|
||||
/libraryctl
|
||||
/libraryagent
|
||||
/apply_s5_patch.py
|
||||
/tmp_*
|
||||
.style-backup-*/
|
||||
|
||||
@@ -1,5 +1,38 @@
|
||||
# Changelog
|
||||
|
||||
## 开发快照 snapshot/v0.1.113 - 2026-10-28
|
||||
|
||||
### Changed
|
||||
|
||||
- 发布管理按已确认稿重做:顶部只保留「对内知识库 / 对外知识库」两个页签,切换后只渲染选中库的一个作业区,不再并排两张巨型数据卡。
|
||||
- 同步前布局回到原稿:生产当前 → 拟发布版本行、新增/更新/删除文档与 Wiki 完整快照、准备清单(文档解析与索引、Wiki、数据完整性)、右上「版本与快照 / 启动同步」、下方左「本次变更」右「生产保护与恢复」、底部五段作业阶段。
|
||||
- 同步中布局:顶部作业阶段/版本/已用时,中间四类数据卡(数据库、原文件、索引、Wiki),底部「同步明细」与异常说明;没有真实总量与完成量的项目只显示状态,不编造百分比。
|
||||
- 「版本与快照」改为右侧抽屉:按选中库列出全部已封存记录,区分测试封存与生产生效/备份,展开看到文档/索引/资源/Wiki 分项数量、字节与逐项摘要;恢复入口在有真实恢复演练前保持禁用并说明。
|
||||
- 存储口径从发布主页移到「系统设置 → 存储管理」只读区(跨版本去重内容、blob 表观/分配、未引用、清单),保留策略/依赖保护/清理预览标未接线,自动清理保持关闭。
|
||||
- 生产段(当前版本、变更差异、预备份、同步、生产验证)没有真实数据的一律显示「未接入 / 尚无记录」;「启动同步」保持禁用并写明原因,不把发起封存冒充启动同步。
|
||||
|
||||
### Removed
|
||||
|
||||
- 主页面上的研发口径文案(A04/A06、schema、SHA、内部表名等)移入必要的分项详情。
|
||||
|
||||
## 开发快照 snapshot/v0.1.112 - 2026-10-28
|
||||
|
||||
### Changed
|
||||
|
||||
- 发布管理改为一版可操作的整库视图:只给「对内 / 对外」两个目标,把整库版本页的封存信息、完整性结果、分项数量/字节/摘要、封存作业状态与归档存储口径并入同一页;链路按真实能力标注「封存已接通、生产预备份未接线、同步未授权、校验/恢复未接线」,禁用项写明原因,不用假进度。
|
||||
- 「整库版本」独立导航并入发布管理(不再保留第三个相近入口);文档级旧流程折叠保留在页底,并明确单篇文档发布成功不等于整库发布成功。
|
||||
|
||||
### Fixed
|
||||
|
||||
- R4:封存子进程不再被默认 SIGKILL。超时/取消先发 SIGTERM 并给宽限期(`StopGrace`),`libraryctl` 把 SIGTERM 转成上下文取消,让停机窗口走恢复路径;任何失败的封存/恢复操作之后 agent 都会再执行一次有界的 `recover`,恢复失败则进入降级状态、阻断后续封存并给出原因(`recover`/`status` 仍可用);agent 启动时先恢复上次遗留的停机窗口,关闭时等待在飞操作完成其恢复责任。
|
||||
- R5:同一作业号换范围不再被回显成新范围。接口以已存 payload 为准,范围不一致返回 409(`library_capture_scope_conflict`)且不入新队;相同请求重放返回真实 `reused`/存储范围。
|
||||
- R6:封存作业列表改为按类型查询(`ListByType`),不再先取全局 200 条再过滤;存储不支持按类型查询时明确返回不可用,页面不据此判断空闲。
|
||||
|
||||
### Added
|
||||
|
||||
- `ListByType` 作用域查询与测试;封存闸口单测(未接线 503、非法 400、范围冲突 409、重放回显)。
|
||||
- 发布管理新增 6 条渲染测试(两个目标、真实数量、链路禁用原因、权限/未接线分支、作业态、存储口径)。
|
||||
|
||||
## 开发快照 snapshot/v0.1.111 - 2026-10-28
|
||||
|
||||
### Added
|
||||
|
||||
@@ -23,9 +23,11 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
@@ -67,7 +69,12 @@ func main() {
|
||||
os.Exit(2)
|
||||
}
|
||||
_ = rest
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
|
||||
// SIGTERM must not kill this process mid-window: the capture path restores the
|
||||
// source writers through a cancelled-context recovery, so the signal is turned
|
||||
// into a context cancellation and the process exits only after that cleanup.
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
ctx, cancel := context.WithTimeout(ctx, 30*time.Minute)
|
||||
defer cancel()
|
||||
var runErr error
|
||||
switch command {
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
./scripts/library-capture.sh recover
|
||||
```
|
||||
|
||||
产物默认写到 `~/.local/share/knowledge-governance/library`(0700),日志写到 `~/.local/share/knowledge-governance/freeze`(0700)。api 容器只以只读方式挂载前者,「整库版本」页据此展示。
|
||||
产物默认写到 `~/.local/share/knowledge-governance/library`(0700),日志写到 `~/.local/share/knowledge-governance/freeze`(0700)。api 容器只以只读方式挂载前者;发布管理的「版本与快照」抽屉与系统设置 → 存储管理据此展示。
|
||||
|
||||
同一个作业号重跑是**幂等重放**:直接返回已封存的同一份候选(`replay=true`、`source_read=false`、`writers_stopped=false`),不读来源、不停写入者;同一作业号换了 scope 或绑定库则明确拒绝。
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -61,8 +62,13 @@ func libraryCaptureEnqueue(w http.ResponseWriter, r *http.Request, config Config
|
||||
return
|
||||
}
|
||||
now := time.Now().UTC()
|
||||
requestedID := fmt.Sprintf("library-capture-%s-%d", request.Scope, now.UnixNano())
|
||||
// The idempotency key is the capture job id: the same logical capture must map
|
||||
// to one queue row. Binding the scope into the key would silently create a
|
||||
// second job instead of reporting a conflicting request, so the conflict is
|
||||
// detected by comparing the stored payload below.
|
||||
job, err := config.Store.Enqueue(r.Context(), jobs.EnqueueRequest{
|
||||
ID: fmt.Sprintf("library-capture-%s-%d", request.Scope, now.UnixNano()),
|
||||
ID: requestedID,
|
||||
Type: libraryCaptureJobType,
|
||||
Payload: payload,
|
||||
AvailableAt: now,
|
||||
@@ -73,24 +79,55 @@ func libraryCaptureEnqueue(w http.ResponseWriter, r *http.Request, config Config
|
||||
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": "cannot enqueue capture job"})
|
||||
return
|
||||
}
|
||||
// Enqueue returns the existing row for a reused key. Answer from that row, not
|
||||
// from the current request: a reused job id with another scope must be refused
|
||||
// instead of being reported as a job for the new scope.
|
||||
var stored struct {
|
||||
Scope string `json:"scope"`
|
||||
CaptureJob string `json:"capture_job"`
|
||||
RequestedBy string `json:"requested_by"`
|
||||
}
|
||||
if err = json.Unmarshal(job.Payload, &stored); err != nil || stored.CaptureJob != captureJob {
|
||||
writeJSON(w, http.StatusConflict, map[string]any{
|
||||
"code": "library_capture_conflict", "error": "该作业号已被另一个封存请求占用",
|
||||
"existing_scope": stored.Scope, "requested_scope": request.Scope,
|
||||
})
|
||||
return
|
||||
}
|
||||
if stored.Scope != request.Scope {
|
||||
writeJSON(w, http.StatusConflict, map[string]any{
|
||||
"code": "library_capture_scope_conflict", "error": "同一作业号已按另一个范围投递",
|
||||
"existing_scope": stored.Scope, "requested_scope": request.Scope,
|
||||
})
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusAccepted, map[string]any{
|
||||
"job_id": job.ID, "capture_job": captureJob, "scope": request.Scope, "state": job.State,
|
||||
"job_id": job.ID, "capture_job": stored.CaptureJob, "scope": stored.Scope,
|
||||
"state": job.State, "reused": job.ID != requestedID, "requested_by": stored.RequestedBy,
|
||||
})
|
||||
}
|
||||
|
||||
// libraryCaptureJobs lists recent capture jobs so the page can show real state
|
||||
// instead of an optimistic spinner. It reads the queue, not the archive.
|
||||
func libraryCaptureJobs(w http.ResponseWriter, r *http.Request, config Config) {
|
||||
queue, err := config.Store.List(r.Context(), 200)
|
||||
// Ask the store for this type only. Reading the global queue and filtering in
|
||||
// the handler would hide capture jobs behind unrelated traffic and make the
|
||||
// page claim "idle" while a capture is still queued.
|
||||
byType, ok := config.Store.(interface {
|
||||
ListByType(ctx context.Context, jobType string, limit int) ([]jobs.Job, error)
|
||||
})
|
||||
if !ok {
|
||||
writeJSON(w, http.StatusOK, map[string]any{"available": false,
|
||||
"reason": "任务存储不支持按类型查询,页面不会据此判断空闲", "jobs": []any{}})
|
||||
return
|
||||
}
|
||||
queue, err := byType.ListByType(r.Context(), libraryCaptureJobType, 20)
|
||||
if err != nil {
|
||||
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": "cannot read capture jobs"})
|
||||
return
|
||||
}
|
||||
views := make([]map[string]any, 0, 20)
|
||||
views := make([]map[string]any, 0, len(queue))
|
||||
for _, job := range queue {
|
||||
if job.Type != libraryCaptureJobType || len(views) >= 20 {
|
||||
continue
|
||||
}
|
||||
var payload struct {
|
||||
Scope string `json:"scope"`
|
||||
CaptureJob string `json:"capture_job"`
|
||||
|
||||
@@ -86,18 +86,25 @@ func TestLibraryCaptureRejectsInvalidRequest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibraryCaptureJobsListsOnlyCaptureJobs(t *testing.T) {
|
||||
store := &fakeJobStore{listResult: []jobs.Job{
|
||||
{ID: "a", Type: libraryCaptureJobType, State: "completed",
|
||||
Payload: json.RawMessage(`{"scope":"internal","capture_job":"lib-internal-1","requested_by":"yaozhanghao"}`),
|
||||
CreatedAt: time.Date(2026, 10, 28, 3, 0, 0, 0, time.UTC)},
|
||||
{ID: "b", Type: "artifact.fetch", State: "completed"},
|
||||
}}
|
||||
func TestLibraryCaptureJobsAsksStoreForItsOwnType(t *testing.T) {
|
||||
// The global queue is busy with unrelated traffic; the capture job must still
|
||||
// be visible because the query is type-scoped, not filtered after the fact.
|
||||
store := &fakeJobStore{
|
||||
listResult: []jobs.Job{{ID: "busy", Type: "artifact.fetch", State: "running"}},
|
||||
listByTypeResult: []jobs.Job{
|
||||
{ID: "a", Type: libraryCaptureJobType, State: "completed",
|
||||
Payload: json.RawMessage(`{"scope":"internal","capture_job":"lib-internal-1","requested_by":"yaozhanghao"}`),
|
||||
CreatedAt: time.Date(2026, 10, 28, 3, 0, 0, 0, time.UTC)},
|
||||
},
|
||||
}
|
||||
recorder := httptest.NewRecorder()
|
||||
libraryCaptureJobs(recorder, httptest.NewRequest(http.MethodGet, "/api/v1/library/captures", nil), Config{Store: store})
|
||||
if recorder.Code != http.StatusOK {
|
||||
t.Fatalf("status=%d", recorder.Code)
|
||||
}
|
||||
if store.listType != libraryCaptureJobType {
|
||||
t.Fatalf("store queried with type %q", store.listType)
|
||||
}
|
||||
var body struct {
|
||||
Available bool `json:"available"`
|
||||
Jobs []map[string]any `json:"jobs"`
|
||||
@@ -109,3 +116,44 @@ func TestLibraryCaptureJobsListsOnlyCaptureJobs(t *testing.T) {
|
||||
t.Fatalf("unexpected body %+v", body)
|
||||
}
|
||||
}
|
||||
|
||||
// Reusing a capture job id with another scope must be refused, and the response
|
||||
// must report the scope that was actually stored.
|
||||
func TestLibraryCaptureRejectsScopeConflictForReusedJob(t *testing.T) {
|
||||
store := &fakeJobStore{enqueueResult: &jobs.Job{ID: "existing-job", Type: libraryCaptureJobType,
|
||||
State: jobs.StateCompleted,
|
||||
Payload: json.RawMessage(`{"scope":"internal","capture_job":"lib-shared","requested_by":"yaozhanghao"}`)}}
|
||||
recorder := httptest.NewRecorder()
|
||||
libraryCaptureEnqueue(recorder, captureRequest(`{"scope":"external","job":"lib-shared"}`),
|
||||
Config{Store: store, LibraryAgentSocket: "/run/library-agent/agent.sock"})
|
||||
if recorder.Code != http.StatusConflict {
|
||||
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)
|
||||
}
|
||||
if body["code"] != "library_capture_scope_conflict" || body["existing_scope"] != "internal" || body["requested_scope"] != "external" {
|
||||
t.Fatalf("unexpected conflict body %v", body)
|
||||
}
|
||||
}
|
||||
|
||||
// A reused job id with an identical request is answered from the stored row.
|
||||
func TestLibraryCaptureReplayReportsStoredJob(t *testing.T) {
|
||||
store := &fakeJobStore{enqueueResult: &jobs.Job{ID: "existing-job", Type: libraryCaptureJobType,
|
||||
State: jobs.StateCompleted,
|
||||
Payload: json.RawMessage(`{"scope":"internal","capture_job":"lib-shared","requested_by":"yaozhanghao"}`)}}
|
||||
recorder := httptest.NewRecorder()
|
||||
libraryCaptureEnqueue(recorder, captureRequest(`{"scope":"internal","job":"lib-shared"}`),
|
||||
Config{Store: store, LibraryAgentSocket: "/run/library-agent/agent.sock"})
|
||||
if recorder.Code != http.StatusAccepted {
|
||||
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)
|
||||
}
|
||||
if body["scope"] != "internal" || body["capture_job"] != "lib-shared" || body["reused"] != true || body["job_id"] != "existing-job" {
|
||||
t.Fatalf("unexpected replay body %v", body)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1526,6 +1526,10 @@ type fakeJobStore struct {
|
||||
enqueued jobs.EnqueueRequest
|
||||
enqueueResult *jobs.Job
|
||||
listResult []jobs.Job
|
||||
listType string
|
||||
listByTypeResult []jobs.Job
|
||||
listByTypeLimit int
|
||||
listByTypeErr error
|
||||
listLimit int
|
||||
assetResult governance.SourceAssetPage
|
||||
assetFilter governance.SourceAssetFilter
|
||||
@@ -1871,7 +1875,9 @@ func (s *fakeJobStore) ActivateUISettingsWithOperation(_ context.Context, revisi
|
||||
func (s *fakeJobStore) Enqueue(_ context.Context, request jobs.EnqueueRequest, _ time.Time) (*jobs.Job, error) {
|
||||
s.enqueued = request
|
||||
if s.enqueueEchoRequestedID {
|
||||
return &jobs.Job{ID: request.ID, Type: request.Type, State: jobs.StatePending}, nil
|
||||
// The real store returns the stored row, including its payload: a reused
|
||||
// idempotency key must be judged by that payload, not by the request.
|
||||
return &jobs.Job{ID: request.ID, Type: request.Type, State: jobs.StatePending, Payload: request.Payload}, nil
|
||||
}
|
||||
return s.enqueueResult, nil
|
||||
}
|
||||
@@ -1881,6 +1887,12 @@ func (s *fakeJobStore) List(_ context.Context, limit int) ([]jobs.Job, error) {
|
||||
return s.listResult, nil
|
||||
}
|
||||
|
||||
func (s *fakeJobStore) ListByType(_ context.Context, jobType string, limit int) ([]jobs.Job, error) {
|
||||
s.listType = jobType
|
||||
s.listByTypeLimit = limit
|
||||
return s.listByTypeResult, s.listByTypeErr
|
||||
}
|
||||
|
||||
func (s *fakeJobStore) ListTestPublications(_ context.Context, filter governance.TestPublicationFilter) (governance.TestPublicationPage, error) {
|
||||
s.publicationFilter = filter
|
||||
return s.publicationResult, nil
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -23,6 +24,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -43,6 +45,13 @@ type Config struct {
|
||||
Writers string
|
||||
NonWriters string
|
||||
MaxDuration time.Duration
|
||||
// StopGrace bounds the graceful stop of one operation: SIGTERM first (the
|
||||
// child aborts the maintenance window and restores writers), then SIGKILL
|
||||
// only after this grace period. It must exceed the child's own restore budget.
|
||||
StopGrace time.Duration
|
||||
// RecoverTimeout bounds the recovery run performed after a failed or killed
|
||||
// operation, and at agent start-up.
|
||||
RecoverTimeout time.Duration
|
||||
// Run executes the binary; replaced in tests.
|
||||
Run func(ctx context.Context, name string, args ...string) ([]byte, error)
|
||||
}
|
||||
@@ -69,6 +78,11 @@ var jobPattern = regexp.MustCompile(`^[A-Za-z0-9_-]{1,64}$`)
|
||||
type Agent struct {
|
||||
config Config
|
||||
mu sync.Mutex
|
||||
// degraded is non-empty when a failed operation could not be followed by a
|
||||
// verified recovery. While set, capture requests are refused: leaving the
|
||||
// source writer stopped is worse than refusing work.
|
||||
degraded string
|
||||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
func New(config Config) (*Agent, error) {
|
||||
@@ -81,6 +95,15 @@ func New(config Config) (*Agent, error) {
|
||||
if config.MaxDuration <= 0 || config.MaxDuration > 30*time.Minute {
|
||||
return nil, errors.New("library agent duration bound is invalid")
|
||||
}
|
||||
if config.StopGrace == 0 {
|
||||
config.StopGrace = 3 * time.Minute
|
||||
}
|
||||
if config.RecoverTimeout == 0 {
|
||||
config.RecoverTimeout = 3 * time.Minute
|
||||
}
|
||||
if config.StopGrace <= 0 || config.StopGrace > 10*time.Minute || config.RecoverTimeout <= 0 || config.RecoverTimeout > 10*time.Minute {
|
||||
return nil, errors.New("library agent recovery/stop budget is invalid")
|
||||
}
|
||||
return &Agent{config: config}, nil
|
||||
}
|
||||
|
||||
@@ -105,6 +128,13 @@ func (a *Agent) Serve(ctx context.Context) error {
|
||||
if err := os.Chmod(a.config.Socket, 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
// Startup responsibility: an agent restart may have inherited a stopped
|
||||
// writer from a previous killed run. Recover before accepting work; if that
|
||||
// fails, stay degraded and refuse captures instead of pretending to be ready.
|
||||
if err := a.recoverWriters(ctx); err != nil {
|
||||
a.degraded = err.Error()
|
||||
log.Printf("library agent: pending freeze recovery failed: %v", err)
|
||||
}
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
_ = listener.Close()
|
||||
@@ -113,11 +143,24 @@ func (a *Agent) Serve(ctx context.Context) error {
|
||||
conn, err := listener.Accept()
|
||||
if err != nil {
|
||||
if ctx.Err() != nil {
|
||||
// Drain in-flight operations: each of them still owes a bounded
|
||||
// recovery before the agent may exit.
|
||||
done := make(chan struct{})
|
||||
go func() { a.wg.Wait(); close(done) }()
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(a.config.StopGrace + a.config.RecoverTimeout):
|
||||
log.Printf("library agent: shutdown deadline exceeded with operations in flight")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
go a.handle(ctx, conn)
|
||||
a.wg.Add(1)
|
||||
go func(conn net.Conn) {
|
||||
defer a.wg.Done()
|
||||
a.handle(ctx, conn)
|
||||
}(conn)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,6 +186,12 @@ func (a *Agent) execute(ctx context.Context, req request) response {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
out := response{Action: req.Action, Scope: req.Scope, Job: req.Job}
|
||||
// Degraded blocks new captures, but recover and status must stay reachable:
|
||||
// otherwise there is no way back to a verified state.
|
||||
if a.degraded != "" && req.Action == "capture" {
|
||||
out.Error = "封存执行边界处于降级状态(上次恢复失败:" + a.degraded + "),先执行 recover"
|
||||
return out
|
||||
}
|
||||
var args []string
|
||||
switch req.Action {
|
||||
case "status":
|
||||
@@ -171,12 +220,30 @@ func (a *Agent) execute(ctx context.Context, req request) response {
|
||||
defer cancel()
|
||||
payload, err := a.config.run(bounded, a.config.Binary, args...)
|
||||
if err != nil {
|
||||
out.Error = "operation failed"
|
||||
detail := "operation failed"
|
||||
if message := strings.TrimSpace(string(payload)); message != "" && len(message) <= 2000 {
|
||||
out.Error = message
|
||||
detail = message
|
||||
}
|
||||
// A killed or aborted child may have left the source writer stopped. The
|
||||
// recovery responsibility does not end with the failed request: run the
|
||||
// idempotent recovery now, and refuse further captures if it does not
|
||||
// verify.
|
||||
if req.Action == "capture" || req.Action == "recover" {
|
||||
if recoveryErr := a.recoverWriters(ctx); recoveryErr != nil {
|
||||
a.degraded = recoveryErr.Error()
|
||||
out.Error = detail + ";写入者恢复失败:" + recoveryErr.Error() + "(已阻断后续封存,需人工处理)"
|
||||
return out
|
||||
}
|
||||
detail += ";已执行 recover 并确认写入者恢复"
|
||||
} else {
|
||||
// status 失败不需要恢复;它不改变停机状态。
|
||||
}
|
||||
out.Error = detail
|
||||
return out
|
||||
}
|
||||
if req.Action == "recover" {
|
||||
a.degraded = ""
|
||||
}
|
||||
out.OK = true
|
||||
if json.Valid(payload) {
|
||||
out.Payload = json.RawMessage(payload)
|
||||
@@ -186,6 +253,18 @@ func (a *Agent) execute(ctx context.Context, req request) response {
|
||||
return out
|
||||
}
|
||||
|
||||
// recoverWriters runs the idempotent recovery command with its own budget, even
|
||||
// when the triggering context is already cancelled (timeout / shutdown).
|
||||
func (a *Agent) recoverWriters(ctx context.Context) error {
|
||||
bounded, cancel := context.WithTimeout(context.WithoutCancel(ctx), a.config.RecoverTimeout)
|
||||
defer cancel()
|
||||
if _, err := a.config.run(bounded, a.config.Binary, append([]string{"recover"}, a.config.declaration()...)...); err != nil {
|
||||
return err
|
||||
}
|
||||
a.degraded = ""
|
||||
return nil
|
||||
}
|
||||
|
||||
// declaration pins every path and the writer group so a request cannot redirect
|
||||
// the operation to another stack, archive or journal.
|
||||
func (c Config) declaration() []string {
|
||||
@@ -208,6 +287,17 @@ func (c Config) run(ctx context.Context, name string, args ...string) ([]byte, e
|
||||
}
|
||||
command := exec.CommandContext(ctx, name, args...)
|
||||
command.Env = append(os.Environ(), "LIBRARYCTL_AGENT=1")
|
||||
// Default CommandContext behaviour is SIGKILL, which would skip the child's
|
||||
// window restore and leave the source writer stopped. Ask for a graceful stop
|
||||
// first and only escalate after the grace period.
|
||||
command.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
command.Cancel = func() error {
|
||||
if command.Process == nil {
|
||||
return nil
|
||||
}
|
||||
return command.Process.Signal(syscall.SIGTERM)
|
||||
}
|
||||
command.WaitDelay = c.StopGrace
|
||||
return command.CombinedOutput()
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package libraryagent
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -108,9 +109,9 @@ func TestAgentSocketIsPrivateAndPinsTheDeclaration(t *testing.T) {
|
||||
if !out.OK || out.Job != "lib-internal-test" {
|
||||
t.Fatalf("capture rejected: %+v", out)
|
||||
}
|
||||
recorded := calls()
|
||||
recorded := captureCalls(calls())
|
||||
if len(recorded) != 1 {
|
||||
t.Fatalf("expected one execution, got %v", recorded)
|
||||
t.Fatalf("expected one capture execution, got %v", recorded)
|
||||
}
|
||||
for _, want := range []string{"capture -scope internal -job lib-internal-test",
|
||||
"-archive " + filepath.Join(filepath.Dir(socket), "library"),
|
||||
@@ -151,11 +152,177 @@ func TestAgentRejectsUnsupportedRequestsWithoutExecuting(t *testing.T) {
|
||||
t.Fatalf("accepted %q: %+v", payload, out)
|
||||
}
|
||||
}
|
||||
if got := calls(); len(got) != 0 {
|
||||
if got := captureCalls(calls()); len(got) != 0 {
|
||||
t.Fatalf("rejected requests still executed: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func captureCalls(calls []string) []string {
|
||||
kept := make([]string, 0, len(calls))
|
||||
for _, call := range calls {
|
||||
if strings.Contains(call, " capture ") {
|
||||
kept = append(kept, call)
|
||||
}
|
||||
}
|
||||
return kept
|
||||
}
|
||||
|
||||
func recoverCalls(calls []string) []string {
|
||||
kept := make([]string, 0, len(calls))
|
||||
for _, call := range calls {
|
||||
if strings.Contains(call, " recover ") {
|
||||
kept = append(kept, call)
|
||||
}
|
||||
}
|
||||
return kept
|
||||
}
|
||||
|
||||
// failingAgent builds an agent whose capture always fails and whose recovery
|
||||
// outcome can be switched, to prove the recovery responsibility after a
|
||||
// killed/aborted child.
|
||||
func failingAgent(t *testing.T) (*Agent, string, func() []string, func(error)) {
|
||||
t.Helper()
|
||||
root, err := os.MkdirTemp(os.TempDir(), "kgrf-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { os.RemoveAll(root) })
|
||||
if err = os.Chmod(root, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var mu sync.Mutex
|
||||
var calls []string
|
||||
var recoverErr error
|
||||
agent, err := New(Config{
|
||||
Socket: filepath.Join(root, "agent.sock"), Binary: "/bin/echo",
|
||||
ArchiveRoot: filepath.Join(root, "library"), JournalRoot: filepath.Join(root, "freeze"),
|
||||
SourceApp: "app-container", SourcePG: "pg", SourceES: "es", GovernancePG: "gov",
|
||||
Project: "weknora071full", Writers: "app", NonWriters: "frontend=UI only",
|
||||
MaxDuration: time.Minute, StopGrace: time.Minute, RecoverTimeout: time.Minute,
|
||||
Run: func(_ context.Context, name string, args ...string) ([]byte, error) {
|
||||
mu.Lock()
|
||||
calls = append(calls, name+" "+strings.Join(args, " "))
|
||||
current := recoverErr
|
||||
mu.Unlock()
|
||||
if len(args) > 0 && args[0] == "recover" {
|
||||
if current != nil {
|
||||
return []byte("writer restart failed"), current
|
||||
}
|
||||
return []byte(`{"recovered":true}`), nil
|
||||
}
|
||||
return []byte("LIBRARYCTL_FAILED: stop outcome uncertain"), errors.New("exit status 1")
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return agent, filepath.Join(root, "agent.sock"), func() []string {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
return append([]string(nil), calls...)
|
||||
}, func(err error) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
recoverErr = err
|
||||
}
|
||||
}
|
||||
|
||||
// A failed capture must be followed by a recovery attempt, not just an error.
|
||||
func TestAgentRecoversWritersAfterFailedCapture(t *testing.T) {
|
||||
agent, socket, calls, _ := failingAgent(t)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
go func() { _ = agent.Serve(ctx) }()
|
||||
waitSocket(t, socket)
|
||||
out := roundTrip(t, socket, `{"action":"capture","scope":"internal","job":"lib-fail-1"}`)
|
||||
if out.OK {
|
||||
t.Fatalf("failed capture reported success: %+v", out)
|
||||
}
|
||||
if !strings.Contains(out.Error, "已执行 recover 并确认写入者恢复") {
|
||||
t.Fatalf("error does not state the recovery outcome: %q", out.Error)
|
||||
}
|
||||
if len(recoverCalls(calls())) == 0 {
|
||||
t.Fatal("no recovery ran after the failed capture")
|
||||
}
|
||||
}
|
||||
|
||||
// If recovery itself fails, the boundary must refuse further captures instead of
|
||||
// leaving the source stopped and merely marking a job failed.
|
||||
func TestAgentBlocksCapturesWhenRecoveryFails(t *testing.T) {
|
||||
agent, socket, calls, setRecoverErr := failingAgent(t)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
go func() { _ = agent.Serve(ctx) }()
|
||||
waitSocket(t, socket)
|
||||
setRecoverErr(errors.New("docker restart failed"))
|
||||
out := roundTrip(t, socket, `{"action":"capture","scope":"internal","job":"lib-fail-2"}`)
|
||||
if out.OK || !strings.Contains(out.Error, "写入者恢复失败") || !strings.Contains(out.Error, "已阻断后续封存") {
|
||||
t.Fatalf("recovery failure not surfaced: %+v", out)
|
||||
}
|
||||
before := len(captureCalls(calls()))
|
||||
blocked := roundTrip(t, socket, `{"action":"capture","scope":"external","job":"lib-fail-3"}`)
|
||||
if blocked.OK || !strings.Contains(blocked.Error, "降级") {
|
||||
t.Fatalf("degraded agent accepted a capture: %+v", blocked)
|
||||
}
|
||||
if got := len(captureCalls(calls())); got != before {
|
||||
t.Fatalf("blocked capture still executed (%d -> %d)", before, got)
|
||||
}
|
||||
// A verified recovery clears the degraded state and lets work resume.
|
||||
setRecoverErr(nil)
|
||||
if recovered := roundTrip(t, socket, `{"action":"recover"}`); !recovered.OK {
|
||||
t.Fatalf("explicit recovery failed: %+v", recovered)
|
||||
}
|
||||
if resumed := roundTrip(t, socket, `{"action":"capture","scope":"internal","job":"lib-fail-4"}`); strings.Contains(resumed.Error, "降级") {
|
||||
t.Fatalf("recovery did not clear the degraded state: %+v", resumed)
|
||||
}
|
||||
}
|
||||
|
||||
// The child is stopped with SIGTERM and the grace period, not an immediate kill.
|
||||
func TestRunStopsChildWithSigterm(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
script := filepath.Join(dir, "child.sh")
|
||||
// A real child that only exits 0 when it receives SIGTERM.
|
||||
child := "#!/bin/sh\ntrap 'exit 0' TERM\nwhile :; do sleep 0.05; done\n"
|
||||
if err := os.WriteFile(script, []byte(child), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
agent, err := New(Config{Socket: "/tmp/irrelevant.sock", Binary: script,
|
||||
ArchiveRoot: filepath.Join(dir, "library"), JournalRoot: filepath.Join(dir, "freeze"),
|
||||
SourceApp: "app-container", SourcePG: "pg", SourceES: "es", GovernancePG: "gov",
|
||||
Project: "weknora071full", Writers: "app", NonWriters: "frontend=UI only",
|
||||
MaxDuration: 2 * time.Second, StopGrace: 5 * time.Second, RecoverTimeout: 5 * time.Second})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 300*time.Millisecond)
|
||||
defer cancel()
|
||||
started := time.Now()
|
||||
_, err = agent.config.run(ctx, script)
|
||||
if err == nil {
|
||||
t.Fatal("cancelled run reported success")
|
||||
}
|
||||
if elapsed := time.Since(started); elapsed > 4*time.Second {
|
||||
t.Fatalf("child was not stopped within the graceful window: %s", elapsed)
|
||||
}
|
||||
if ctx.Err() == nil {
|
||||
t.Fatal("test did not exercise cancellation")
|
||||
}
|
||||
}
|
||||
|
||||
func waitSocket(t *testing.T, socket string) {
|
||||
t.Helper()
|
||||
deadline := time.Now().Add(2 * time.Second)
|
||||
for {
|
||||
if _, err := os.Stat(socket); err == nil {
|
||||
return
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatal("agent socket never appeared")
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRejectsIncompleteConfiguration(t *testing.T) {
|
||||
if _, err := New(Config{}); err == nil {
|
||||
t.Fatal("empty configuration accepted")
|
||||
|
||||
@@ -132,6 +132,18 @@ RETURNING job_id
|
||||
SELECT id FROM updated
|
||||
`
|
||||
|
||||
// One job type, newest first: a caller which needs "the recent jobs of MY type"
|
||||
// must not page the global queue (other traffic would hide its own rows).
|
||||
const listJobsByTypeSQL = `
|
||||
SELECT id, type, payload, state, priority, available_at,
|
||||
lease_owner, lease_until, attempt, max_attempts,
|
||||
last_error, idempotency_key, created_at, updated_at
|
||||
FROM jobs
|
||||
WHERE type = $1
|
||||
ORDER BY created_at DESC, id DESC
|
||||
LIMIT $2
|
||||
`
|
||||
|
||||
const listJobsSQL = `
|
||||
SELECT id, type, payload, state, priority, available_at,
|
||||
lease_owner, lease_until, attempt, max_attempts,
|
||||
|
||||
@@ -65,6 +65,31 @@ func (s *Store) Claim(ctx context.Context, workerID string, allowedTypes []strin
|
||||
return job, nil
|
||||
}
|
||||
|
||||
// ListByType lists only the requested job type, so a busy queue cannot hide the
|
||||
// caller's own recent jobs behind unrelated traffic.
|
||||
func (s *Store) ListByType(ctx context.Context, jobType string, limit int) ([]jobs.Job, error) {
|
||||
if strings.TrimSpace(jobType) == "" || limit < 1 || limit > 200 {
|
||||
return nil, errors.New("list jobs by type requires a type and a bounded limit")
|
||||
}
|
||||
rows, err := s.db.Query(ctx, listJobsByTypeSQL, jobType, limit)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("list jobs by type: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
result := make([]jobs.Job, 0, limit)
|
||||
for rows.Next() {
|
||||
job, err := scanJob(rows)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("scan listed job: %w", err)
|
||||
}
|
||||
result = append(result, *job)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, fmt.Errorf("iterate jobs: %w", err)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *Store) List(ctx context.Context, limit int) ([]jobs.Job, error) {
|
||||
rows, err := s.db.Query(ctx, listJobsSQL, limit)
|
||||
if err != nil {
|
||||
|
||||
Binary file not shown.
+10
-7
@@ -4,7 +4,7 @@ import { DocumentWorkbench } from './DocumentWorkbench'
|
||||
import { SourceCatalogBrowser } from './SourceCatalogBrowser'
|
||||
import { WeKnoraMonitor } from './WeKnoraMonitor'
|
||||
import { VersionHistory } from './VersionHistory'
|
||||
import { LibraryVersions } from './LibraryVersions'
|
||||
import { ReleaseTargets } from './ReleaseTargets'
|
||||
import { QAOperations } from './QAOperations'
|
||||
import { SourceLinkManager } from './SourceLinkManager'
|
||||
import { SystemSettings } from './SystemSettings'
|
||||
@@ -63,7 +63,6 @@ const modules: ReadonlyArray<{ id: ModuleId; label: string; icon: string }> = [
|
||||
{ id: 'tasks', label: '解析监控', icon: '↻' },
|
||||
{ id: 'qaops', label: '问答运营', icon: '▤' },
|
||||
{ id: 'releases', label: '发布管理', icon: '⇧' },
|
||||
{ id: 'library', label: '整库版本', icon: '▦' },
|
||||
{ id: 'settings', label: '系统设置', icon: '⚙' },
|
||||
{ id: 'versions', label: '版本记录', icon: '⌥' },
|
||||
]
|
||||
@@ -409,7 +408,11 @@ export function ModulePage({
|
||||
}
|
||||
if (moduleId === 'releases') {
|
||||
return (
|
||||
<ReleaseManagement
|
||||
<div className="release-module">
|
||||
<ReleaseTargets />
|
||||
<details className="release-legacy">
|
||||
<summary>文档级发布(旧流程,折叠保留):单篇文档发布成功不等于整库发布成功</summary>
|
||||
<ReleaseManagement
|
||||
reviewPage={reviewPage}
|
||||
reviewLoading={reviewLoading}
|
||||
reviewError={reviewError}
|
||||
@@ -451,8 +454,10 @@ export function ModulePage({
|
||||
onStartReleaseAction={onStartReleaseAction}
|
||||
onReleaseActionPhrase={onReleaseActionPhrase}
|
||||
onSubmitReleaseAction={onSubmitReleaseAction}
|
||||
onCancelReleaseAction={onCancelReleaseAction}
|
||||
/>
|
||||
onCancelReleaseAction={onCancelReleaseAction}
|
||||
/>
|
||||
</details>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
if (moduleId === 'settings') {
|
||||
@@ -2972,8 +2977,6 @@ export default function App() {
|
||||
<SystemSettings />
|
||||
) : workspace.activeTab === 'knowledge' ? (
|
||||
<DocumentWorkbench mode="attention" connections={connectionPage.items} />
|
||||
) : workspace.activeTab === 'library' ? (
|
||||
<LibraryVersions />
|
||||
) : workspace.activeTab === 'versions' ? (
|
||||
<VersionHistory />
|
||||
) : workspace.activeTab === 'qaops' ? (
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { fetchLibrarySnapshots, formatBytes, type LibrarySnapshotList } from './librarySnapshots'
|
||||
import './libraryStorage.css'
|
||||
|
||||
// 系统设置 → 存储管理:只读展示整库归档的真实口径。
|
||||
// 保留策略、依赖保护、清理预览都没有实现,自动清理保持关闭——页面不能暗示可以删。
|
||||
export function LibraryStorageSection() {
|
||||
const [page, setPage] = useState<LibrarySnapshotList | null>(null)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
const controller = new AbortController()
|
||||
fetchLibrarySnapshots(controller.signal)
|
||||
.then((value) => {
|
||||
setPage(value)
|
||||
setError(null)
|
||||
})
|
||||
.catch((loadError) => {
|
||||
if ((loadError as Error).name === 'AbortError') return
|
||||
setError(loadError instanceof Error ? loadError.message : '读取归档用量失败')
|
||||
})
|
||||
.finally(() => setLoading(false))
|
||||
return () => controller.abort()
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<section className="library-storage" aria-label="存储管理">
|
||||
<header>
|
||||
<h3>版本快照与归档占用</h3>
|
||||
<p>只读口径:被版本引用的去重内容、blob 文件表观/实际分配字节、未被引用对象、清单文件。</p>
|
||||
</header>
|
||||
{loading ? <p className="library-storage-hint">读取中…</p> : null}
|
||||
{error ? (
|
||||
<div className="library-storage-blocked">
|
||||
<strong>读取失败</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
) : null}
|
||||
{page && !page.available ? <p className="library-storage-hint">{page.reason || '归档未接线'}</p> : null}
|
||||
{page?.available ? (
|
||||
<dl className="library-storage-grid">
|
||||
<div>
|
||||
<dt>版本数</dt>
|
||||
<dd>{page.versions}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>被版本引用的去重内容</dt>
|
||||
<dd>{formatBytes(page.content_bytes)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>blob 文件(表观)</dt>
|
||||
<dd>{formatBytes(page.blob_file_bytes)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>blob 实际分配</dt>
|
||||
<dd>{formatBytes(page.blob_allocated_bytes)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>未被任何版本引用</dt>
|
||||
<dd>
|
||||
{page.unreferenced_blobs} 个 / {formatBytes(page.unreferenced_bytes)}
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>清单文件</dt>
|
||||
<dd>{formatBytes(page.manifest_file_bytes)}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
) : null}
|
||||
<ul className="library-storage-limits">
|
||||
<li>保留策略:未接线(不提供保留几版/多少天的设置)</li>
|
||||
<li>依赖保护与清理预览:未接线</li>
|
||||
<li>自动清理:保持关闭,页面不提供删除动作</li>
|
||||
<li>以上数字都不是“可回收空间”,不能用来估算清理收益</li>
|
||||
</ul>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -1,387 +0,0 @@
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import {
|
||||
enqueueLibraryCapture,
|
||||
fetchLibraryCaptures,
|
||||
fetchLibrarySnapshots,
|
||||
formatBytes,
|
||||
scopeLabel,
|
||||
type LibraryCaptureJob,
|
||||
type LibrarySnapshot,
|
||||
type LibrarySnapshotList,
|
||||
} from './librarySnapshots'
|
||||
import { useOptionalAuth } from './auth'
|
||||
import './libraryVersions.css'
|
||||
|
||||
// 「整库版本」页:只读展示已封存的整库候选产物(对内/对外各一份最新)。
|
||||
// 页面不提供封存按钮:封存要停真实写入者并读来源凭据,只能在目标主机用
|
||||
// scripts/library-capture.sh 执行。通过完整性检查 != 已发布,授权仍走发布管理。
|
||||
const stamp = (value: string) =>
|
||||
value && Number.isFinite(new Date(value).getTime())
|
||||
? new Date(value).toLocaleString('zh-CN', {
|
||||
timeZone: 'Asia/Shanghai',
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: false,
|
||||
})
|
||||
: '—'
|
||||
|
||||
const metric = (snapshot: LibrarySnapshot, key: string) => String(snapshot.totals[key] ?? 0)
|
||||
|
||||
const jobStateLabel: Record<string, string> = {
|
||||
pending: '待执行',
|
||||
running: '执行中',
|
||||
retry: '重试中',
|
||||
completed: '已完成',
|
||||
failed: '失败',
|
||||
}
|
||||
|
||||
export function LibraryVersions() {
|
||||
const auth = useOptionalAuth()
|
||||
const [page, setPage] = useState<LibrarySnapshotList | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [expanded, setExpanded] = useState<string | null>(null)
|
||||
const [scopeFilter, setScopeFilter] = useState<'all' | 'internal' | 'external'>('all')
|
||||
const [jobs, setJobs] = useState<LibraryCaptureJob[]>([])
|
||||
const [pendingScope, setPendingScope] = useState<string | null>(null)
|
||||
const [notice, setNotice] = useState<string | null>(null)
|
||||
|
||||
const load = useCallback(async (signal?: AbortSignal) => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const result = await fetchLibrarySnapshots(signal)
|
||||
setPage(result)
|
||||
setError(null)
|
||||
} catch (loadError) {
|
||||
if ((loadError as Error).name === 'AbortError') return
|
||||
setError(loadError instanceof Error ? loadError.message : '加载整库版本失败')
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const controller = new AbortController()
|
||||
void load(controller.signal)
|
||||
return () => controller.abort()
|
||||
}, [load])
|
||||
|
||||
const refreshJobs = useCallback(async (signal?: AbortSignal) => {
|
||||
const items = await fetchLibraryCaptures(signal)
|
||||
setJobs(items)
|
||||
return items
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const controller = new AbortController()
|
||||
void refreshJobs(controller.signal).catch(() => undefined)
|
||||
return () => controller.abort()
|
||||
}, [refreshJobs])
|
||||
|
||||
// A capture runs in a maintenance window (seconds), so a short poll is enough
|
||||
// to show the real queue state and to pick up the new sealed version.
|
||||
const active = jobs.some((job) => job.state === 'pending' || job.state === 'running' || job.state === 'retry')
|
||||
useEffect(() => {
|
||||
if (!active) return
|
||||
const timer = window.setInterval(() => {
|
||||
void refreshJobs()
|
||||
.then((items) => {
|
||||
if (!items.some((job) => job.state === 'pending' || job.state === 'running' || job.state === 'retry')) {
|
||||
void load()
|
||||
}
|
||||
})
|
||||
.catch(() => undefined)
|
||||
}, 3000)
|
||||
return () => window.clearInterval(timer)
|
||||
}, [active, refreshJobs, load])
|
||||
|
||||
const canCapture = (auth?.identity?.role === 'engineer' || auth?.identity?.role === 'admin') && page?.capture_available === true
|
||||
|
||||
const startCapture = async (scope: string) => {
|
||||
setPendingScope(scope)
|
||||
setNotice(null)
|
||||
try {
|
||||
const accepted = await enqueueLibraryCapture(scope)
|
||||
setNotice(`已投递封存作业:${scopeLabel(scope)} · ${accepted.capture_job}(等待主机侧执行)`)
|
||||
await refreshJobs()
|
||||
} catch (captureError) {
|
||||
setNotice(captureError instanceof Error ? captureError.message : '发起封存失败')
|
||||
} finally {
|
||||
setPendingScope(null)
|
||||
}
|
||||
}
|
||||
|
||||
const snapshots = page?.snapshots ?? []
|
||||
const latestByScope = useMemo(() => {
|
||||
const map: Record<string, LibrarySnapshot | undefined> = {}
|
||||
for (const snapshot of snapshots) {
|
||||
if (!map[snapshot.scope]) map[snapshot.scope] = snapshot
|
||||
}
|
||||
return map
|
||||
}, [snapshots])
|
||||
const visible = snapshots.filter((snapshot) => scopeFilter === 'all' || snapshot.scope === scopeFilter)
|
||||
|
||||
return (
|
||||
<section className="library-versions" aria-label="整库版本">
|
||||
<header className="library-versions-header">
|
||||
<div>
|
||||
<h2>整库版本</h2>
|
||||
<p className="library-versions-sub">
|
||||
每个条目是一份<b>完整封存</b>的整库候选:数据库十表、原始索引正文与向量、对象资源与 Wiki 快照,
|
||||
带逐项摘要与兼容契约。封存期间真实写入者被停住,完成后已恢复。
|
||||
</p>
|
||||
</div>
|
||||
<div className="library-versions-actions">
|
||||
<span
|
||||
className="library-versions-usage"
|
||||
title="跨版本去重后被版本引用的内容字节;不是磁盘占用,也不是可回收空间"
|
||||
>
|
||||
共 {snapshots.length} 份 · 被引用的去重内容 {formatBytes(page?.content_bytes ?? 0)}
|
||||
</span>
|
||||
<button type="button" onClick={() => void load()} disabled={loading}>
|
||||
{loading ? '刷新中…' : '刷新'}
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{page && !page.available ? (
|
||||
<div className="library-versions-blocked">
|
||||
<strong>未接线</strong>
|
||||
<p>{page.reason || '归档根未配置'}</p>
|
||||
</div>
|
||||
) : null}
|
||||
{error ? (
|
||||
<div className="library-versions-blocked">
|
||||
<strong>读取失败</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{page?.available ? (
|
||||
<>
|
||||
<div className="library-versions-scopes">
|
||||
{(['internal', 'external'] as const).map((scope) => {
|
||||
const latest = latestByScope[scope]
|
||||
return (
|
||||
<article key={scope} className={`library-scope-card ${latest ? '' : 'empty'}`}>
|
||||
<header>
|
||||
<h3>{scopeLabel(scope)}</h3>
|
||||
<span className="library-scope-state">{latest ? '已封存' : '尚无封存'}</span>
|
||||
</header>
|
||||
{latest ? (
|
||||
<>
|
||||
<p className="library-scope-time">封存于 {stamp(latest.created_at)}</p>
|
||||
<dl className="library-scope-metrics">
|
||||
<div>
|
||||
<dt>文档</dt>
|
||||
<dd>{metric(latest, 'documents')}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>分块</dt>
|
||||
<dd>{metric(latest, 'chunks')}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>索引</dt>
|
||||
<dd>{metric(latest, 'index_documents')}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>资源</dt>
|
||||
<dd>{metric(latest, 'resources')}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Wiki 页</dt>
|
||||
<dd>{metric(latest, 'wiki_pages')}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>体积</dt>
|
||||
<dd>{formatBytes(latest.logical_bytes)}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<p className="library-scope-id">
|
||||
快照 <code>{latest.snapshot_id.slice(0, 16)}</code>
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<p className="library-scope-hint">该库还没有封存产物。</p>
|
||||
)}
|
||||
<div className="library-scope-actions">
|
||||
{page?.capture_available ? (
|
||||
canCapture ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void startCapture(scope)}
|
||||
disabled={
|
||||
pendingScope === scope ||
|
||||
jobs.some(
|
||||
(job) =>
|
||||
job.scope === scope &&
|
||||
(job.state === 'pending' || job.state === 'running' || job.state === 'retry')
|
||||
)
|
||||
}
|
||||
>
|
||||
{pendingScope === scope ? '投递中…' : `发起${scopeLabel(scope)}封存`}
|
||||
</button>
|
||||
) : (
|
||||
<span>发起封存需要知识工程师及以上权限</span>
|
||||
)
|
||||
) : (
|
||||
<span>{page?.capture_reason}</span>
|
||||
)}
|
||||
</div>
|
||||
</article>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="library-versions-toolbar">
|
||||
<div className="library-versions-filters" role="group" aria-label="按范围筛选">
|
||||
{(
|
||||
[
|
||||
{ id: 'all', label: '全部' },
|
||||
{ id: 'internal', label: '对内' },
|
||||
{ id: 'external', label: '对外' },
|
||||
] as const
|
||||
).map((item) => (
|
||||
<button
|
||||
key={item.id}
|
||||
type="button"
|
||||
className={scopeFilter === item.id ? 'active' : ''}
|
||||
onClick={() => setScopeFilter(item.id)}
|
||||
>
|
||||
{item.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<span className="library-versions-note">{page.capture_note}</span>
|
||||
</div>
|
||||
|
||||
<div className="library-versions-toolbar library-versions-accounting">
|
||||
<span>
|
||||
磁盘事实(不是可回收空间):清单 {formatBytes(page.manifest_file_bytes)} · blob 文件{' '}
|
||||
{formatBytes(page.blob_file_bytes)}(实际分配 {formatBytes(page.blob_allocated_bytes)})· 未被任何版本引用{' '}
|
||||
{page.unreferenced_blobs} 个 / {formatBytes(page.unreferenced_bytes)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{visible.length === 0 ? (
|
||||
<p className="library-versions-empty">还没有封存产物。</p>
|
||||
) : (
|
||||
<table className="library-versions-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>封存时间</th>
|
||||
<th>范围</th>
|
||||
<th>文档</th>
|
||||
<th>分块</th>
|
||||
<th>索引</th>
|
||||
<th>资源</th>
|
||||
<th>Wiki</th>
|
||||
<th>体积</th>
|
||||
<th>模型 / 维度</th>
|
||||
<th>快照</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{visible.map((snapshot) => (
|
||||
<tr key={snapshot.snapshot_id}>
|
||||
<td>{stamp(snapshot.created_at)}</td>
|
||||
<td>{scopeLabel(snapshot.scope)}</td>
|
||||
<td>{metric(snapshot, 'documents')}</td>
|
||||
<td>{metric(snapshot, 'chunks')}</td>
|
||||
<td>{metric(snapshot, 'index_documents')}</td>
|
||||
<td>{metric(snapshot, 'resources')}</td>
|
||||
<td>{metric(snapshot, 'wiki_pages')}</td>
|
||||
<td
|
||||
title={`本版逻辑 ${snapshot.logical_bytes} 字节 · 本版内去重 ${snapshot.unique_bytes} 字节(跨版本去重见上方合计)`}
|
||||
>
|
||||
{formatBytes(snapshot.logical_bytes)}
|
||||
</td>
|
||||
<td>
|
||||
{snapshot.compatibility.embedding_model || '—'} / {snapshot.compatibility.embedding_dimension}
|
||||
</td>
|
||||
<td>
|
||||
<button
|
||||
type="button"
|
||||
className="library-snapshot-toggle"
|
||||
onClick={() =>
|
||||
setExpanded(expanded === snapshot.snapshot_id ? null : snapshot.snapshot_id)
|
||||
}
|
||||
aria-expanded={expanded === snapshot.snapshot_id}
|
||||
>
|
||||
<code>{snapshot.snapshot_id.slice(0, 12)}</code>
|
||||
{expanded === snapshot.snapshot_id ? ' 收起' : ' 分项'}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
|
||||
{notice ? <p className="library-capture-notice">{notice}</p> : null}
|
||||
|
||||
{jobs.length > 0 ? (
|
||||
<div className="library-capture-jobs">
|
||||
<h3>封存作业</h3>
|
||||
<table className="library-versions-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>投递时间</th>
|
||||
<th>范围</th>
|
||||
<th>状态</th>
|
||||
<th>作业号</th>
|
||||
<th>发起人</th>
|
||||
<th>最后错误</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{jobs.map((job) => (
|
||||
<tr key={job.job_id}>
|
||||
<td>{stamp(job.created_at)}</td>
|
||||
<td>{scopeLabel(job.scope)}</td>
|
||||
<td>{jobStateLabel[job.state] ?? job.state}</td>
|
||||
<td>
|
||||
<code>{job.capture_job.slice(0, 24)}</code>
|
||||
</td>
|
||||
<td>{job.requested_by || '—'}</td>
|
||||
<td className="library-capture-error">{job.last_error || '—'}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{visible
|
||||
.filter((snapshot) => snapshot.snapshot_id === expanded)
|
||||
.map((snapshot) => (
|
||||
<div key={snapshot.snapshot_id} className="library-snapshot-parts">
|
||||
<header>
|
||||
<strong>{scopeLabel(snapshot.scope)} · {snapshot.snapshot_id}</strong>
|
||||
<span>
|
||||
策略 {snapshot.validation_policy || '—'} · WeKnora {snapshot.compatibility.weknora_version} ·
|
||||
schema {snapshot.compatibility.schema_version} · 映射{' '}
|
||||
{snapshot.compatibility.index_mapping_sha256.slice(0, 12)}
|
||||
</span>
|
||||
</header>
|
||||
<ul>
|
||||
{snapshot.parts.map((part) => (
|
||||
<li key={`${part.kind}-${part.name}`}>
|
||||
<span className="library-part-kind">{part.kind}</span>
|
||||
<span className="library-part-name">{part.name}</span>
|
||||
<span>{part.count} 项</span>
|
||||
<span>{formatBytes(part.bytes)}</span>
|
||||
<code title={part.sha256}>{part.sha256.slice(0, 12)}</code>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
) : null}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
import { renderToStaticMarkup } from 'react-dom/server'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { ReleaseTargetsView } from './ReleaseTargets'
|
||||
import type { LibraryCaptureJob, LibrarySnapshot, LibrarySnapshotList } from './librarySnapshots'
|
||||
|
||||
const internalSnapshot: LibrarySnapshot = {
|
||||
snapshot_id: 'f992d64ea45bf737a0721a465b5aef2b150ef7757157eb84f3aaf8b6972d98f9',
|
||||
scope: 'internal',
|
||||
knowledge_base_id: '0c84a098-d3ed-4b82-a165-e6de9691d6a8',
|
||||
tenant_id: 10000,
|
||||
created_at: '2026-10-28T03:34:57.314178223Z',
|
||||
validation_policy: 'artifact-acceptance-v1',
|
||||
format: 'weknora-library-snapshot/v1',
|
||||
compatibility: {
|
||||
weknora_version: 'v0.7.1',
|
||||
schema_version: 74,
|
||||
retriever_engine: 'elasticsearch_v8',
|
||||
embedding_model: 'text-embedding-v4',
|
||||
embedding_dimension: 1024,
|
||||
index_mapping_sha256: 'a'.repeat(64),
|
||||
},
|
||||
parts: [
|
||||
{ kind: 'database', name: 'knowledges', sha256: 'b'.repeat(64), count: 4, bytes: 10654 },
|
||||
{ kind: 'index', name: 'chunks', sha256: 'c'.repeat(64), count: 122, bytes: 1624880 },
|
||||
],
|
||||
logical_bytes: 55309044,
|
||||
unique_bytes: 55309040,
|
||||
shared_bytes: 2,
|
||||
totals: { documents: 4, chunks: 38, index_documents: 122, resources: 21, wiki_pages: 31 },
|
||||
}
|
||||
|
||||
const externalSnapshot: LibrarySnapshot = {
|
||||
...internalSnapshot,
|
||||
snapshot_id: '01343b0b310b3977c2fdda05f5b8a6272148c4f7bfa124a6c5944123cf0c51c3',
|
||||
scope: 'external',
|
||||
created_at: '2026-10-28T03:35:53.000000000Z',
|
||||
totals: { documents: 0, chunks: 0, index_documents: 0, resources: 0, wiki_pages: 1 },
|
||||
}
|
||||
|
||||
const runningJob: LibraryCaptureJob = {
|
||||
job_id: 'library-capture-internal-1',
|
||||
capture_job: 'lib-internal-20261028T033457',
|
||||
scope: 'internal',
|
||||
state: 'running',
|
||||
attempt: 1,
|
||||
last_error: '',
|
||||
requested_by: 'yaozhanghao',
|
||||
created_at: '2026-10-28T03:34:50Z',
|
||||
updated_at: '2026-10-28T03:34:55Z',
|
||||
}
|
||||
|
||||
const page: LibrarySnapshotList = {
|
||||
available: true,
|
||||
reason: '',
|
||||
archive_root: '/var/lib/knowledge-governance/library',
|
||||
snapshots: [internalSnapshot, externalSnapshot],
|
||||
versions: 2,
|
||||
content_bytes: 55309693,
|
||||
blob_file_bytes: 55309693,
|
||||
blob_allocated_bytes: 55373824,
|
||||
unreferenced_blobs: 0,
|
||||
unreferenced_bytes: 0,
|
||||
manifest_file_bytes: 7544,
|
||||
manifest_allocated_bytes: 12288,
|
||||
capture_note: '',
|
||||
capture_available: true,
|
||||
capture_reason: '',
|
||||
}
|
||||
|
||||
type ViewProps = Parameters<typeof ReleaseTargetsView>[0]
|
||||
|
||||
const base: ViewProps = {
|
||||
page,
|
||||
jobs: [],
|
||||
loading: false,
|
||||
error: null,
|
||||
notice: null,
|
||||
scope: 'internal',
|
||||
onScope: vi.fn(),
|
||||
drawerOpen: false,
|
||||
onDrawer: vi.fn(),
|
||||
expandedSnapshot: null,
|
||||
onExpandSnapshot: vi.fn(),
|
||||
pendingCapture: false,
|
||||
canCapture: true,
|
||||
canWrite: true,
|
||||
now: new Date('2026-10-28T03:35:00Z').getTime(),
|
||||
onRefresh: vi.fn(),
|
||||
onCapture: vi.fn(),
|
||||
}
|
||||
|
||||
const render = (overrides: Partial<ViewProps> = {}) => renderToStaticMarkup(<ReleaseTargetsView {...base} {...overrides} />)
|
||||
|
||||
describe('ReleaseTargetsView(确认稿布局)', () => {
|
||||
it('顶部只有两个知识库页签,且一次只显示选中库的作业区', () => {
|
||||
const html = render()
|
||||
expect(html).toContain('对内知识库')
|
||||
expect(html).toContain('对外知识库')
|
||||
expect(html).toContain('role="tab"')
|
||||
// 只显示一个主作业卡:选中库标题出现一次,另一个库不渲染作业卡
|
||||
expect(html.match(/· 已封存,生产同步未接入/g)?.length).toBe(1)
|
||||
expect(html).not.toContain('对外知识库 · 尚无')
|
||||
})
|
||||
|
||||
it('未接入项显示“未接入”,不用 0 / 无变化冒充', () => {
|
||||
const html = render()
|
||||
expect(html).toContain('生产当前')
|
||||
expect(html).toContain('未接入')
|
||||
expect(html).toContain('尚无记录 · 变更清单来自生产与测试版本对比')
|
||||
})
|
||||
|
||||
it('“启动同步”保持禁用并说明原因,不把封存当成同步', () => {
|
||||
const html = render()
|
||||
expect(html).toMatch(/<button[^>]*class="rel-primary"[^>]*disabled/)
|
||||
expect(html).toContain('生产同步未接线')
|
||||
expect(html).toContain('封存测试版本')
|
||||
})
|
||||
|
||||
it('版本与快照抽屉按 scope 列出全部历史并区分测试封存/不可直接恢复', () => {
|
||||
const html = render({ drawerOpen: true, expandedSnapshot: internalSnapshot.snapshot_id })
|
||||
expect(html).toContain('版本与快照')
|
||||
expect(html).toContain('封存 f992d64ea45b')
|
||||
expect(html).toContain('测试封存')
|
||||
expect(html).toContain('不可直接恢复')
|
||||
expect(html).toContain('恢复至该版本')
|
||||
expect(html).toMatch(/恢复至该版本[^<]*<\/button>/)
|
||||
expect(html).toContain('分项数量 / 字节 / 摘要(2 项)')
|
||||
expect(html).toContain('不支持只选择 Wiki 或某张数据表恢复')
|
||||
})
|
||||
|
||||
it('抽屉只展示当前选中库的历史', () => {
|
||||
const html = render({ drawerOpen: true, scope: 'external' })
|
||||
expect(html).toContain('封存 01343b0b310b')
|
||||
expect(html).not.toContain('封存 f992d64ea45b')
|
||||
})
|
||||
|
||||
it('同步中布局显示四类数据卡与明细,且不编造百分比', () => {
|
||||
const html = render({ jobs: [runningJob] })
|
||||
expect(html).toContain('正在封存测试版本')
|
||||
expect(html).toContain('数据库 · 文档与分块')
|
||||
expect(html).toContain('原文件 · 图片 · 附件')
|
||||
expect(html).toContain('检索索引 · 向量')
|
||||
expect(html).toContain('Wiki · 完整快照')
|
||||
expect(html).toContain('同步明细')
|
||||
// 唯一允许出现的百分比是免责声明里的「100% ≠ 作业完成」,没有任何进度主张
|
||||
expect(html.match(/[1-9]\d*%/g) ?? []).toEqual(['100%'])
|
||||
expect(html).toContain('文件传输 100% ≠ 作业完成')
|
||||
expect(html).toContain('不编造百分比')
|
||||
})
|
||||
|
||||
it('无权限时不给封存入口,未接线时说明通道状态', () => {
|
||||
expect(render({ canCapture: false, canWrite: false })).toContain('封存需要知识工程师及以上权限')
|
||||
const unwired = render({
|
||||
canCapture: false,
|
||||
canWrite: true,
|
||||
page: { ...page, capture_available: false, capture_reason: '主机侧封存 agent 未接线' },
|
||||
})
|
||||
expect(unwired).toContain('封存通道未接线')
|
||||
})
|
||||
|
||||
it('无封存时给出“尚无封存”而不是空表', () => {
|
||||
const html = render({ page: { ...page, snapshots: [] } })
|
||||
expect(html).toContain('尚无测试封存')
|
||||
expect(html).toContain('还没有测试库封存')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,803 @@
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import {
|
||||
enqueueLibraryCapture,
|
||||
fetchLibraryCaptures,
|
||||
fetchLibrarySnapshots,
|
||||
formatBytes,
|
||||
scopeLabel,
|
||||
type LibraryCaptureJob,
|
||||
type LibrarySnapshot,
|
||||
type LibrarySnapshotList,
|
||||
} from './librarySnapshots'
|
||||
import { useOptionalAuth } from './auth'
|
||||
import './releaseTargets.css'
|
||||
|
||||
// 发布管理:按已确认稿实现——顶部两个知识库页签,下面是**一个**作业区。
|
||||
//
|
||||
// 真实能力只有「测试库封存」这一段;生产当前版本、变更差异、生产预备份、
|
||||
// 同步与生产验证都还没有接线。页面照原稿结构全部画出来,但未接线的位置一律
|
||||
// 写「未接入 / 尚无记录」,不用 0、无变化或已同步冒充。队列状态、封存、传输、
|
||||
// 生产验证是四个不同阶段,不能互相顶替。
|
||||
|
||||
const stamp = (value: string) =>
|
||||
value && Number.isFinite(new Date(value).getTime())
|
||||
? new Date(value).toLocaleString('zh-CN', {
|
||||
timeZone: 'Asia/Shanghai',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hour12: false,
|
||||
})
|
||||
: '—'
|
||||
|
||||
const elapsed = (from: string, to: number) => {
|
||||
const start = new Date(from).getTime()
|
||||
if (!Number.isFinite(start) || to <= start) return '—'
|
||||
const total = Math.floor((to - start) / 1000)
|
||||
const minutes = Math.floor(total / 60)
|
||||
const seconds = total % 60
|
||||
return `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`
|
||||
}
|
||||
|
||||
const ACTIVE_STATES = ['pending', 'running', 'retry']
|
||||
const jobStateLabel: Record<string, string> = {
|
||||
pending: '排队中',
|
||||
running: '执行中',
|
||||
retry: '重试中',
|
||||
completed: '已完成',
|
||||
failed: '失败',
|
||||
}
|
||||
|
||||
type Scope = 'internal' | 'external'
|
||||
|
||||
interface ScopeView {
|
||||
scope: Scope
|
||||
snapshot?: LibrarySnapshot
|
||||
history: LibrarySnapshot[]
|
||||
activeJob?: LibraryCaptureJob
|
||||
lastJob?: LibraryCaptureJob
|
||||
}
|
||||
|
||||
interface ViewProps {
|
||||
page: LibrarySnapshotList | null
|
||||
jobs: LibraryCaptureJob[]
|
||||
loading: boolean
|
||||
error: string | null
|
||||
notice: string | null
|
||||
scope: Scope
|
||||
onScope: (scope: Scope) => void
|
||||
drawerOpen: boolean
|
||||
onDrawer: (open: boolean) => void
|
||||
expandedSnapshot: string | null
|
||||
onExpandSnapshot: (id: string | null) => void
|
||||
pendingCapture: boolean
|
||||
canCapture: boolean
|
||||
canWrite: boolean
|
||||
now: number
|
||||
onRefresh: () => void
|
||||
onCapture: () => void
|
||||
}
|
||||
|
||||
function scopeView(page: LibrarySnapshotList | null, jobs: LibraryCaptureJob[], scope: Scope): ScopeView {
|
||||
const history = (page?.snapshots ?? []).filter((item) => item.scope === scope)
|
||||
const scoped = jobs.filter((job) => job.scope === scope)
|
||||
return {
|
||||
scope,
|
||||
snapshot: history[0],
|
||||
history,
|
||||
activeJob: scoped.find((job) => ACTIVE_STATES.includes(job.state)),
|
||||
lastJob: scoped[0],
|
||||
}
|
||||
}
|
||||
|
||||
const scopeName = (scope: Scope) => (scope === 'internal' ? '对内知识库' : '对外知识库')
|
||||
|
||||
function statusOf(view: ScopeView) {
|
||||
if (view.activeJob) return { text: '封存中', tone: 'blue' as const }
|
||||
if (view.snapshot) return { text: '已有封存', tone: 'green' as const }
|
||||
return { text: '尚无封存', tone: 'gray' as const }
|
||||
}
|
||||
|
||||
const jstate = (state?: string) =>
|
||||
state === 'failed' ? '封存失败,可在版本与快照里查看原因' : state ? '封存已完成,生产段未接入' : '尚无作业'
|
||||
|
||||
// 五个阶段对应原稿:固定测试版本 → 备份生产 → 同步数据与 Wiki → 生产验证 → 新版本生效。
|
||||
// 只有第一段有真实实现;其余按"未接入"显示,不画成进行中或已完成。
|
||||
function StageBar({ view }: { view: ScopeView }) {
|
||||
const sealed = Boolean(view.snapshot)
|
||||
const capturing = Boolean(view.activeJob)
|
||||
const stages = [
|
||||
{
|
||||
label: '固定测试版本',
|
||||
state: capturing ? 'live' : sealed ? 'done' : 'idle',
|
||||
hint: capturing ? '封存执行中' : sealed ? `最近封存 ${stamp(view.snapshot!.created_at)}` : '尚未封存',
|
||||
},
|
||||
{ label: '备份生产', state: 'idle', hint: '未接入' },
|
||||
{ label: '同步数据与 Wiki', state: 'idle', hint: '未接入' },
|
||||
{ label: '生产验证', state: 'idle', hint: '未接入' },
|
||||
{ label: '新版本生效', state: 'idle', hint: '未接入' },
|
||||
]
|
||||
return (
|
||||
<>
|
||||
<ol className="rel-steps" aria-label="作业阶段">
|
||||
{stages.map((stage, index) => (
|
||||
<li key={stage.label} className={`rel-step ${stage.state}`}>
|
||||
<span className="rel-step-mark">{stage.state === 'done' ? '✓' : stage.state === 'live' ? '●' : '○'}</span>
|
||||
<strong>{stage.label}</strong>
|
||||
<small>{stage.hint}</small>
|
||||
{index < stages.length - 1 ? <span className="rel-step-arrow">→</span> : null}
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
<p className="rel-steps-note">
|
||||
{capturing
|
||||
? '封存是停写入者后的原子导出,没有分项进度上报;导出完成后才会出现新版本。'
|
||||
: '运行时展开各类数据的数量、字节进度及 Wiki 快照进度;不把提交成功当作版本生效。'}
|
||||
</p>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
function ChangeTable() {
|
||||
return (
|
||||
<div className="rel-panel rel-changes">
|
||||
<header className="rel-panel-head">
|
||||
<div>
|
||||
<h2>本次变更</h2>
|
||||
<p>整库版本同步,不单独勾选文件</p>
|
||||
</div>
|
||||
<span className="rel-pill gray">未接入</span>
|
||||
</header>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>动作</th>
|
||||
<th>文档</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td colSpan={2} className="rel-table-empty">
|
||||
尚无记录 · 变更清单来自生产与测试版本对比,这项数据还没有接入
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function ProtectionCard({ onOpen }: { onOpen: () => void }) {
|
||||
return (
|
||||
<aside className="rel-panel rel-protection">
|
||||
<header className="rel-panel-head">
|
||||
<h2>生产保护与恢复</h2>
|
||||
<span className="rel-pill gray">尚未创建</span>
|
||||
</header>
|
||||
<dl>
|
||||
<dt>本次同步前备份</dt>
|
||||
<dd>未接入</dd>
|
||||
<dt>生产当前版本</dt>
|
||||
<dd>未接入</dd>
|
||||
<dt>备份范围</dt>
|
||||
<dd>数据库 / 资源 / 索引 / Wiki</dd>
|
||||
<dt>恢复条件</dt>
|
||||
<dd>备份完成后核验</dd>
|
||||
</dl>
|
||||
<p className="rel-hint">同步启动后,这里显示本次生产恢复点及备份进度,可直接查看对应快照。</p>
|
||||
<button type="button" className="rel-secondary" onClick={onOpen}>
|
||||
查看已有版本与快照 ›
|
||||
</button>
|
||||
<p className="rel-warn">恢复版本会恢复一整套生产知识状态,不回退测试知识库。</p>
|
||||
</aside>
|
||||
)
|
||||
}
|
||||
|
||||
interface ReadyProps {
|
||||
view: ScopeView
|
||||
canCapture: boolean
|
||||
canWrite: boolean
|
||||
pendingCapture: boolean
|
||||
onCapture: () => void
|
||||
onOpen: () => void
|
||||
}
|
||||
|
||||
function ReadyBody({ view, canCapture, canWrite, pendingCapture, onCapture, onOpen }: ReadyProps) {
|
||||
const snapshot = view.snapshot
|
||||
return (
|
||||
<>
|
||||
<div className="rel-grid">
|
||||
<ChangeTable />
|
||||
<ProtectionCard onOpen={onOpen} />
|
||||
</div>
|
||||
<div className="rel-panel rel-jobbar">
|
||||
<header className="rel-panel-head">
|
||||
<h2>启动后的作业进度</h2>
|
||||
<span className="rel-pill gray">此时尚未运行</span>
|
||||
</header>
|
||||
<StageBar view={view} />
|
||||
</div>
|
||||
<div className="rel-panel rel-seal">
|
||||
<div>
|
||||
<h2>测试库封存</h2>
|
||||
<p>
|
||||
{snapshot
|
||||
? `最近一次封存 ${stamp(snapshot.created_at)},快照 ${snapshot.snapshot_id.slice(0, 12)}。封存只读测试库,不影响生产。`
|
||||
: '还没有测试库封存。封存会短暂停住测试写入者,导出完整版本后恢复。'}
|
||||
</p>
|
||||
</div>
|
||||
{canCapture ? (
|
||||
<button
|
||||
type="button"
|
||||
className="rel-secondary"
|
||||
onClick={onCapture}
|
||||
disabled={pendingCapture || Boolean(view.activeJob)}
|
||||
>
|
||||
{pendingCapture ? '投递中…' : '封存测试版本'}
|
||||
</button>
|
||||
) : (
|
||||
<span className="rel-hint">{canWrite ? '封存通道未接线' : '封存需要知识工程师及以上权限'}</span>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
function ProgressBody({ view, now, onOpen }: { view: ScopeView; now: number; onOpen: () => void }) {
|
||||
const job = view.activeJob ?? view.lastJob
|
||||
const running = Boolean(view.activeJob)
|
||||
const cards = [
|
||||
{ title: '数据库 · 文档与分块', note: '封存导出为原子操作,尚无分项上报' },
|
||||
{ title: '原文件 · 图片 · 附件', note: '封存导出为原子操作,尚无分项上报' },
|
||||
{ title: '检索索引 · 向量', note: '复用测试端产物;生产不重新解析(未接入)' },
|
||||
{ title: 'Wiki · 完整快照', note: 'Wiki 随整库快照导出;生产写入未接入' },
|
||||
]
|
||||
return (
|
||||
<>
|
||||
<div className="rel-panel rel-progress-head">
|
||||
<div className="rel-between">
|
||||
<h2>
|
||||
正在封存测试版本
|
||||
<span className="rel-version">
|
||||
当前 <b>{view.snapshot ? view.snapshot.snapshot_id.slice(0, 12) : '未接入'}</b> → 目标{' '}
|
||||
<b>本次封存产物</b>
|
||||
</span>
|
||||
</h2>
|
||||
<span className={`rel-pill ${running ? 'blue' : job?.state === 'failed' ? 'red' : 'green'}`}>
|
||||
{job ? `${jobStateLabel[job.state] ?? job.state} · 已用时 ${elapsed(job.created_at, now)}` : '无作业'}
|
||||
</span>
|
||||
</div>
|
||||
<p className="rel-jobmeta">
|
||||
作业 <code>{job?.capture_job ?? '未接入'}</code> · 操作人 {job?.requested_by || '—'} · 最近进展{' '}
|
||||
{job ? stamp(job.updated_at) : '—'}
|
||||
</p>
|
||||
<StageBar view={view} />
|
||||
<div className="rel-between rel-progress-foot">
|
||||
<span>当前:{running ? '导出数据库、索引、对象与 Wiki 快照' : jstate(job?.state)}</span>
|
||||
<button type="button" className="rel-link" onClick={onOpen}>
|
||||
查看版本与快照 ↗
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="rel-panel rel-datatypes">
|
||||
<header className="rel-panel-head">
|
||||
<h2>各类数据同步情况</h2>
|
||||
<span className="rel-hint">没有真实总量与完成量的项目只显示状态,不编造百分比</span>
|
||||
</header>
|
||||
<div className="rel-grid rel-grid-4">
|
||||
{cards.map((card) => (
|
||||
<article key={card.title} className="rel-datacard">
|
||||
<header>
|
||||
<h3>{card.title}</h3>
|
||||
<span className="rel-pill gray">未接入</span>
|
||||
</header>
|
||||
<p className="rel-datacount">
|
||||
<strong>—</strong> / 未接入
|
||||
</p>
|
||||
<div className="rel-progress" aria-hidden="true">
|
||||
<span style={{ width: '0%' }} />
|
||||
</div>
|
||||
<p className="rel-datadetail">{card.note}</p>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="rel-panel rel-details">
|
||||
<header className="rel-panel-head">
|
||||
<h2>同步明细</h2>
|
||||
<div className="rel-filters">
|
||||
<button type="button" className="chosen">
|
||||
全部
|
||||
</button>
|
||||
<button type="button">正在执行</button>
|
||||
<button type="button">失败</button>
|
||||
</div>
|
||||
</header>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>任务 / 对象</th>
|
||||
<th>数据类型</th>
|
||||
<th>进度</th>
|
||||
<th>状态</th>
|
||||
<th>说明</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>测试库封存 {job ? job.capture_job : ''}</td>
|
||||
<td>数据库 / 资源 / 索引 / Wiki</td>
|
||||
<td>{job ? jobStateLabel[job.state] : '—'}</td>
|
||||
<td>{running ? '执行中' : job?.state === 'failed' ? '失败' : job ? '已完成' : '未接入'}</td>
|
||||
<td>
|
||||
{job?.last_error ? job.last_error : running ? '导出完成前无分项数据' : '封存结束后恢复测试写入者'}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>生产恢复备份</td>
|
||||
<td>数据库 / 资源 / 索引 / Wiki</td>
|
||||
<td>未接入</td>
|
||||
<td>未接入</td>
|
||||
<td>生产预备份还没有接线</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>本次变更文档</td>
|
||||
<td>文档 / 分块 / 资源关联</td>
|
||||
<td>未接入</td>
|
||||
<td>未接入</td>
|
||||
<td>差异清单还没有接入</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>生产 Wiki 快照</td>
|
||||
<td>Wiki 页面 / 关联数据</td>
|
||||
<td>未接入</td>
|
||||
<td>未接入</td>
|
||||
<td>生产不重新生成 Wiki;写入未接线</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<footer className="rel-log">
|
||||
<span>
|
||||
最近事件:
|
||||
{job?.last_error
|
||||
? `封存作业报错(${job.last_error.slice(0, 60)})`
|
||||
: running
|
||||
? '封存作业执行中;无错误。'
|
||||
: job
|
||||
? '封存作业已结束;无错误。'
|
||||
: '尚无作业记录。'}
|
||||
</span>
|
||||
<span>文件传输 100% ≠ 作业完成;生产验证通过前不显示“完成”。</span>
|
||||
</footer>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
interface DrawerProps {
|
||||
view: ScopeView
|
||||
page: LibrarySnapshotList | null
|
||||
now: number
|
||||
open: boolean
|
||||
expanded: string | null
|
||||
onExpand: (id: string | null) => void
|
||||
onClose: () => void
|
||||
canCapture: boolean
|
||||
pendingCapture: boolean
|
||||
onCapture: () => void
|
||||
}
|
||||
|
||||
function Drawer({ view, page, now, open, expanded, onExpand, onClose, canCapture, pendingCapture, onCapture }: DrawerProps) {
|
||||
if (!open) return null
|
||||
const listing = view.history
|
||||
const selected = listing.find((item) => item.snapshot_id === expanded)
|
||||
return (
|
||||
<div className="rel-drawer-backdrop" role="presentation" onClick={onClose}>
|
||||
<aside className="rel-drawer" role="dialog" aria-label="版本与快照" onClick={(event) => event.stopPropagation()}>
|
||||
<header className="rel-drawer-head">
|
||||
<div>
|
||||
<h2>版本与快照</h2>
|
||||
<p>{scopeName(view.scope)} · 已封存记录</p>
|
||||
</div>
|
||||
<button type="button" className="rel-close" onClick={onClose}>
|
||||
关闭 ✕
|
||||
</button>
|
||||
</header>
|
||||
<p className="rel-notice">生产当前版本未接入;测试封存与生产生效、生产备份分别记录,不要互相顶替。</p>
|
||||
<table className="rel-drawer-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>版本 / 发布记录</th>
|
||||
<th>状态</th>
|
||||
<th>恢复资料</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{listing.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={4} className="rel-table-empty">
|
||||
尚无封存记录。封存测试版本后,这里会按时间列出每一份完整版本。
|
||||
</td>
|
||||
</tr>
|
||||
) : (
|
||||
listing.map((snapshot) => {
|
||||
const isSelected = expanded === snapshot.snapshot_id
|
||||
return (
|
||||
<tr key={snapshot.snapshot_id} className={isSelected ? 'selected' : ''}>
|
||||
<td>
|
||||
<strong>封存 {snapshot.snapshot_id.slice(0, 12)}</strong>
|
||||
<small>{stamp(snapshot.created_at)}</small>
|
||||
</td>
|
||||
<td>
|
||||
<span className="rel-pill green">测试封存</span>
|
||||
</td>
|
||||
<td>
|
||||
<span className="rel-pill gray">分项完整 · 未做生产恢复验证</span>
|
||||
</td>
|
||||
<td>
|
||||
<button
|
||||
type="button"
|
||||
className="rel-link"
|
||||
onClick={() => onExpand(isSelected ? null : snapshot.snapshot_id)}
|
||||
>
|
||||
{isSelected ? '收起快照' : '查看快照'}
|
||||
</button>
|
||||
<button type="button" className="rel-link" disabled title="生产恢复未接线,也没有恢复演练记录">
|
||||
不可直接恢复
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
})
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{selected ? (
|
||||
<section className="rel-snapshot">
|
||||
<header>
|
||||
<h3>封存 {selected.snapshot_id.slice(0, 12)} · 恢复资料</h3>
|
||||
<span className="rel-pill green">读取时逐项校验通过</span>
|
||||
</header>
|
||||
<p className="rel-hint">
|
||||
完整快照 <code>{selected.snapshot_id}</code> · 封存于 {stamp(selected.created_at)} · 模型{' '}
|
||||
{selected.compatibility.embedding_model || '未记录'}
|
||||
</p>
|
||||
<dl className="rel-snapshot-grid">
|
||||
<div>
|
||||
<dt>文档 / 分块</dt>
|
||||
<dd>
|
||||
{selected.totals.documents ?? 0} 份 · {selected.totals.chunks ?? 0} 分块 ✓
|
||||
</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>检索索引 / 向量</dt>
|
||||
<dd>{selected.totals.index_documents ?? 0} 条 ✓</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>原文件 / 图片 / 附件</dt>
|
||||
<dd>{selected.totals.resources ?? 0} 个 ✓</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Wiki 完整快照</dt>
|
||||
<dd>{selected.totals.wiki_pages ?? 0} 页 ✓</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<details className="rel-parts">
|
||||
<summary>分项数量 / 字节 / 摘要({selected.parts.length} 项)</summary>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>类别</th>
|
||||
<th>分项</th>
|
||||
<th>数量</th>
|
||||
<th>字节</th>
|
||||
<th>摘要</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{selected.parts.map((part) => (
|
||||
<tr key={`${part.kind}-${part.name}`}>
|
||||
<td>{part.kind}</td>
|
||||
<td>{part.name}</td>
|
||||
<td>{part.count}</td>
|
||||
<td>{part.bytes.toLocaleString('zh-CN')}</td>
|
||||
<td>
|
||||
<code>{part.sha256.slice(0, 10)}</code>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</details>
|
||||
<p className="rel-hint">
|
||||
以上是同一恢复点的配套内容,不支持只选择 Wiki 或某张数据表恢复。恢复速度需实测;“有备份文件”不等于可恢复。
|
||||
</p>
|
||||
<div className="rel-drawer-actions">
|
||||
<button type="button" disabled title="生产恢复验证记录未接入">
|
||||
查看校验记录
|
||||
</button>
|
||||
<button type="button" className="rel-danger" disabled title="生产恢复未接线,也没有经过恢复演练">
|
||||
恢复至该版本
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
<footer className="rel-drawer-foot">
|
||||
<div>
|
||||
<strong>封存测试版本</strong>
|
||||
<p>
|
||||
封存只读测试库、短暂停住测试写入者并恢复;不会写入生产。当前作业:
|
||||
{view.activeJob
|
||||
? ` ${jobStateLabel[view.activeJob.state] ?? view.activeJob.state}(${elapsed(view.activeJob.created_at, now)})`
|
||||
: ' 无'}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="rel-secondary"
|
||||
disabled={!canCapture || pendingCapture || Boolean(view.activeJob)}
|
||||
onClick={onCapture}
|
||||
>
|
||||
{pendingCapture ? '投递中…' : '封存测试版本'}
|
||||
</button>
|
||||
</footer>
|
||||
<p className="rel-hint">
|
||||
归档占用(只读):被版本引用的去重内容 {formatBytes(page?.content_bytes ?? 0)} · 磁盘分配{' '}
|
||||
{formatBytes(page?.blob_allocated_bytes ?? 0)} · 未被引用 {page?.unreferenced_blobs ?? 0} 个。保留策略与清理在系统设置 →
|
||||
存储管理,均未接线。
|
||||
</p>
|
||||
</aside>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export function ReleaseTargetsView(props: ViewProps) {
|
||||
const {
|
||||
page, jobs, loading, error, notice, scope, onScope, drawerOpen, onDrawer, expandedSnapshot, onExpandSnapshot,
|
||||
pendingCapture, canCapture, canWrite, now, onRefresh, onCapture,
|
||||
} = props
|
||||
const internal = scopeView(page, jobs, 'internal')
|
||||
const external = scopeView(page, jobs, 'external')
|
||||
const view = scope === 'internal' ? internal : external
|
||||
const active = Boolean(view.activeJob)
|
||||
|
||||
return (
|
||||
<section className="release-targets" aria-label="发布管理">
|
||||
<header className="rel-head">
|
||||
<div>
|
||||
<h1>发布管理</h1>
|
||||
<p>测试维护与验证,生产按知识库版本同步。</p>
|
||||
</div>
|
||||
<div className="rel-head-actions">
|
||||
<button type="button" className="rel-secondary" onClick={() => onDrawer(true)}>
|
||||
▣ 版本与快照
|
||||
</button>
|
||||
<button type="button" className="rel-secondary" onClick={onRefresh} disabled={loading}>
|
||||
{loading ? '刷新中…' : '刷新'}
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="rel-tabs" role="tablist" aria-label="知识库">
|
||||
{[internal, external].map((item) => {
|
||||
const status = statusOf(item)
|
||||
const isSelected = item.scope === scope
|
||||
return (
|
||||
<button
|
||||
key={item.scope}
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={isSelected}
|
||||
className={isSelected ? 'rel-tab selected' : 'rel-tab'}
|
||||
onClick={() => onScope(item.scope)}
|
||||
>
|
||||
<strong>{scopeName(item.scope)}</strong>
|
||||
<span className={`rel-pill ${status.tone}`}>{status.text}</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{error ? (
|
||||
<div className="rel-blocked">
|
||||
<strong>读取失败</strong>
|
||||
<p>{error}</p>
|
||||
</div>
|
||||
) : null}
|
||||
{page && !page.available ? (
|
||||
<div className="rel-blocked">
|
||||
<strong>归档未接线</strong>
|
||||
<p>{page.reason || '整库归档根未配置'}</p>
|
||||
</div>
|
||||
) : null}
|
||||
{notice ? <p className="rel-notice">{notice}</p> : null}
|
||||
|
||||
<div className="rel-panel rel-jobhead">
|
||||
<div className="rel-between">
|
||||
<h2>
|
||||
{scopeName(scope)} · {active ? '封存进行中' : view.snapshot ? '已封存,生产同步未接入' : '尚无测试封存'}
|
||||
</h2>
|
||||
<div className="rel-head-actions">
|
||||
<button type="button" className="rel-secondary" onClick={() => onDrawer(true)}>
|
||||
版本与快照
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="rel-primary"
|
||||
disabled
|
||||
title="生产同步未接线:没有生产预备份、生产授权与同步协调器,点击不会写入生产"
|
||||
>
|
||||
▶ 启动同步
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p className="rel-versionline">
|
||||
生产当前 <b className="rel-unknown">未接入</b> → 拟发布{' '}
|
||||
<b>{view.snapshot ? `封存 ${view.snapshot.snapshot_id.slice(0, 12)}` : '未接入'}</b> · 尚未启动,不修改生产
|
||||
</p>
|
||||
<dl className="rel-metrics">
|
||||
<div>
|
||||
<dt>新增文档</dt>
|
||||
<dd className="rel-unknown">未接入</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>更新文档</dt>
|
||||
<dd className="rel-unknown">未接入</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>删除文档</dt>
|
||||
<dd className="rel-unknown">未接入</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Wiki 发布方式</dt>
|
||||
<dd>{view.snapshot ? '完整快照' : '未接入'}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<ul className="rel-checklist">
|
||||
<li className={view.snapshot ? 'ok' : 'unknown'}>
|
||||
{view.snapshot
|
||||
? `✓ 文档解析与索引完整(${view.snapshot.totals.chunks ?? 0} 分块 / ${view.snapshot.totals.index_documents ?? 0} 索引)`
|
||||
: '○ 文档解析与索引:未接入'}
|
||||
</li>
|
||||
<li className={view.snapshot ? 'ok' : 'unknown'}>
|
||||
{view.snapshot ? `✓ Wiki 快照完整(${view.snapshot.totals.wiki_pages ?? 0} 页)` : '○ Wiki 快照:未接入'}
|
||||
</li>
|
||||
<li className={view.snapshot ? 'ok' : 'unknown'}>
|
||||
{view.snapshot ? `✓ 数据完整性:${view.snapshot.parts.length} 项摘要逐项一致` : '○ 数据完整性:尚无封存可核验'}
|
||||
</li>
|
||||
</ul>
|
||||
<p className="rel-footnote">
|
||||
启动后先固定测试版本,再备份生产。备份失败或恢复条件不满足,不进入生产写入。启动同步这一步当前未接线。
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{active ? (
|
||||
<ProgressBody view={view} now={now} onOpen={() => onDrawer(true)} />
|
||||
) : (
|
||||
<ReadyBody
|
||||
view={view}
|
||||
canCapture={canCapture}
|
||||
canWrite={canWrite}
|
||||
pendingCapture={pendingCapture}
|
||||
onCapture={onCapture}
|
||||
onOpen={() => onDrawer(true)}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Drawer
|
||||
view={view}
|
||||
page={page}
|
||||
now={now}
|
||||
open={drawerOpen}
|
||||
expanded={expandedSnapshot}
|
||||
onExpand={onExpandSnapshot}
|
||||
onClose={() => onDrawer(false)}
|
||||
canCapture={canCapture}
|
||||
pendingCapture={pendingCapture}
|
||||
onCapture={onCapture}
|
||||
/>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export function ReleaseTargets() {
|
||||
const auth = useOptionalAuth()
|
||||
const [page, setPage] = useState<LibrarySnapshotList | null>(null)
|
||||
const [jobs, setJobs] = useState<LibraryCaptureJob[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [notice, setNotice] = useState<string | null>(null)
|
||||
const [scope, setScope] = useState<Scope>('internal')
|
||||
const [drawerOpen, setDrawerOpen] = useState(false)
|
||||
const [expandedSnapshot, setExpandedSnapshot] = useState<string | null>(null)
|
||||
const [pendingCapture, setPendingCapture] = useState(false)
|
||||
const [now, setNow] = useState(() => Date.now())
|
||||
|
||||
const load = useCallback(async (signal?: AbortSignal) => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const [snapshots, captures] = await Promise.all([
|
||||
fetchLibrarySnapshots(signal),
|
||||
fetchLibraryCaptures(signal),
|
||||
])
|
||||
setPage(snapshots)
|
||||
setJobs(captures)
|
||||
setNow(Date.now())
|
||||
setError(null)
|
||||
} catch (loadError) {
|
||||
if ((loadError as Error).name === 'AbortError') return
|
||||
setError(loadError instanceof Error ? loadError.message : '加载发布状态失败')
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const controller = new AbortController()
|
||||
void load(controller.signal)
|
||||
return () => controller.abort()
|
||||
}, [load])
|
||||
|
||||
const busy = jobs.some((job) => ACTIVE_STATES.includes(job.state))
|
||||
useEffect(() => {
|
||||
if (!busy) return
|
||||
const timer = window.setInterval(() => {
|
||||
setNow(Date.now())
|
||||
void load().catch(() => undefined)
|
||||
}, 3000)
|
||||
return () => window.clearInterval(timer)
|
||||
}, [busy, load])
|
||||
|
||||
const role = auth?.identity?.role
|
||||
const canWrite = role === 'engineer' || role === 'admin'
|
||||
const canCapture = canWrite && page?.capture_available === true
|
||||
|
||||
const startCapture = async () => {
|
||||
setPendingCapture(true)
|
||||
setNotice(null)
|
||||
try {
|
||||
const accepted = await enqueueLibraryCapture(scope)
|
||||
setNotice(
|
||||
accepted.reused
|
||||
? `该封存作业已存在:${scopeLabel(scope)} · ${accepted.capture_job}(${jobStateLabel[accepted.state] ?? accepted.state})`
|
||||
: `已投递封存:${scopeLabel(scope)} · ${accepted.capture_job}`
|
||||
)
|
||||
await load()
|
||||
} catch (captureError) {
|
||||
setNotice(captureError instanceof Error ? captureError.message : '发起封存失败')
|
||||
} finally {
|
||||
setPendingCapture(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<ReleaseTargetsView
|
||||
page={page}
|
||||
jobs={jobs}
|
||||
loading={loading}
|
||||
error={error}
|
||||
notice={notice}
|
||||
scope={scope}
|
||||
onScope={(next) => {
|
||||
setScope(next)
|
||||
setExpandedSnapshot(null)
|
||||
}}
|
||||
drawerOpen={drawerOpen}
|
||||
onDrawer={setDrawerOpen}
|
||||
expandedSnapshot={expandedSnapshot}
|
||||
onExpandSnapshot={setExpandedSnapshot}
|
||||
pendingCapture={pendingCapture}
|
||||
canCapture={canCapture}
|
||||
canWrite={canWrite}
|
||||
now={now}
|
||||
onRefresh={() => void load()}
|
||||
onCapture={() => void startCapture()}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
|
||||
import { BackupScheduleSection } from './BackupScheduleSection'
|
||||
import { LibraryStorageSection } from './LibraryStorageSection'
|
||||
import { QAModelSettings } from './QAModelSettings'
|
||||
import { MembersSection } from './MembersSection'
|
||||
import { DingtalkAccountStatus, SourceManagementDetails, SourceSettingsCard } from './SourceManagement'
|
||||
@@ -394,7 +395,12 @@ export function SystemSettingsView({
|
||||
) : null}
|
||||
{section === 'bindings' ? <RoutingBindingsSection /> : null}
|
||||
{section === 'production-bindings' ? <ProductionBindingsSection /> : null}
|
||||
{section === 'storage' ? <BackupScheduleSection /> : null}
|
||||
{section === 'storage' ? (
|
||||
<>
|
||||
<LibraryStorageSection />
|
||||
<BackupScheduleSection />
|
||||
</>
|
||||
) : null}
|
||||
{section === 'members' && identity?.role === 'admin' ? <MembersSection /> : null}
|
||||
{section === 'refresh' ? (
|
||||
<section className="settings-panel wide" id="settings-refresh">
|
||||
|
||||
@@ -54,6 +54,9 @@ export interface LibraryCaptureAccepted {
|
||||
capture_job: string
|
||||
scope: string
|
||||
state: string
|
||||
// true when the idempotency key matched an existing job; the response then
|
||||
// reports the stored job's scope, not the requested one.
|
||||
reused: boolean
|
||||
}
|
||||
|
||||
export interface LibrarySnapshotList {
|
||||
@@ -178,6 +181,7 @@ export async function enqueueLibraryCapture(scope: string): Promise<LibraryCaptu
|
||||
capture_job: text(value.capture_job),
|
||||
scope: text(value.scope),
|
||||
state: text(value.state),
|
||||
reused: bool(value.reused),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
.library-storage {
|
||||
border: 1px solid var(--border-base, #e2e8f0);
|
||||
border-radius: 10px;
|
||||
padding: 16px 18px;
|
||||
margin-bottom: 18px;
|
||||
background: #fff;
|
||||
}
|
||||
.library-storage header h3 {
|
||||
margin: 0 0 4px;
|
||||
font-size: 16px;
|
||||
}
|
||||
.library-storage header p {
|
||||
margin: 0 0 12px;
|
||||
font-size: 12px;
|
||||
color: var(--ink-mute, #64748b);
|
||||
line-height: 1.6;
|
||||
}
|
||||
.library-storage-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
||||
gap: 10px;
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
.library-storage-grid div {
|
||||
border: 1px solid #e6edf2;
|
||||
border-radius: 8px;
|
||||
padding: 9px 11px;
|
||||
}
|
||||
.library-storage-grid dt {
|
||||
font-size: 11px;
|
||||
color: var(--ink-mute, #64748b);
|
||||
}
|
||||
.library-storage-grid dd {
|
||||
margin: 3px 0 0;
|
||||
font-size: 16px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.library-storage-limits {
|
||||
margin: 0;
|
||||
padding-left: 18px;
|
||||
font-size: 12px;
|
||||
color: #986b24;
|
||||
line-height: 1.8;
|
||||
}
|
||||
.library-storage-hint {
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
color: var(--ink-mute, #64748b);
|
||||
}
|
||||
.library-storage-blocked {
|
||||
border: 1px solid #f3c2b8;
|
||||
background: #fff6f3;
|
||||
border-radius: 8px;
|
||||
padding: 10px 12px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.library-storage-blocked strong {
|
||||
display: block;
|
||||
font-size: 12px;
|
||||
color: #a03a1e;
|
||||
}
|
||||
.library-storage-blocked p {
|
||||
margin: 2px 0 0;
|
||||
font-size: 12px;
|
||||
color: #7c2d12;
|
||||
}
|
||||
@@ -1,315 +0,0 @@
|
||||
/* Whole-library versions: scope cards first, then a compact sealed-artifact table. */
|
||||
.library-versions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 18px;
|
||||
min-width: 0;
|
||||
padding: 24px;
|
||||
color: var(--ink-base);
|
||||
}
|
||||
.library-versions-header,
|
||||
.library-versions-toolbar,
|
||||
.library-snapshot-parts,
|
||||
.library-scope-card {
|
||||
background: var(--bg-panel, #fff);
|
||||
border: 1px solid var(--border-base, #e2e8f0);
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
min-width: 0;
|
||||
}
|
||||
.library-versions-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.library-versions h2 {
|
||||
margin: 0 0 6px;
|
||||
font-size: 22px;
|
||||
}
|
||||
.library-versions-sub {
|
||||
margin: 0;
|
||||
max-width: 68ch;
|
||||
color: var(--ink-mute, #64748b);
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.library-versions-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.library-versions-usage {
|
||||
font-size: 13px;
|
||||
color: var(--ink-mute, #64748b);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.library-versions-actions button,
|
||||
.library-versions-filters button {
|
||||
padding: 7px 14px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--border-base, #e2e8f0);
|
||||
background: var(--bg-panel, #fff);
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
.library-versions-actions button:disabled {
|
||||
cursor: progress;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.library-versions-blocked {
|
||||
border: 1px solid #f3c2b8;
|
||||
background: #fff6f3;
|
||||
border-radius: 10px;
|
||||
padding: 16px 20px;
|
||||
}
|
||||
.library-versions-blocked strong {
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
color: #a03a1e;
|
||||
}
|
||||
.library-versions-blocked p {
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
color: #7c2d12;
|
||||
}
|
||||
.library-versions-scopes {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
|
||||
gap: 16px;
|
||||
}
|
||||
.library-scope-card header {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
.library-scope-card h3 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
}
|
||||
.library-scope-state {
|
||||
font-size: 12px;
|
||||
padding: 2px 10px;
|
||||
border-radius: 999px;
|
||||
background: #ecfdf5;
|
||||
color: #047857;
|
||||
border: 1px solid #a7f3d0;
|
||||
}
|
||||
.library-scope-card.empty .library-scope-state {
|
||||
background: #f8fafc;
|
||||
color: #64748b;
|
||||
border-color: #e2e8f0;
|
||||
}
|
||||
.library-scope-time {
|
||||
margin: 8px 0 14px;
|
||||
font-size: 12px;
|
||||
color: var(--ink-mute, #64748b);
|
||||
}
|
||||
.library-scope-metrics {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
.library-scope-metrics div {
|
||||
border: 1px solid var(--border-base, #e2e8f0);
|
||||
border-radius: 8px;
|
||||
padding: 8px 10px;
|
||||
}
|
||||
.library-scope-metrics dt {
|
||||
font-size: 12px;
|
||||
color: var(--ink-mute, #64748b);
|
||||
}
|
||||
.library-scope-metrics dd {
|
||||
margin: 2px 0 0;
|
||||
font-size: 18px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.library-scope-id,
|
||||
.library-scope-hint {
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
color: var(--ink-mute, #64748b);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.library-scope-hint code,
|
||||
.library-scope-id code {
|
||||
font-size: 12px;
|
||||
background: #f1f5f9;
|
||||
border-radius: 5px;
|
||||
padding: 1px 6px;
|
||||
}
|
||||
.library-versions-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
padding: 12px 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.library-versions-filters {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
.library-versions-filters button.active {
|
||||
border-color: #2563eb;
|
||||
color: #1d4ed8;
|
||||
background: #eff6ff;
|
||||
}
|
||||
.library-versions-note {
|
||||
font-size: 12px;
|
||||
color: var(--ink-mute, #64748b);
|
||||
max-width: 70ch;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.library-scope-actions {
|
||||
margin-top: 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
font-size: 12px;
|
||||
color: var(--ink-mute, #64748b);
|
||||
}
|
||||
.library-scope-actions button {
|
||||
padding: 7px 14px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #2563eb;
|
||||
background: #eff6ff;
|
||||
color: #1d4ed8;
|
||||
cursor: pointer;
|
||||
}
|
||||
.library-scope-actions button:disabled {
|
||||
cursor: progress;
|
||||
opacity: 0.6;
|
||||
}
|
||||
.library-capture-notice {
|
||||
margin: 0;
|
||||
padding: 10px 14px;
|
||||
border-radius: 8px;
|
||||
background: #eff6ff;
|
||||
border: 1px solid #bfdbfe;
|
||||
color: #1d4ed8;
|
||||
font-size: 13px;
|
||||
}
|
||||
.library-capture-jobs {
|
||||
background: var(--bg-panel, #fff);
|
||||
border: 1px solid var(--border-base, #e2e8f0);
|
||||
border-radius: 10px;
|
||||
padding: 16px 20px;
|
||||
}
|
||||
.library-capture-jobs h3 {
|
||||
margin: 0 0 10px;
|
||||
font-size: 15px;
|
||||
}
|
||||
.library-capture-error {
|
||||
max-width: 360px;
|
||||
overflow-wrap: anywhere;
|
||||
white-space: normal;
|
||||
}
|
||||
.library-versions-accounting {
|
||||
justify-content: flex-start;
|
||||
font-size: 12px;
|
||||
color: var(--ink-mute, #64748b);
|
||||
line-height: 1.6;
|
||||
}
|
||||
.library-versions-empty {
|
||||
margin: 0;
|
||||
padding: 24px;
|
||||
border: 1px dashed var(--border-base, #e2e8f0);
|
||||
border-radius: 10px;
|
||||
color: var(--ink-mute, #64748b);
|
||||
font-size: 13px;
|
||||
}
|
||||
.library-versions-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
background: var(--bg-panel, #fff);
|
||||
border: 1px solid var(--border-base, #e2e8f0);
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
font-size: 13px;
|
||||
}
|
||||
.library-versions-table th,
|
||||
.library-versions-table td {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--border-base, #eef2f7);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.library-versions-table th {
|
||||
font-weight: 600;
|
||||
font-size: 12px;
|
||||
color: var(--ink-mute, #64748b);
|
||||
background: #f8fafc;
|
||||
}
|
||||
.library-versions-table td {
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.library-snapshot-toggle {
|
||||
border: 1px solid var(--border-base, #e2e8f0);
|
||||
border-radius: 7px;
|
||||
background: #fff;
|
||||
padding: 4px 8px;
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
color: inherit;
|
||||
}
|
||||
.library-snapshot-parts header {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
margin-bottom: 12px;
|
||||
font-size: 12px;
|
||||
color: var(--ink-mute, #64748b);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.library-snapshot-parts header strong {
|
||||
font-size: 14px;
|
||||
color: var(--ink-base);
|
||||
}
|
||||
.library-snapshot-parts ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.library-snapshot-parts li {
|
||||
display: grid;
|
||||
grid-template-columns: 90px minmax(140px, 2fr) 80px 90px 110px;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
font-size: 12px;
|
||||
padding: 6px 8px;
|
||||
border-radius: 7px;
|
||||
background: #f8fafc;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.library-part-kind {
|
||||
font-size: 11px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.04em;
|
||||
color: var(--ink-mute, #64748b);
|
||||
}
|
||||
.library-part-name {
|
||||
font-weight: 600;
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.library-versions {
|
||||
padding: 12px;
|
||||
}
|
||||
.library-versions-table {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
}
|
||||
.library-snapshot-parts li {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.library-scope-metrics {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,600 @@
|
||||
/* 发布管理:按已确认稿的布局与色系(浅底、青绿主色、白色圆角面板)。 */
|
||||
.release-targets {
|
||||
--rel-ink: #26394a;
|
||||
--rel-muted: #7b8d9a;
|
||||
--rel-line: #dce6ed;
|
||||
--rel-teal: #269e88;
|
||||
--rel-teal-dark: #228b75;
|
||||
--rel-teal-soft: #eaf8f3;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
padding: 24px 28px 40px;
|
||||
color: var(--rel-ink);
|
||||
min-width: 0;
|
||||
}
|
||||
.release-targets h1 {
|
||||
margin: 0 0 4px;
|
||||
font-size: 28px;
|
||||
}
|
||||
.release-targets h2 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
}
|
||||
.release-targets h3 {
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
.rel-head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.rel-head p {
|
||||
margin: 0;
|
||||
color: var(--rel-muted);
|
||||
font-size: 13px;
|
||||
}
|
||||
.rel-head-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.release-targets button {
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
background: #fff;
|
||||
border: 1px solid #d6e2e8;
|
||||
border-radius: 7px;
|
||||
padding: 7px 14px;
|
||||
color: #41596b;
|
||||
}
|
||||
.release-targets button:hover:not(:disabled) {
|
||||
background: #edf8f5;
|
||||
}
|
||||
.release-targets button:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
.rel-primary {
|
||||
background: var(--rel-teal) !important;
|
||||
border-color: var(--rel-teal) !important;
|
||||
color: #fff !important;
|
||||
font-weight: 600;
|
||||
}
|
||||
.rel-secondary {
|
||||
background: #fff;
|
||||
}
|
||||
.rel-tabs {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.rel-tab {
|
||||
width: 310px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 13px 18px !important;
|
||||
text-align: left;
|
||||
border-radius: 9px !important;
|
||||
}
|
||||
.rel-tab strong {
|
||||
font-size: 16px;
|
||||
}
|
||||
.rel-tab.selected {
|
||||
background: var(--rel-teal-soft) !important;
|
||||
border: 2px solid var(--rel-teal) !important;
|
||||
}
|
||||
.rel-pill {
|
||||
border-radius: 5px;
|
||||
font-size: 12px;
|
||||
padding: 2px 9px;
|
||||
white-space: nowrap;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
.rel-pill.green {
|
||||
color: #228368;
|
||||
background: #e6f5ef;
|
||||
border-color: #bfe6d8;
|
||||
}
|
||||
.rel-pill.blue {
|
||||
color: #387eb8;
|
||||
background: #eaf3fc;
|
||||
border-color: #c6ddf1;
|
||||
}
|
||||
.rel-pill.gray {
|
||||
color: #7c8d99;
|
||||
background: #eff3f6;
|
||||
border-color: #dde5ea;
|
||||
}
|
||||
.rel-pill.red {
|
||||
color: #b4381f;
|
||||
background: #fdecea;
|
||||
border-color: #f3c6bc;
|
||||
}
|
||||
.rel-panel {
|
||||
background: #fff;
|
||||
border: 1px solid var(--rel-line);
|
||||
border-radius: 12px;
|
||||
padding: 20px 22px;
|
||||
min-width: 0;
|
||||
}
|
||||
.rel-between {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 14px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.rel-panel-head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.rel-panel-head p {
|
||||
margin: 3px 0 0;
|
||||
font-size: 12px;
|
||||
color: var(--rel-muted);
|
||||
}
|
||||
.rel-jobhead h2 {
|
||||
font-size: 19px;
|
||||
}
|
||||
.rel-versionline {
|
||||
margin: 12px 0 0;
|
||||
color: #496579;
|
||||
font-size: 14px;
|
||||
}
|
||||
.rel-versionline b {
|
||||
color: var(--rel-teal-dark);
|
||||
}
|
||||
.rel-unknown {
|
||||
color: #9aa9b4 !important;
|
||||
font-weight: 500;
|
||||
}
|
||||
.rel-metrics {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
gap: 10px;
|
||||
margin: 16px 0 0;
|
||||
}
|
||||
.rel-metrics div {
|
||||
border: 1px solid #e6edf2;
|
||||
border-radius: 9px;
|
||||
padding: 10px 12px;
|
||||
}
|
||||
.rel-metrics dt {
|
||||
font-size: 12px;
|
||||
color: var(--rel-muted);
|
||||
}
|
||||
.rel-metrics dd {
|
||||
margin: 4px 0 0;
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
}
|
||||
.rel-checklist {
|
||||
list-style: none;
|
||||
display: flex;
|
||||
gap: 22px;
|
||||
flex-wrap: wrap;
|
||||
margin: 14px 0 0;
|
||||
padding: 11px 14px;
|
||||
border-radius: 9px;
|
||||
background: #f2faf6;
|
||||
font-size: 13px;
|
||||
color: #228368;
|
||||
}
|
||||
.rel-checklist .unknown {
|
||||
color: #8a9aa6;
|
||||
}
|
||||
.rel-footnote {
|
||||
margin: 12px 0 0;
|
||||
font-size: 12px;
|
||||
color: var(--rel-muted);
|
||||
line-height: 1.6;
|
||||
}
|
||||
.rel-grid {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
|
||||
gap: 16px;
|
||||
}
|
||||
.rel-grid-4 {
|
||||
grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
|
||||
}
|
||||
.rel-changes table,
|
||||
.rel-details table,
|
||||
.rel-drawer-table,
|
||||
.rel-parts table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 13px;
|
||||
}
|
||||
.rel-changes th,
|
||||
.rel-details th,
|
||||
.rel-drawer-table th,
|
||||
.rel-parts th {
|
||||
text-align: left;
|
||||
background: #f8fafb;
|
||||
color: #8a9aa6;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
padding: 9px 12px;
|
||||
}
|
||||
.rel-changes td,
|
||||
.rel-details td,
|
||||
.rel-drawer-table td,
|
||||
.rel-parts td {
|
||||
padding: 10px 12px;
|
||||
border-top: 1px solid #eef2f5;
|
||||
vertical-align: top;
|
||||
}
|
||||
.rel-table-empty {
|
||||
color: var(--rel-muted);
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
padding: 22px 12px !important;
|
||||
}
|
||||
.rel-protection dl {
|
||||
display: grid;
|
||||
grid-template-columns: auto 1fr;
|
||||
gap: 8px 14px;
|
||||
margin: 0 0 12px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.rel-protection dt {
|
||||
color: var(--rel-muted);
|
||||
}
|
||||
.rel-protection dd {
|
||||
margin: 0;
|
||||
color: var(--rel-ink);
|
||||
}
|
||||
.rel-hint {
|
||||
margin: 0 0 10px;
|
||||
font-size: 12px;
|
||||
color: var(--rel-muted);
|
||||
line-height: 1.6;
|
||||
}
|
||||
.rel-warn {
|
||||
margin: 12px 0 0;
|
||||
font-size: 12px;
|
||||
color: #986b24;
|
||||
background: #fff8e8;
|
||||
border: 1px solid #ead7b0;
|
||||
border-radius: 7px;
|
||||
padding: 8px 10px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.rel-notice {
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
color: #986b24;
|
||||
background: #fff8e8;
|
||||
border: 1px solid #ead7b0;
|
||||
border-radius: 8px;
|
||||
padding: 9px 12px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.rel-blocked {
|
||||
border: 1px solid #f3c2b8;
|
||||
background: #fff6f3;
|
||||
border-radius: 10px;
|
||||
padding: 12px 16px;
|
||||
}
|
||||
.rel-blocked strong {
|
||||
display: block;
|
||||
color: #a03a1e;
|
||||
font-size: 13px;
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
.rel-blocked p {
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
color: #7c2d12;
|
||||
}
|
||||
|
||||
/* 阶段条 */
|
||||
.rel-steps {
|
||||
display: flex;
|
||||
align-items: stretch;
|
||||
gap: 8px;
|
||||
list-style: none;
|
||||
margin: 16px 0 6px;
|
||||
padding: 0;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.rel-step {
|
||||
flex: 1 1 150px;
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
padding: 11px 12px;
|
||||
border-radius: 8px;
|
||||
background: #f5f8fa;
|
||||
border: 1px solid #e1e8ed;
|
||||
color: #8a9aa6;
|
||||
font-size: 13px;
|
||||
}
|
||||
.rel-step strong {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.rel-step small {
|
||||
font-size: 11px;
|
||||
}
|
||||
.rel-step.done {
|
||||
color: #25886b;
|
||||
background: #f0faf5;
|
||||
}
|
||||
.rel-step.live {
|
||||
color: #167f70;
|
||||
background: #e9f8f4;
|
||||
border-color: #4eb49f;
|
||||
font-weight: 700;
|
||||
}
|
||||
.rel-step-mark {
|
||||
position: absolute;
|
||||
top: 9px;
|
||||
right: 12px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.rel-step-arrow {
|
||||
display: none;
|
||||
}
|
||||
.rel-steps-note {
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
color: var(--rel-muted);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
/* 仅剩的次级操作:封存测试版本 */
|
||||
.rel-seal {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
flex-wrap: wrap;
|
||||
background: #fbfdfe;
|
||||
}
|
||||
.rel-seal p {
|
||||
margin: 6px 0 0;
|
||||
font-size: 12px;
|
||||
color: var(--rel-muted);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
/* 同步中 */
|
||||
.rel-jobmeta {
|
||||
margin: 8px 0 0;
|
||||
font-size: 12px;
|
||||
color: var(--rel-muted);
|
||||
}
|
||||
.rel-progress-foot {
|
||||
margin-top: 12px;
|
||||
border-top: 1px solid #eef2f5;
|
||||
padding-top: 10px;
|
||||
font-size: 12px;
|
||||
color: var(--rel-muted);
|
||||
}
|
||||
.rel-link {
|
||||
border: 0 !important;
|
||||
background: transparent !important;
|
||||
padding: 2px 4px !important;
|
||||
color: #2b7fa6 !important;
|
||||
font-size: 12px;
|
||||
}
|
||||
.rel-datacard {
|
||||
border: 1px solid #dce6ed;
|
||||
border-radius: 10px;
|
||||
padding: 14px 16px;
|
||||
background: #fff;
|
||||
}
|
||||
.rel-datacard header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
.rel-datacount {
|
||||
margin: 10px 0 6px;
|
||||
font-size: 13px;
|
||||
color: var(--rel-muted);
|
||||
}
|
||||
.rel-datacount strong {
|
||||
font-size: 24px;
|
||||
color: #9aa9b4;
|
||||
margin-right: 4px;
|
||||
}
|
||||
.rel-progress {
|
||||
height: 6px;
|
||||
border-radius: 8px;
|
||||
background: #edf1f4;
|
||||
overflow: hidden;
|
||||
}
|
||||
.rel-progress span {
|
||||
display: block;
|
||||
height: 100%;
|
||||
background: var(--rel-teal);
|
||||
}
|
||||
.rel-datadetail {
|
||||
margin: 10px 0 0;
|
||||
font-size: 12px;
|
||||
color: var(--rel-muted);
|
||||
line-height: 1.55;
|
||||
}
|
||||
.rel-filters {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
}
|
||||
.rel-filters button {
|
||||
font-size: 12px;
|
||||
padding: 4px 11px;
|
||||
}
|
||||
.rel-filters .chosen {
|
||||
color: #168b73;
|
||||
background: #ebf8f3;
|
||||
border-color: #a6d7c8;
|
||||
}
|
||||
.rel-log {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
background: #f9fbfc;
|
||||
border-top: 1px solid #eef2f5;
|
||||
padding: 10px 12px;
|
||||
font-size: 12px;
|
||||
color: #7b8e9c;
|
||||
}
|
||||
|
||||
/* 版本与快照抽屉 */
|
||||
.rel-drawer-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(20, 52, 74, 0.4);
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
z-index: 40;
|
||||
}
|
||||
.rel-drawer {
|
||||
width: min(1024px, 92vw);
|
||||
height: 100%;
|
||||
overflow-y: auto;
|
||||
background: #fff;
|
||||
border-left: 1px solid #dce6ed;
|
||||
box-shadow: -12px 0 32px rgba(19, 44, 61, 0.18);
|
||||
padding: 22px 26px 28px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
}
|
||||
.rel-drawer-head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
.rel-drawer-head p {
|
||||
margin: 4px 0 0;
|
||||
font-size: 12px;
|
||||
color: var(--rel-muted);
|
||||
}
|
||||
.rel-close {
|
||||
padding: 5px 10px !important;
|
||||
font-size: 12px;
|
||||
}
|
||||
.rel-drawer-table td small {
|
||||
display: block;
|
||||
color: var(--rel-muted);
|
||||
font-size: 11px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
.rel-drawer-table tr.selected td {
|
||||
background: #f4fbf8;
|
||||
}
|
||||
.rel-snapshot {
|
||||
border: 1px solid #cfe6dd;
|
||||
border-radius: 10px;
|
||||
padding: 16px 18px;
|
||||
background: #fbfefd;
|
||||
}
|
||||
.rel-snapshot header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.rel-snapshot-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 10px;
|
||||
margin: 12px 0;
|
||||
}
|
||||
.rel-snapshot-grid div {
|
||||
border: 1px solid #e2eef7;
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
padding: 9px 11px;
|
||||
}
|
||||
.rel-snapshot-grid dt {
|
||||
font-size: 11px;
|
||||
color: var(--rel-muted);
|
||||
}
|
||||
.rel-snapshot-grid dd {
|
||||
margin: 4px 0 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
.rel-parts {
|
||||
margin: 8px 0 12px;
|
||||
}
|
||||
.rel-parts summary {
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
color: #2b7fa6;
|
||||
}
|
||||
.rel-parts table {
|
||||
margin-top: 8px;
|
||||
border: 1px solid #e6edf2;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.rel-drawer-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.rel-danger {
|
||||
border-color: #e7b4a8 !important;
|
||||
color: #b4381f !important;
|
||||
}
|
||||
.rel-drawer-foot {
|
||||
margin-top: auto;
|
||||
border-top: 1px solid #eef2f5;
|
||||
padding-top: 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 14px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.rel-drawer-foot p {
|
||||
margin: 4px 0 0;
|
||||
font-size: 12px;
|
||||
color: var(--rel-muted);
|
||||
line-height: 1.6;
|
||||
max-width: 62ch;
|
||||
}
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.rel-grid {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
.rel-metrics {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.release-targets {
|
||||
padding: 14px;
|
||||
}
|
||||
.rel-tab {
|
||||
width: 100%;
|
||||
}
|
||||
.rel-drawer {
|
||||
width: 100vw;
|
||||
padding: 16px;
|
||||
}
|
||||
.rel-changes table,
|
||||
.rel-details table {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ export type ModuleId =
|
||||
| 'knowledge'
|
||||
| 'tasks'
|
||||
| 'releases'
|
||||
| 'library'
|
||||
| 'settings'
|
||||
| 'versions'
|
||||
| 'qaops'
|
||||
@@ -14,7 +13,7 @@ export interface WorkspaceState {
|
||||
activeTab: ModuleId
|
||||
}
|
||||
|
||||
const moduleIds = new Set<ModuleId>(['dashboard', 'tasks', 'releases', 'library', 'settings', 'qaops'])
|
||||
const moduleIds = new Set<ModuleId>(['dashboard', 'tasks', 'releases', 'settings', 'qaops'])
|
||||
|
||||
export const initialWorkspace: WorkspaceState = {
|
||||
openTabs: ['dashboard'],
|
||||
|
||||
Reference in New Issue
Block a user