feat: 知识治理平台(含已验证发布/回滚契约)
全栈知识治理平台首次入库(P1-P10 + 发布链路模拟验证闭环): - 治理核心:源目录/变更集/人工审核/发布批次/发布执行(fail-closed 闸口) - 测试通道:WeKnora 测试 KB 上传/轮询/验收;poll 完成时写入 parser_generation/index_generation,修复 manual/seed 路径发布闸口永久拦截 - 发布适配器 v071(本地 source=测试角色 / 云端 target=生产角色 模拟验证通过): * ES 导出/导入 mapping 自适应(.keyword 子字段、可选 tenant_id) * OSS locator 支持嵌套 scheme;chunks.seq_id 由目标序列分配 * bundle 归档同身份重试原子替换;verifier 按 bundle chunk_type 计数 * 回滚 job payload 支持 prior_execution_id(strict 解码) - 三通道发布+回滚演练实测:publish 4/4 verified,检索命中, rollback 4/4 rolled_back,目标端 PG is_enabled=false、ES is_enabled=false - 前端 A·Data-console 风格全站统一,120 用例通过 - 门禁:go vet / go test 全包通过,gofmt 干净
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package governance
|
||||
|
||||
import "time"
|
||||
|
||||
// ConfirmCatalogChangeSetRequest is the P3 human confirmation: explicit items of
|
||||
// one planned ChangeSet are executed into publications and processing jobs.
|
||||
type ConfirmCatalogChangeSetRequest struct {
|
||||
ChangeSetID string
|
||||
ItemSeqs []int64
|
||||
OperatorRef string
|
||||
Reason string
|
||||
InternalTargetKBID string
|
||||
ExternalTargetKBID string
|
||||
Now time.Time
|
||||
}
|
||||
|
||||
type ConfirmCatalogChangeSetResult struct {
|
||||
ChangeSetID string `json:"change_set_id"`
|
||||
ConfirmedItems int `json:"confirmed_items"`
|
||||
UploadsCreated int `json:"uploads_created"`
|
||||
UploadsExisting int `json:"uploads_existing"`
|
||||
RemovalsRequested int `json:"removals_requested"`
|
||||
SkippedNoArtifact int `json:"skipped_no_artifact"`
|
||||
SkippedNoTarget int `json:"skipped_no_target"`
|
||||
NoChangeIgnored int `json:"no_change_ignored"`
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package governance
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDomainModelContractDeclaresCanonicalObjectsAndCurrentMappings(t *testing.T) {
|
||||
content, err := os.ReadFile("../../docs/DOMAIN_MODEL.md")
|
||||
if err != nil {
|
||||
t.Fatalf("read domain model contract: %v", err)
|
||||
}
|
||||
|
||||
text := string(content)
|
||||
for _, required := range []string{
|
||||
"## Source",
|
||||
"## SourceFile",
|
||||
"## Snapshot",
|
||||
"## ChangeSet",
|
||||
"## Job",
|
||||
"## Release",
|
||||
"SourceConnection → SourceItem → SourceItemVersion → ContentObject",
|
||||
"SourceConnection → SourceCatalogSnapshot → SourceCatalogNode",
|
||||
"SourceCatalogChangeSet → SourceCatalogChangeItem",
|
||||
"ReleaseBatch → ReleaseExecution → ReleaseItemExecution",
|
||||
"source_items",
|
||||
"source_item_versions",
|
||||
"content_objects",
|
||||
"source_catalog_snapshots",
|
||||
"source_catalog_change_sets",
|
||||
"jobs",
|
||||
"release_executions",
|
||||
"Current implementation gaps",
|
||||
} {
|
||||
if !strings.Contains(text, required) {
|
||||
t.Fatalf("domain model contract is missing %q", required)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package governance
|
||||
|
||||
import "time"
|
||||
|
||||
// JobFailure is one terminal-attempt dead-letter projection (P6). It never
|
||||
// replaces the original jobs audit row; it points at it.
|
||||
type JobFailure struct {
|
||||
ID string `json:"id"`
|
||||
JobID string `json:"job_id"`
|
||||
JobType string `json:"job_type"`
|
||||
PublicationID string `json:"publication_id,omitempty"`
|
||||
SourceItemID string `json:"source_item_id,omitempty"`
|
||||
ErrorCode string `json:"error_code"`
|
||||
Attempt int `json:"attempt"`
|
||||
MaxAttempts int `json:"max_attempts_at_failure"`
|
||||
ChangeSetID string `json:"change_set_id,omitempty"`
|
||||
Action string `json:"action,omitempty"`
|
||||
TargetKBID string `json:"target_kb_id,omitempty"`
|
||||
State string `json:"state"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type JobFailureFilter struct {
|
||||
State string // open | requeued | abandoned | "" (defaults to open)
|
||||
Limit int
|
||||
Offset int
|
||||
}
|
||||
|
||||
type JobFailurePage struct {
|
||||
Items []JobFailure `json:"items"`
|
||||
Total int `json:"total"`
|
||||
Limit int `json:"limit"`
|
||||
Offset int `json:"offset"`
|
||||
}
|
||||
|
||||
const (
|
||||
RetryStarted = "started"
|
||||
RetryAlreadyRunning = "already_running"
|
||||
RetryNotRetryable = "not_retryable"
|
||||
)
|
||||
|
||||
// RetryPublicationsBatchRequest is the server-side batch retry (P6): one
|
||||
// atomic operation covering 1..100 publications with per-item outcomes.
|
||||
type RetryPublicationsBatchRequest struct {
|
||||
PublicationIDs []string `json:"publication_ids"`
|
||||
OperatorRef string `json:"operator_ref"`
|
||||
Reason string `json:"reason"`
|
||||
Now time.Time `json:"-"`
|
||||
}
|
||||
|
||||
type RetryOutcome struct {
|
||||
PublicationID string `json:"publication_id"`
|
||||
Result string `json:"result"`
|
||||
Detail string `json:"detail,omitempty"`
|
||||
}
|
||||
|
||||
type RetryPublicationsBatchResult struct {
|
||||
BatchKey string `json:"batch_key"`
|
||||
Total int `json:"total"`
|
||||
Started int `json:"started"`
|
||||
AlreadyRunning int `json:"already_running"`
|
||||
NotRetryable int `json:"not_retryable"`
|
||||
Outcomes []RetryOutcome `json:"outcomes"`
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
package governance
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SourceType string
|
||||
|
||||
const (
|
||||
SourceTypePP SourceType = "pp"
|
||||
SourceTypeAList SourceType = "alist"
|
||||
SourceTypeDingTalk SourceType = "dingtalk"
|
||||
SourceTypeManual SourceType = "manual"
|
||||
)
|
||||
|
||||
func (sourceType SourceType) Valid() bool {
|
||||
switch sourceType {
|
||||
case SourceTypePP, SourceTypeAList, SourceTypeDingTalk, SourceTypeManual:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type ItemType string
|
||||
|
||||
const (
|
||||
ItemTypeDocument ItemType = "document"
|
||||
ItemTypeFile ItemType = "file"
|
||||
ItemTypeLink ItemType = "link"
|
||||
ItemTypeVideo ItemType = "video"
|
||||
)
|
||||
|
||||
type Visibility string
|
||||
|
||||
const (
|
||||
VisibilityInternal Visibility = "internal"
|
||||
VisibilityExternal Visibility = "external"
|
||||
VisibilityBoth Visibility = "both"
|
||||
VisibilityBlocked Visibility = "blocked"
|
||||
)
|
||||
|
||||
type VisibilityOrigin string
|
||||
|
||||
const (
|
||||
VisibilityOriginPPPublicTag VisibilityOrigin = "pp_public_tag"
|
||||
VisibilityOriginConfiguredScope VisibilityOrigin = "configured_scope"
|
||||
VisibilityOriginManual VisibilityOrigin = "manual"
|
||||
)
|
||||
|
||||
type SourceChange string
|
||||
|
||||
const (
|
||||
SourceChangeUnchanged SourceChange = "unchanged"
|
||||
SourceChangeAdded SourceChange = "added"
|
||||
SourceChangeUpdated SourceChange = "updated"
|
||||
SourceChangeDeleted SourceChange = "deleted"
|
||||
SourceChangeUnavailable SourceChange = "unavailable"
|
||||
)
|
||||
|
||||
func (state SourceChange) Valid() bool {
|
||||
switch state {
|
||||
case SourceChangeUnchanged, SourceChangeAdded, SourceChangeUpdated, SourceChangeDeleted, SourceChangeUnavailable:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type ReviewState string
|
||||
|
||||
const (
|
||||
ReviewPending ReviewState = "pending"
|
||||
ReviewApproved ReviewState = "approved"
|
||||
ReviewRejected ReviewState = "rejected"
|
||||
ReviewNotRequired ReviewState = "not_required"
|
||||
)
|
||||
|
||||
func (state ReviewState) Valid() bool {
|
||||
switch state {
|
||||
case ReviewPending, ReviewApproved, ReviewRejected, ReviewNotRequired:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type ContentState string
|
||||
|
||||
const (
|
||||
ContentUnknown ContentState = "unknown"
|
||||
ContentDownloading ContentState = "downloading"
|
||||
ContentVerified ContentState = "verified"
|
||||
ContentInvalid ContentState = "invalid"
|
||||
ContentOverLimit ContentState = "over_limit"
|
||||
ContentFailed ContentState = "failed"
|
||||
)
|
||||
|
||||
func (state ContentState) Valid() bool {
|
||||
switch state {
|
||||
case ContentUnknown, ContentDownloading, ContentVerified, ContentInvalid, ContentOverLimit, ContentFailed:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type IngestState string
|
||||
|
||||
const (
|
||||
IngestPending IngestState = "pending"
|
||||
IngestUploading IngestState = "uploading"
|
||||
IngestUploaded IngestState = "uploaded"
|
||||
IngestFailed IngestState = "failed"
|
||||
)
|
||||
|
||||
func (state IngestState) Valid() bool {
|
||||
switch state {
|
||||
case IngestPending, IngestUploading, IngestUploaded, IngestFailed:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type ProcessingState string
|
||||
|
||||
const (
|
||||
ProcessingPending ProcessingState = "pending"
|
||||
ProcessingProcessing ProcessingState = "processing"
|
||||
ProcessingFinalizing ProcessingState = "finalizing"
|
||||
ProcessingCompleted ProcessingState = "completed"
|
||||
ProcessingFailed ProcessingState = "failed"
|
||||
ProcessingStalled ProcessingState = "stalled"
|
||||
)
|
||||
|
||||
func (state ProcessingState) Valid() bool {
|
||||
switch state {
|
||||
case ProcessingPending, ProcessingProcessing, ProcessingFinalizing, ProcessingCompleted, ProcessingFailed, ProcessingStalled:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type RetrievalState string
|
||||
|
||||
const (
|
||||
RetrievalUnpublished RetrievalState = "unpublished"
|
||||
RetrievalEnabled RetrievalState = "enabled"
|
||||
RetrievalDisabling RetrievalState = "disabling"
|
||||
RetrievalDisabled RetrievalState = "disabled"
|
||||
RetrievalEnabling RetrievalState = "enabling"
|
||||
RetrievalFailed RetrievalState = "failed"
|
||||
)
|
||||
|
||||
func (state RetrievalState) Valid() bool {
|
||||
switch state {
|
||||
case RetrievalUnpublished, RetrievalEnabled, RetrievalDisabling, RetrievalDisabled, RetrievalEnabling, RetrievalFailed:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type AcceptanceState string
|
||||
|
||||
const (
|
||||
AcceptancePending AcceptanceState = "pending"
|
||||
AcceptancePassed AcceptanceState = "passed"
|
||||
AcceptanceFailed AcceptanceState = "failed"
|
||||
AcceptanceManualRequired AcceptanceState = "manual_required"
|
||||
)
|
||||
|
||||
func (state AcceptanceState) Valid() bool {
|
||||
switch state {
|
||||
case AcceptancePending, AcceptancePassed, AcceptanceFailed, AcceptanceManualRequired:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func ValidSHA256(value string) bool {
|
||||
if len(value) != 64 {
|
||||
return false
|
||||
}
|
||||
for _, character := range value {
|
||||
if !((character >= '0' && character <= '9') || (character >= 'a' && character <= 'f')) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
type SourceConnection struct {
|
||||
ID string
|
||||
Type SourceType
|
||||
Name string
|
||||
BaseURL string
|
||||
SecretRef string
|
||||
Enabled bool
|
||||
Schedule json.RawMessage
|
||||
LastHealth json.RawMessage
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type SourceItem struct {
|
||||
ID string
|
||||
SourceConnectionID string
|
||||
StableExternalID string
|
||||
CanonicalURIHash string
|
||||
ParentExternalID string
|
||||
NormalizedPath string
|
||||
Title string
|
||||
ItemType ItemType
|
||||
SizeBytes *int64
|
||||
MIME string
|
||||
Revision string
|
||||
UpdatedAtSource *time.Time
|
||||
Visibility Visibility
|
||||
VisibilityOrigin VisibilityOrigin
|
||||
LastSeenScanID string
|
||||
SourceChange SourceChange
|
||||
AbsenceStreak int
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type ContentObject struct {
|
||||
ID string
|
||||
SHA256 string
|
||||
SizeBytes int64
|
||||
MIME string
|
||||
ValidatedFormat string
|
||||
LocalSpoolRef string
|
||||
State ContentState
|
||||
FirstDiscoveredAt time.Time
|
||||
LastDiscoveredAt time.Time
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type SourceItemVersion struct {
|
||||
ID string
|
||||
SourceItemID string
|
||||
Revision string
|
||||
ContentObjectID *string
|
||||
ContentState ContentState
|
||||
DownloadError string
|
||||
RawRecordSummary json.RawMessage
|
||||
SourceUpdatedAt *time.Time
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type Publication struct {
|
||||
ID string
|
||||
SourceItemVersionID string
|
||||
TestKBID string
|
||||
KnowledgeID string
|
||||
IngestState IngestState
|
||||
ProcessingState ProcessingState
|
||||
RetrievalState RetrievalState
|
||||
ParserGeneration string
|
||||
IndexGeneration string
|
||||
LastError string
|
||||
RetryCount int
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
type AcceptanceResult struct {
|
||||
ID string
|
||||
PublicationID string
|
||||
RunID string
|
||||
CheckType string
|
||||
State AcceptanceState
|
||||
PolicyVersion string
|
||||
EvidenceSummary json.RawMessage
|
||||
ObservedAt time.Time
|
||||
CreatedAt time.Time
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package governance
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDeclaredWorkflowStatesAreValid(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
valid bool
|
||||
}{
|
||||
{"source type", SourceTypeManual.Valid() && SourceTypePP.Valid() && !SourceType("__invalid__").Valid()},
|
||||
{"source change", SourceChangeAdded.Valid() && !SourceChange("__invalid__").Valid()},
|
||||
{"review", ReviewPending.Valid() && !ReviewState("__invalid__").Valid()},
|
||||
{"content", ContentVerified.Valid() && !ContentState("__invalid__").Valid()},
|
||||
{"ingest", IngestUploaded.Valid() && !IngestState("__invalid__").Valid()},
|
||||
{"processing", ProcessingCompleted.Valid() && !ProcessingState("__invalid__").Valid()},
|
||||
{"retrieval", RetrievalEnabled.Valid() && !RetrievalState("__invalid__").Valid()},
|
||||
{"acceptance", AcceptanceManualRequired.Valid() && AcceptancePassed.Valid() && AcceptanceFailed.Valid() && !AcceptanceState("__invalid__").Valid()},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if !tt.valid {
|
||||
t.Fatal("declared state must be valid and unknown state must be invalid")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidSHA256RequiresCanonicalDigest(t *testing.T) {
|
||||
valid := "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
value string
|
||||
want bool
|
||||
}{
|
||||
{"canonical", valid, true},
|
||||
{"short", valid[:63], false},
|
||||
{"uppercase", "A" + valid[1:], false},
|
||||
{"non hex", "g" + valid[1:], false},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := ValidSHA256(tt.value); got != tt.want {
|
||||
t.Fatalf("ValidSHA256() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestModelsKeepSourceVersionContentAndPublicationSeparate(t *testing.T) {
|
||||
contentID := "content-1"
|
||||
item := SourceItem{ID: "item-1", StableExternalID: "pp-42", SourceChange: SourceChangeAdded}
|
||||
version := SourceItemVersion{ID: "version-1", SourceItemID: item.ID, ContentObjectID: &contentID, ContentState: ContentVerified}
|
||||
publication := Publication{ID: "publication-1", SourceItemVersionID: version.ID, IngestState: IngestUploaded, ProcessingState: ProcessingCompleted, RetrievalState: RetrievalEnabled}
|
||||
|
||||
if version.SourceItemID != item.ID || *version.ContentObjectID != contentID || publication.SourceItemVersionID != version.ID {
|
||||
t.Fatal("source, version, content, and publication identities must remain independently linked")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package governance
|
||||
|
||||
import "time"
|
||||
|
||||
type MonitorHost struct {
|
||||
CPUPercent float64 `json:"cpu_percent"`
|
||||
MemoryUsedBytes int64 `json:"memory_used_bytes"`
|
||||
MemoryTotalBytes int64 `json:"memory_total_bytes"`
|
||||
DiskUsedBytes int64 `json:"disk_used_bytes"`
|
||||
DiskTotalBytes int64 `json:"disk_total_bytes"`
|
||||
GPUState string `json:"gpu_state"`
|
||||
GPUDetail string `json:"gpu_detail"`
|
||||
Simulated bool `json:"simulated"`
|
||||
}
|
||||
|
||||
type MonitorService struct {
|
||||
Key string `json:"key"`
|
||||
Name string `json:"name"`
|
||||
State string `json:"state"`
|
||||
Detail string `json:"detail"`
|
||||
LatencyMS int `json:"latency_ms"`
|
||||
ObservedAt time.Time `json:"observed_at"`
|
||||
Simulated bool `json:"simulated"`
|
||||
}
|
||||
|
||||
// ServiceHealth (P10) separates "process reachable" (Liveness) from "can
|
||||
// accept work" (Readiness). not_configured and not_applicable are explicit and
|
||||
// never collapse into unknown.
|
||||
type ServiceHealth struct {
|
||||
Key string `json:"key"`
|
||||
Name string `json:"name"`
|
||||
Liveness string `json:"liveness"`
|
||||
Readiness string `json:"readiness"`
|
||||
Reason string `json:"reason"`
|
||||
LatencyMS int64 `json:"latency_ms"`
|
||||
ObservedAt time.Time `json:"observed_at"`
|
||||
LastSuccessAt *time.Time `json:"last_success_at"`
|
||||
ConsecutiveFailures int `json:"consecutive_failures"`
|
||||
Configured bool `json:"configured"`
|
||||
Applicable bool `json:"applicable"`
|
||||
}
|
||||
|
||||
type KnowledgeBaseProgress struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Visibility string `json:"visibility"`
|
||||
Imported int `json:"imported"`
|
||||
Completed int `json:"completed"`
|
||||
Pending int `json:"pending"`
|
||||
Processing int `json:"processing"`
|
||||
Finalizing int `json:"finalizing"`
|
||||
Failed int `json:"failed"`
|
||||
Cancelled int `json:"cancelled"`
|
||||
InternalImported int `json:"internal_imported"`
|
||||
InternalCompleted int `json:"internal_completed"`
|
||||
ExternalImported int `json:"external_imported"`
|
||||
ExternalCompleted int `json:"external_completed"`
|
||||
}
|
||||
|
||||
// JobWindowMetrics reports a frozen statistical window; insufficient samples
|
||||
// stay null and are never rendered as 0.
|
||||
type JobWindowMetrics struct {
|
||||
WindowSeconds int `json:"window_seconds"`
|
||||
JobsStarted int `json:"jobs_started"`
|
||||
JobsCompleted int `json:"jobs_completed"`
|
||||
JobsFailed int `json:"jobs_failed"`
|
||||
SuccessRate *float64 `json:"success_rate"`
|
||||
FailureRate *float64 `json:"failure_rate"`
|
||||
DurationAvgSeconds *float64 `json:"duration_avg_seconds"`
|
||||
DurationP50Seconds *float64 `json:"duration_p50_seconds"`
|
||||
DurationP95Seconds *float64 `json:"duration_p95_seconds"`
|
||||
}
|
||||
|
||||
type QueueGauges struct {
|
||||
Pending int `json:"pending"`
|
||||
Running int `json:"running"`
|
||||
Retry int `json:"retry"`
|
||||
Failed int `json:"failed"`
|
||||
OldestPendingAgeSeconds *float64 `json:"oldest_pending_age_seconds"`
|
||||
}
|
||||
|
||||
type RunMetrics struct {
|
||||
ObservedAt time.Time `json:"observed_at"`
|
||||
ActiveWorkers int `json:"active_workers"`
|
||||
WorkerSource string `json:"worker_source"`
|
||||
Queue QueueGauges `json:"queue"`
|
||||
ShortWindow JobWindowMetrics `json:"short_window"`
|
||||
LongWindow JobWindowMetrics `json:"long_window"`
|
||||
}
|
||||
|
||||
type MonitorOverview struct {
|
||||
Mode string `json:"mode"`
|
||||
Simulated bool `json:"simulated"`
|
||||
ObservedAt time.Time `json:"observed_at"`
|
||||
Host MonitorHost `json:"host"`
|
||||
Services []MonitorService `json:"services"`
|
||||
KnowledgeBases []KnowledgeBaseProgress `json:"knowledge_bases"`
|
||||
Health []ServiceHealth `json:"health"`
|
||||
}
|
||||
|
||||
type KnowledgeMonitorFile struct {
|
||||
Name string `json:"name"`
|
||||
Directory string `json:"directory"`
|
||||
Visibility string `json:"visibility"`
|
||||
Status string `json:"status"`
|
||||
StageDetail string `json:"stage_detail"`
|
||||
ElapsedSecond int `json:"elapsed_seconds"`
|
||||
ErrorCode string `json:"error_code"`
|
||||
}
|
||||
|
||||
type KnowledgeMonitorFilePage struct {
|
||||
Items []KnowledgeMonitorFile `json:"items"`
|
||||
Total int `json:"total"`
|
||||
Limit int `json:"limit"`
|
||||
Offset int `json:"offset"`
|
||||
SampleOnly bool `json:"sample_only"`
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package governance
|
||||
|
||||
import "time"
|
||||
|
||||
// ReleaseAuditChain is the R6 read-only evidence projection: one execution can
|
||||
// be traced to its batch, the confirmed release change set, the bound source
|
||||
// snapshots and catalog change sets, and every item's review, acceptance run
|
||||
// and source identity. Only safe identifiers, labels, counts and timestamps
|
||||
// travel here — never bundle paths, credentials, or signed URLs.
|
||||
type ReleaseAuditChain struct {
|
||||
ExecutionID string `json:"execution_id"`
|
||||
Operation string `json:"operation"`
|
||||
State string `json:"state"`
|
||||
FailureLevel string `json:"failure_level"`
|
||||
BatchID string `json:"release_batch_id"`
|
||||
BatchName string `json:"release_batch_name"`
|
||||
CreatedBy string `json:"created_by"`
|
||||
SealedBy string `json:"sealed_by"`
|
||||
AuthorizedBy string `json:"authorized_by"`
|
||||
ReleaseChangeSetID string `json:"release_change_set_id"`
|
||||
ChangeSetName string `json:"release_change_set_name"`
|
||||
ChangeSetNumber int `json:"release_change_set_number"`
|
||||
ChangeSetState string `json:"release_change_set_state"`
|
||||
ChangeSetCreatedBy string `json:"release_change_set_created_by"`
|
||||
ChangeSetConfirmedBy string `json:"release_change_set_confirmed_by"`
|
||||
ChangeSetConfirmedAt *time.Time `json:"release_change_set_confirmed_at"`
|
||||
ManifestSHA256 string `json:"manifest_sha256"`
|
||||
Snapshots []AuditSnapshot `json:"snapshots"`
|
||||
CatalogChangeSets []AuditCatalogSet `json:"catalog_change_sets"`
|
||||
PriorExecutionID string `json:"prior_execution_id"`
|
||||
RollbackExecutionID string `json:"rollback_execution_id"`
|
||||
Items []AuditChainItem `json:"items"`
|
||||
}
|
||||
|
||||
type AuditSnapshot struct {
|
||||
ID string `json:"id"`
|
||||
SourceName string `json:"source_name"`
|
||||
NodeCount int `json:"node_count"`
|
||||
FileCount int `json:"file_count"`
|
||||
ObservedAt time.Time `json:"observed_at"`
|
||||
}
|
||||
|
||||
type AuditCatalogSet struct {
|
||||
ID string `json:"id"`
|
||||
State string `json:"state"`
|
||||
AddCount int `json:"add_count"`
|
||||
UpdateCount int `json:"update_count"`
|
||||
MoveCount int `json:"move_count"`
|
||||
DeleteCount int `json:"delete_count"`
|
||||
}
|
||||
|
||||
type AuditChainItem struct {
|
||||
PublicationID string `json:"publication_id"`
|
||||
Title string `json:"title"`
|
||||
Action string `json:"action"`
|
||||
ItemState string `json:"item_state"`
|
||||
ReviewID string `json:"review_id"`
|
||||
AcceptanceRunID string `json:"acceptance_run_id"`
|
||||
SourceItemID string `json:"source_item_id"`
|
||||
SourceVersionID string `json:"source_item_version_id"`
|
||||
ProductionRevision string `json:"production_revision"`
|
||||
ErrorCode string `json:"error_code"`
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package governance
|
||||
|
||||
import "time"
|
||||
|
||||
type ReleaseBatchState string
|
||||
|
||||
const (
|
||||
ReleaseBatchDraft ReleaseBatchState = "draft"
|
||||
ReleaseBatchSealed ReleaseBatchState = "sealed"
|
||||
ReleaseBatchCancelled ReleaseBatchState = "cancelled"
|
||||
)
|
||||
|
||||
func (state ReleaseBatchState) Valid() bool {
|
||||
switch state {
|
||||
case ReleaseBatchDraft, ReleaseBatchSealed, ReleaseBatchCancelled:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type ReleaseBatch struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
State ReleaseBatchState `json:"state"`
|
||||
PolicyVersion string `json:"policy_version"`
|
||||
CreatedBy string `json:"created_by"`
|
||||
SealedBy string `json:"sealed_by"`
|
||||
ItemCount int `json:"item_count"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
SealedAt *time.Time `json:"sealed_at"`
|
||||
ReleaseChangeSetID string `json:"release_change_set_id,omitempty"`
|
||||
}
|
||||
|
||||
type CreateReleaseBatchRequest struct {
|
||||
Name string
|
||||
CreatedBy string
|
||||
PublicationIDs []string
|
||||
DeletePublicationIDs []string
|
||||
// ReleaseChangeSetID (R1): a formal batch must cite a CONFIRMED persistent
|
||||
// release change set; empty keeps legacy ad-hoc batches draft-only.
|
||||
ReleaseChangeSetID string
|
||||
Now time.Time
|
||||
}
|
||||
|
||||
type SealReleaseBatchRequest struct {
|
||||
BatchID string
|
||||
SealedBy string
|
||||
Now time.Time
|
||||
}
|
||||
|
||||
type ReleaseBatchFilter struct {
|
||||
State string
|
||||
Limit int
|
||||
Offset int
|
||||
}
|
||||
|
||||
type ReleaseBatchPage struct {
|
||||
Items []ReleaseBatch `json:"items"`
|
||||
Total int `json:"total"`
|
||||
Limit int `json:"limit"`
|
||||
Offset int `json:"offset"`
|
||||
}
|
||||
|
||||
type ReleaseBatchItemView struct {
|
||||
PublicationID string `json:"publication_id"`
|
||||
Title string `json:"title"`
|
||||
DecidedVisibility Visibility `json:"decided_visibility"`
|
||||
Action string `json:"action"`
|
||||
}
|
||||
|
||||
type ReleaseBatchDetail struct {
|
||||
ReleaseBatch
|
||||
Items []ReleaseBatchItemView `json:"items"`
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package governance
|
||||
|
||||
import "time"
|
||||
|
||||
// ReleaseChangeSet is the R1 persistent, immutable release plan: generated from
|
||||
// the live plan exactly once, bound to the source snapshots it was computed
|
||||
// against, hash-sealed, and confirmed before batches may cite it.
|
||||
type ReleaseChangeSet struct {
|
||||
ID string `json:"id"`
|
||||
Number int `json:"number"`
|
||||
Name string `json:"name"`
|
||||
State string `json:"state"`
|
||||
SourceSnapshotIDs []string `json:"source_snapshot_ids"`
|
||||
SourceChangeSetIDs []string `json:"source_change_set_ids"`
|
||||
AcceptanceCutoff time.Time `json:"acceptance_cutoff"`
|
||||
ProductionBaselineRef string `json:"production_baseline_ref"`
|
||||
ItemCount int `json:"item_count"`
|
||||
AddCount int `json:"add_count"`
|
||||
UpdateCount int `json:"update_count"`
|
||||
DeleteCount int `json:"delete_count"`
|
||||
BlockedCount int `json:"blocked_count"`
|
||||
ManifestSHA256 string `json:"manifest_sha256"`
|
||||
CreatedBy string `json:"created_by"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ConfirmedBy string `json:"confirmed_by"`
|
||||
ConfirmedAt *time.Time `json:"confirmed_at"`
|
||||
}
|
||||
|
||||
type GenerateReleaseChangeSetRequest struct {
|
||||
Name string
|
||||
CreatedBy string
|
||||
Now time.Time
|
||||
}
|
||||
|
||||
type ConfirmReleaseChangeSetRequest struct {
|
||||
ChangeSetID string
|
||||
ConfirmedBy string
|
||||
Now time.Time
|
||||
}
|
||||
|
||||
type ReleaseChangeSetItem struct {
|
||||
Seq int `json:"seq"`
|
||||
PublicationID string `json:"publication_id"`
|
||||
Title string `json:"title"`
|
||||
TargetScope string `json:"target_scope"`
|
||||
Action string `json:"action"`
|
||||
TestState string `json:"test_state"`
|
||||
ProductionState string `json:"production_state"`
|
||||
CanRelease bool `json:"can_release"`
|
||||
Blocker string `json:"blocker"`
|
||||
}
|
||||
|
||||
type ReleaseChangeSetDetail struct {
|
||||
ReleaseChangeSet
|
||||
Items []ReleaseChangeSetItem `json:"items"`
|
||||
}
|
||||
|
||||
type ReleaseChangeSetPage struct {
|
||||
Items []ReleaseChangeSet `json:"items"`
|
||||
Total int `json:"total"`
|
||||
Limit int `json:"limit"`
|
||||
Offset int `json:"offset"`
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package governance
|
||||
|
||||
import "time"
|
||||
|
||||
type ReleaseOperation string
|
||||
|
||||
const (
|
||||
ReleaseOperationPublish ReleaseOperation = "publish"
|
||||
ReleaseOperationRollback ReleaseOperation = "rollback"
|
||||
)
|
||||
|
||||
func (operation ReleaseOperation) Valid() bool {
|
||||
return operation == ReleaseOperationPublish || operation == ReleaseOperationRollback
|
||||
}
|
||||
|
||||
type ReleaseExecutionState string
|
||||
|
||||
const (
|
||||
ReleaseExecutionPending ReleaseExecutionState = "pending"
|
||||
ReleaseExecutionRunning ReleaseExecutionState = "running"
|
||||
// R4: a rollback execution compensates in rolling_back and terminates in
|
||||
// rolled_back (all compensated) or rollback_failed (manual action needed).
|
||||
ReleaseExecutionRollingBack ReleaseExecutionState = "rolling_back"
|
||||
ReleaseExecutionRolledBack ReleaseExecutionState = "rolled_back"
|
||||
ReleaseExecutionRollbackFailed ReleaseExecutionState = "rollback_failed"
|
||||
ReleaseExecutionCompleted ReleaseExecutionState = "completed"
|
||||
ReleaseExecutionFailed ReleaseExecutionState = "failed"
|
||||
)
|
||||
|
||||
func (state ReleaseExecutionState) Valid() bool {
|
||||
switch state {
|
||||
case ReleaseExecutionPending, ReleaseExecutionRunning, ReleaseExecutionRollingBack,
|
||||
ReleaseExecutionRolledBack, ReleaseExecutionRollbackFailed,
|
||||
ReleaseExecutionCompleted, ReleaseExecutionFailed:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type ReleaseExecution struct {
|
||||
ID string `json:"id"`
|
||||
ReleaseBatchID string `json:"release_batch_id"`
|
||||
Operation ReleaseOperation `json:"operation"`
|
||||
PriorExecutionID string `json:"prior_execution_id"`
|
||||
State ReleaseExecutionState `json:"state"`
|
||||
FailureLevel string `json:"failure_level"`
|
||||
RestoreTrigger string `json:"restore_trigger"`
|
||||
ReleaseChangeSetID string `json:"release_change_set_id"`
|
||||
TargetEnvironment string `json:"target_environment"`
|
||||
AuthorizedBy string `json:"authorized_by"`
|
||||
AuthorizationCode string `json:"authorization_code"`
|
||||
JobID string `json:"job_id"`
|
||||
ManifestSHA256 string `json:"manifest_sha256"`
|
||||
ItemCount int `json:"item_count"`
|
||||
BatchSize int `json:"batch_size"`
|
||||
CurrentBatch int `json:"current_batch"`
|
||||
TotalBatches int `json:"total_batches"`
|
||||
CompletedItemCount int `json:"completed_item_count"`
|
||||
FailedItemCount int `json:"failed_item_count"`
|
||||
ErrorCode string `json:"error_code"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
StartedAt *time.Time `json:"started_at"`
|
||||
CompletedAt *time.Time `json:"completed_at"`
|
||||
}
|
||||
|
||||
type AuthorizeReleaseBatchRequest struct {
|
||||
BatchID string
|
||||
AuthorizedBy string
|
||||
AuthorizationCode string
|
||||
Now time.Time
|
||||
}
|
||||
|
||||
type AuthorizeReleaseRollbackRequest struct {
|
||||
PriorExecutionID string
|
||||
AuthorizedBy string
|
||||
AuthorizationCode string
|
||||
Now time.Time
|
||||
}
|
||||
|
||||
type RetryReleaseExecutionRequest struct {
|
||||
ExecutionID string
|
||||
Now time.Time
|
||||
}
|
||||
|
||||
type ReleaseExecutionFilter struct {
|
||||
Operation string
|
||||
State string
|
||||
Limit int
|
||||
Offset int
|
||||
}
|
||||
|
||||
type ReleaseExecutionPage struct {
|
||||
Items []ReleaseExecution
|
||||
Total int
|
||||
Limit int
|
||||
Offset int
|
||||
}
|
||||
|
||||
type ReleaseItemExecutionView struct {
|
||||
PublicationID string `json:"publication_id"`
|
||||
Title string `json:"title"`
|
||||
Action string `json:"action"`
|
||||
State string `json:"state"`
|
||||
PreviousProductionRevision string `json:"previous_production_revision"`
|
||||
ProductionRevision string `json:"production_revision"`
|
||||
ErrorCode string `json:"error_code"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
CompletedAt *time.Time `json:"completed_at"`
|
||||
}
|
||||
|
||||
type ReleaseExecutionDetail struct {
|
||||
ReleaseExecution
|
||||
Items []ReleaseItemExecutionView `json:"items"`
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package governance
|
||||
|
||||
type ReleasePlanItem struct {
|
||||
PublicationID string `json:"publication_id"`
|
||||
Title string `json:"title"`
|
||||
TargetScope string `json:"target_scope"`
|
||||
Action string `json:"action"`
|
||||
TestState string `json:"test_state"`
|
||||
ProductionState string `json:"production_state"`
|
||||
CanRelease bool `json:"can_release"`
|
||||
Blocker string `json:"blocker"`
|
||||
}
|
||||
|
||||
type ReleasePlanSummary struct {
|
||||
Add int `json:"add"`
|
||||
Update int `json:"update"`
|
||||
Delete int `json:"delete"`
|
||||
Blocked int `json:"blocked"`
|
||||
Unchanged int `json:"unchanged"`
|
||||
}
|
||||
|
||||
type ReleasePlan struct {
|
||||
Items []ReleasePlanItem `json:"items"`
|
||||
Summary ReleasePlanSummary `json:"summary"`
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package governance
|
||||
|
||||
import "time"
|
||||
|
||||
type ReviewGateStatus string
|
||||
|
||||
const (
|
||||
ReviewGateReady ReviewGateStatus = "ready"
|
||||
ReviewGateBlocked ReviewGateStatus = "blocked"
|
||||
)
|
||||
|
||||
func (status ReviewGateStatus) Valid() bool {
|
||||
return status == ReviewGateReady || status == ReviewGateBlocked
|
||||
}
|
||||
|
||||
type ReviewCandidate struct {
|
||||
PublicationID string `json:"publication_id"`
|
||||
Title string `json:"title"`
|
||||
SourceType SourceType `json:"source_type"`
|
||||
CurrentVisibility Visibility `json:"current_visibility"`
|
||||
AcceptanceRunID string `json:"-"`
|
||||
KnowledgeExists AcceptanceState `json:"knowledge_exists"`
|
||||
ChunksPresent AcceptanceState `json:"chunks_present"`
|
||||
RetrievalHit AcceptanceState `json:"retrieval_hit"`
|
||||
GateStatus ReviewGateStatus `json:"gate_status"`
|
||||
GateCode string `json:"gate_code"`
|
||||
ReviewState ReviewState `json:"review_state"`
|
||||
DecidedVisibility string `json:"decided_visibility"`
|
||||
DecisionCode string `json:"decision_code"`
|
||||
ReviewerRef string `json:"reviewer_ref"`
|
||||
ReviewedAt *time.Time `json:"reviewed_at"`
|
||||
PublicationUpdated time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type ReviewCandidateFilter struct {
|
||||
ReviewState string
|
||||
Limit int
|
||||
Offset int
|
||||
}
|
||||
|
||||
type ReviewCandidatePage struct {
|
||||
Items []ReviewCandidate `json:"items"`
|
||||
Total int `json:"total"`
|
||||
Limit int `json:"limit"`
|
||||
Offset int `json:"offset"`
|
||||
}
|
||||
|
||||
type PublicationReview struct {
|
||||
ID string `json:"id"`
|
||||
PublicationID string `json:"publication_id"`
|
||||
Decision ReviewState `json:"decision"`
|
||||
DecidedVisibility Visibility `json:"decided_visibility"`
|
||||
ReviewerRef string `json:"reviewer_ref"`
|
||||
DecisionCode string `json:"decision_code"`
|
||||
AcceptanceRunID string `json:"-"`
|
||||
PublicationUpdated time.Time `json:"-"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type ReviewPublicationRequest struct {
|
||||
PublicationID string
|
||||
Decision ReviewState
|
||||
DecidedVisibility Visibility
|
||||
ReviewerRef string
|
||||
DecisionCode string
|
||||
Now time.Time
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package governance
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
type ScopeTargetType string
|
||||
|
||||
const (
|
||||
ScopeTargetDirectory ScopeTargetType = "directory"
|
||||
ScopeTargetItem ScopeTargetType = "item"
|
||||
)
|
||||
|
||||
type ScopeRuleMutation struct {
|
||||
TargetType ScopeTargetType
|
||||
ConnectionID string
|
||||
DirectoryPath string
|
||||
SourceItemID string
|
||||
Visibility Visibility
|
||||
OperatorRef string
|
||||
Reason string
|
||||
Clear bool
|
||||
Now time.Time
|
||||
}
|
||||
|
||||
type ScopeRule struct {
|
||||
TargetType ScopeTargetType `json:"target_type"`
|
||||
ConnectionID string `json:"connection_id,omitempty"`
|
||||
DirectoryPath string `json:"directory_path,omitempty"`
|
||||
SourceItemID string `json:"source_item_id,omitempty"`
|
||||
Visibility Visibility `json:"visibility"`
|
||||
UpdatedBy string `json:"updated_by"`
|
||||
Reason string `json:"reason"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (request ScopeRuleMutation) Validate() error {
|
||||
if request.TargetType != ScopeTargetDirectory && request.TargetType != ScopeTargetItem {
|
||||
return errors.New("scope target must be directory or item")
|
||||
}
|
||||
if request.TargetType == ScopeTargetDirectory {
|
||||
if strings.TrimSpace(request.ConnectionID) == "" || request.SourceItemID != "" || !validScopePath(request.DirectoryPath) {
|
||||
return errors.New("directory scope target is invalid")
|
||||
}
|
||||
} else if strings.TrimSpace(request.SourceItemID) == "" || request.ConnectionID != "" || request.DirectoryPath != "" {
|
||||
return errors.New("item scope target is invalid")
|
||||
}
|
||||
if !request.Clear && request.Visibility != VisibilityInternal && request.Visibility != VisibilityExternal {
|
||||
return errors.New("visibility must be internal or external")
|
||||
}
|
||||
if request.Clear && request.Visibility != "" {
|
||||
return errors.New("clear scope must not include visibility")
|
||||
}
|
||||
operator := strings.TrimSpace(request.OperatorRef)
|
||||
reason := strings.TrimSpace(request.Reason)
|
||||
if operator == "" || len(operator) > 128 || reason == "" || len(reason) > 500 || request.Now.IsZero() {
|
||||
return errors.New("operator, reason, and time are required")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validScopePath(value string) bool {
|
||||
if len(value) > 2048 || strings.HasPrefix(value, "/") || strings.Contains(value, "\\") {
|
||||
return false
|
||||
}
|
||||
for _, part := range strings.Split(value, "/") {
|
||||
if part == "." || part == ".." {
|
||||
return false
|
||||
}
|
||||
}
|
||||
for _, value := range value {
|
||||
if unicode.IsControl(value) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package governance
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestValidateScopeRuleMutationAcceptsDirectoryRootAndItemOverride(t *testing.T) {
|
||||
now := time.Now()
|
||||
for _, request := range []ScopeRuleMutation{
|
||||
{TargetType: ScopeTargetDirectory, ConnectionID: "conn-1", DirectoryPath: "", Visibility: VisibilityInternal, OperatorRef: "engineer-1", Reason: "仅供内部使用", Now: now},
|
||||
{TargetType: ScopeTargetDirectory, ConnectionID: "conn-1", DirectoryPath: "产品/说明书", Visibility: VisibilityExternal, OperatorRef: "engineer-1", Reason: "官网公开资料", Now: now},
|
||||
{TargetType: ScopeTargetItem, SourceItemID: "item-1", Visibility: VisibilityInternal, OperatorRef: "engineer-1", Reason: "文件单独包含内部参数", Now: now},
|
||||
} {
|
||||
if err := request.Validate(); err != nil {
|
||||
t.Errorf("Validate(%#v) error = %v", request, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateScopeRuleMutationRejectsAmbiguousOrUnsafeTargets(t *testing.T) {
|
||||
valid := ScopeRuleMutation{TargetType: ScopeTargetDirectory, ConnectionID: "conn-1", Visibility: VisibilityInternal, OperatorRef: "engineer-1", Reason: "范围调整", Now: time.Now()}
|
||||
cases := []ScopeRuleMutation{
|
||||
{},
|
||||
{TargetType: ScopeTargetDirectory, ConnectionID: "conn-1", SourceItemID: "item-1", Visibility: VisibilityInternal, OperatorRef: "engineer", Reason: "x", Now: time.Now()},
|
||||
{TargetType: ScopeTargetDirectory, ConnectionID: "conn-1", DirectoryPath: "/private", Visibility: VisibilityInternal, OperatorRef: "engineer", Reason: "x", Now: time.Now()},
|
||||
{TargetType: ScopeTargetDirectory, ConnectionID: "conn-1", DirectoryPath: "a/../private", Visibility: VisibilityInternal, OperatorRef: "engineer", Reason: "x", Now: time.Now()},
|
||||
{TargetType: ScopeTargetItem, SourceItemID: "item-1", Visibility: Visibility("public"), OperatorRef: "engineer", Reason: "x", Now: time.Now()},
|
||||
{TargetType: ScopeTargetItem, SourceItemID: "item-1", Visibility: VisibilityInternal, OperatorRef: "", Reason: "x", Now: time.Now()},
|
||||
{TargetType: ScopeTargetItem, SourceItemID: "item-1", Visibility: VisibilityInternal, OperatorRef: "engineer", Reason: "", Now: time.Now()},
|
||||
}
|
||||
for _, request := range cases {
|
||||
if err := request.Validate(); err == nil {
|
||||
t.Errorf("Validate(%#v) error=nil", request)
|
||||
}
|
||||
}
|
||||
valid.Clear = true
|
||||
valid.Visibility = ""
|
||||
if err := valid.Validate(); err != nil {
|
||||
t.Fatalf("clear validation error = %v", err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package governance
|
||||
|
||||
import "time"
|
||||
|
||||
type SourceAsset struct {
|
||||
CanRetry bool `json:"can_retry"`
|
||||
Title string `json:"title"`
|
||||
DirectoryPath string `json:"directory_path"`
|
||||
ConnectionID string `json:"connection_id"`
|
||||
VisibilityOrigin string `json:"visibility_origin"`
|
||||
ScopeRulePath string `json:"scope_rule_path"`
|
||||
IngestState string `json:"ingest_state"`
|
||||
LastError string `json:"last_error"`
|
||||
PublicationID string `json:"publication_id"`
|
||||
ID string `json:"id"`
|
||||
SourceType SourceType `json:"source_type"`
|
||||
ConnectionName string `json:"connection_name"`
|
||||
SizeBytes int64 `json:"size_bytes"`
|
||||
Visibility Visibility `json:"visibility"`
|
||||
SourceChange SourceChange `json:"source_change"`
|
||||
ContentState ContentState `json:"content_state"`
|
||||
LegacyStatus string `json:"legacy_status"`
|
||||
HasPublication bool `json:"has_publication"`
|
||||
ProcessingState string `json:"processing_state"`
|
||||
RetrievalState string `json:"retrieval_state"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type SourceAssetFilter struct {
|
||||
State string
|
||||
Limit int
|
||||
Offset int
|
||||
}
|
||||
|
||||
type SourceAssetSummary struct {
|
||||
Total int `json:"total"`
|
||||
Completed int `json:"completed"`
|
||||
ContentAlias int `json:"content_alias"`
|
||||
OverLimit int `json:"over_limit"`
|
||||
}
|
||||
|
||||
type SourceAssetPage struct {
|
||||
Items []SourceAsset `json:"items"`
|
||||
Summary SourceAssetSummary `json:"summary"`
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package governance
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSourceAssetIncludesDocumentNavigationMetadata(t *testing.T) {
|
||||
data, err := json.Marshal(SourceAsset{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, field := range []string{"title", "directory_path", "connection_id", "visibility_origin", "ingest_state", "last_error", "publication_id", "can_retry"} {
|
||||
if !strings.Contains(string(data), `"`+field+`"`) {
|
||||
t.Errorf("missing document field %s", field)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package governance
|
||||
|
||||
import "time"
|
||||
|
||||
type CatalogSource struct {
|
||||
ConnectionID string `json:"connection_id"`
|
||||
SourceType SourceType `json:"source_type"`
|
||||
Name string `json:"name"`
|
||||
RootNodeID string `json:"root_node_id"`
|
||||
FolderCount int `json:"folder_count"`
|
||||
FileCount int `json:"file_count"`
|
||||
ObservedAt time.Time `json:"observed_at"`
|
||||
SnapshotOnly bool `json:"snapshot_only"`
|
||||
SnapshotStatus string `json:"snapshot_status"`
|
||||
LastRefreshDurationMS int64 `json:"last_refresh_duration_ms"`
|
||||
}
|
||||
|
||||
type CatalogBreadcrumb struct {
|
||||
NodeID string `json:"node_id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type CatalogNode struct {
|
||||
NodeID string `json:"node_id"`
|
||||
ParentNodeID string `json:"parent_node_id,omitempty"`
|
||||
NodeType string `json:"node_type"`
|
||||
Name string `json:"name"`
|
||||
DirectChildCount int `json:"direct_child_count"`
|
||||
SubtreeFileCount int `json:"subtree_file_count"`
|
||||
SubtreeBytes int64 `json:"subtree_bytes"`
|
||||
SizeBytes *int64 `json:"size_bytes,omitempty"`
|
||||
ModifiedAt *time.Time `json:"modified_at,omitempty"`
|
||||
ContentSHA256 *string `json:"content_sha256,omitempty"`
|
||||
Visibility string `json:"visibility"`
|
||||
ImportedCount int `json:"imported_count"`
|
||||
ParsedCount int `json:"parsed_count"`
|
||||
ActiveCount int `json:"active_count"`
|
||||
FailedCount int `json:"failed_count"`
|
||||
RoutableCount int `json:"routable_count"`
|
||||
}
|
||||
|
||||
type CatalogNodeFilter struct {
|
||||
ConnectionID string
|
||||
ParentNodeID string
|
||||
Limit int
|
||||
Offset int
|
||||
}
|
||||
|
||||
type CatalogNodePage struct {
|
||||
Current CatalogNode `json:"current"`
|
||||
Breadcrumbs []CatalogBreadcrumb `json:"breadcrumbs"`
|
||||
Items []CatalogNode `json:"items"`
|
||||
Total int `json:"total"`
|
||||
Limit int `json:"limit"`
|
||||
Offset int `json:"offset"`
|
||||
}
|
||||
|
||||
type CatalogSnapshot struct {
|
||||
SnapshotID string `json:"snapshot_id"`
|
||||
ConnectionID string `json:"connection_id"`
|
||||
RootNodeID string `json:"root_node_id"`
|
||||
SourceName string `json:"source_name"`
|
||||
NodeCount int `json:"node_count"`
|
||||
FolderCount int `json:"folder_count"`
|
||||
FileCount int `json:"file_count"`
|
||||
ObservedAt time.Time `json:"observed_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
IsHead bool `json:"is_head"`
|
||||
}
|
||||
|
||||
type CatalogSnapshotPage struct {
|
||||
Items []CatalogSnapshot `json:"items"`
|
||||
Total int `json:"total"`
|
||||
Limit int `json:"limit"`
|
||||
Offset int `json:"offset"`
|
||||
}
|
||||
|
||||
type CatalogSnapshotNodeFilter struct {
|
||||
ConnectionID string
|
||||
SnapshotID string
|
||||
ParentNodeID string
|
||||
Limit int
|
||||
Offset int
|
||||
}
|
||||
|
||||
type CatalogRouteRequest struct {
|
||||
ConnectionID string
|
||||
NodeIDs []string
|
||||
Visibility Visibility
|
||||
TargetKnowledgeBaseID string
|
||||
TargetKnowledgeBaseIDs []string
|
||||
OperatorRef string
|
||||
Reason string
|
||||
Now time.Time
|
||||
}
|
||||
|
||||
// CatalogRouteResult describes the desired-state write only. S7 guarantees the
|
||||
// annotation never creates publications or jobs; counts explain what the
|
||||
// subsequent ChangeSet/P3 pipeline will be able to act on.
|
||||
type CatalogRouteResult struct {
|
||||
SelectedFiles int `json:"selected_files"`
|
||||
RoutableFiles int `json:"routable_files"`
|
||||
UnboundFiles int `json:"unbound_files"`
|
||||
HashUnknownFiles int `json:"hash_unknown_files"`
|
||||
UnavailableFiles int `json:"unavailable_files"`
|
||||
}
|
||||
|
||||
type CatalogChangeSetFilter struct {
|
||||
ConnectionID string
|
||||
Action string
|
||||
Limit int
|
||||
Offset int
|
||||
}
|
||||
|
||||
type CatalogChangeSet struct {
|
||||
ID string `json:"id"`
|
||||
ConnectionID string `json:"connection_id"`
|
||||
SourceName string `json:"source_name"`
|
||||
State string `json:"state"`
|
||||
AddCount int `json:"add_count"`
|
||||
UpdateCount int `json:"update_count"`
|
||||
MoveCount int `json:"move_count"`
|
||||
MoveScopeCount int `json:"move_scope_count"`
|
||||
DeleteCount int `json:"delete_count"`
|
||||
NoChangeCount int `json:"no_change_count"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type CatalogChangeItem struct {
|
||||
Action string `json:"action"`
|
||||
Title string `json:"title"`
|
||||
OldPath string `json:"old_path,omitempty"`
|
||||
NewPath string `json:"new_path,omitempty"`
|
||||
OldSizeBytes *int64 `json:"old_size_bytes,omitempty"`
|
||||
NewSizeBytes *int64 `json:"new_size_bytes,omitempty"`
|
||||
OldModified *time.Time `json:"old_modified_at,omitempty"`
|
||||
NewModified *time.Time `json:"new_modified_at,omitempty"`
|
||||
OldContentSHA256 string `json:"old_content_sha256,omitempty"`
|
||||
NewContentSHA256 string `json:"new_content_sha256,omitempty"`
|
||||
ReasonCode string `json:"reason_code"`
|
||||
Seq int64 `json:"seq"`
|
||||
OldScope string `json:"old_scope,omitempty"`
|
||||
NewScope string `json:"new_scope,omitempty"`
|
||||
OldVersionID string `json:"old_version_id,omitempty"`
|
||||
NewVersionID string `json:"new_version_id,omitempty"`
|
||||
}
|
||||
|
||||
type CatalogChangeSetDetail struct {
|
||||
CatalogChangeSet
|
||||
Items []CatalogChangeItem `json:"items"`
|
||||
Total int `json:"total"`
|
||||
Limit int `json:"limit"`
|
||||
Offset int `json:"offset"`
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package governance
|
||||
|
||||
import "time"
|
||||
|
||||
type SourceHealthStatus string
|
||||
|
||||
const (
|
||||
SourceHealthUnknown SourceHealthStatus = "unknown"
|
||||
SourceHealthHealthy SourceHealthStatus = "healthy"
|
||||
SourceHealthDegraded SourceHealthStatus = "degraded"
|
||||
SourceHealthUnhealthy SourceHealthStatus = "unhealthy"
|
||||
)
|
||||
|
||||
func (status SourceHealthStatus) Valid() bool {
|
||||
switch status {
|
||||
case SourceHealthUnknown, SourceHealthHealthy, SourceHealthDegraded, SourceHealthUnhealthy:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type SourceConnectionView struct {
|
||||
ID string `json:"id"`
|
||||
SourceType SourceType `json:"source_type"`
|
||||
Name string `json:"name"`
|
||||
Enabled bool `json:"enabled"`
|
||||
ScheduleConfigured bool `json:"schedule_configured"`
|
||||
HealthStatus SourceHealthStatus `json:"health_status"`
|
||||
ItemCount int `json:"item_count"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
NextRefreshAt *time.Time `json:"next_refresh_at"`
|
||||
LastScan *SourceScanSummary `json:"last_scan"`
|
||||
}
|
||||
|
||||
// SourceConnectionRevision is one validated/active/retired settings revision of
|
||||
// a source connection (V1). The JSON surface uses endpoint/credential_ref: the
|
||||
// credential field is a reference NAME only — real secret values never live in
|
||||
// this table and can never be read back through any endpoint.
|
||||
type SourceConnectionRevision struct {
|
||||
ID string `json:"id"`
|
||||
RevisionNumber int `json:"revision_number"`
|
||||
State string `json:"state"`
|
||||
Name string `json:"name"`
|
||||
BaseURL string `json:"endpoint"`
|
||||
SecretRef string `json:"credential_ref"`
|
||||
Enabled bool `json:"enabled"`
|
||||
RefreshIntervalSeconds string `json:"refresh_interval_seconds"`
|
||||
CreatedBy string `json:"created_by"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ValidatedAt *time.Time `json:"validated_at"`
|
||||
ActivatedAt *time.Time `json:"activated_at"`
|
||||
RetiredAt *time.Time `json:"retired_at"`
|
||||
}
|
||||
|
||||
type SourceScanSummary struct {
|
||||
ID string `json:"id"`
|
||||
State SourceScanState `json:"state"`
|
||||
ObservedItems int `json:"observed_items"`
|
||||
UnchangedItems int `json:"unchanged_items"`
|
||||
AddedItems int `json:"added_items"`
|
||||
UpdatedItems int `json:"updated_items"`
|
||||
OverLimitItems int `json:"over_limit_items"`
|
||||
MissingItems int `json:"missing_items"`
|
||||
PlannedUploads int `json:"planned_uploads"`
|
||||
ErrorCode string `json:"error_code"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
CompletedAt *time.Time `json:"completed_at"`
|
||||
}
|
||||
|
||||
type SourceConnectionSummary struct {
|
||||
Total int `json:"total"`
|
||||
Enabled int `json:"enabled"`
|
||||
Disabled int `json:"disabled"`
|
||||
Healthy int `json:"healthy"`
|
||||
Degraded int `json:"degraded"`
|
||||
Unhealthy int `json:"unhealthy"`
|
||||
Unknown int `json:"unknown"`
|
||||
}
|
||||
|
||||
type SourceConnectionPage struct {
|
||||
Items []SourceConnectionView `json:"items"`
|
||||
Summary SourceConnectionSummary `json:"summary"`
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package governance
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// The frontend source-settings parser requires the next_refresh_at KEY to
|
||||
// exist whenever a connection is listed — null is a first-class value ("manual
|
||||
// only"), not something to omit. A `omitempty` here once blanked the entire
|
||||
// settings page in the deployed stack because every source defaulted to
|
||||
// manual-only and the strict parser rejected the key-less payload.
|
||||
func TestSourceConnectionViewAlwaysProjectsNextRefreshAt(t *testing.T) {
|
||||
view := SourceConnectionView{ID: "conn-1", SourceType: SourceTypePP, Name: "PP", Enabled: true, ScheduleConfigured: false, HealthStatus: SourceHealthHealthy, ItemCount: 621, UpdatedAt: time.Now().UTC()}
|
||||
payload, err := json.Marshal([]SourceConnectionView{view})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(payload), `"next_refresh_at":null`) {
|
||||
t.Fatalf("manual-only connection must project next_refresh_at:null, got %s", payload)
|
||||
}
|
||||
|
||||
at := time.Now().UTC().Truncate(time.Second)
|
||||
view.NextRefreshAt = &at
|
||||
payload, err = json.Marshal([]SourceConnectionView{view})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(string(payload), `"next_refresh_at":"`) {
|
||||
t.Fatalf("scheduled connection must project a timestamp, got %s", payload)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package governance
|
||||
|
||||
import "time"
|
||||
|
||||
type SourceScanState string
|
||||
|
||||
const (
|
||||
SourceScanPending SourceScanState = "pending"
|
||||
SourceScanRunning SourceScanState = "running"
|
||||
SourceScanCompleted SourceScanState = "completed"
|
||||
SourceScanFailed SourceScanState = "failed"
|
||||
)
|
||||
|
||||
func (s SourceScanState) Valid() bool {
|
||||
switch s {
|
||||
case SourceScanPending, SourceScanRunning, SourceScanCompleted, SourceScanFailed:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type SourceScan struct {
|
||||
ID string `json:"id"`
|
||||
SourceConnectionID string `json:"source_connection_id"`
|
||||
SourceType SourceType `json:"source_type"`
|
||||
State SourceScanState `json:"state"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type SourceScanSummaryView struct {
|
||||
ID string `json:"id"`
|
||||
State SourceScanState `json:"state"`
|
||||
ObservedItems int `json:"observed_items"`
|
||||
UnchangedItems int `json:"unchanged_items"`
|
||||
AddedItems int `json:"added_items"`
|
||||
UpdatedItems int `json:"updated_items"`
|
||||
OverLimitItems int `json:"over_limit_items"`
|
||||
MissingItems int `json:"missing_items"`
|
||||
PlannedUploads int `json:"planned_uploads"`
|
||||
ErrorCode string `json:"error_code"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
CompletedAt *time.Time `json:"completed_at"`
|
||||
}
|
||||
|
||||
type SourceScanPage struct {
|
||||
Items []SourceScanSummaryView
|
||||
Total int
|
||||
Limit int
|
||||
Offset int
|
||||
}
|
||||
|
||||
type SourceScanChangeView struct {
|
||||
ID string `json:"id"`
|
||||
SourceItemID *string `json:"source_item_id"`
|
||||
ChangeType SourceScanChangeType `json:"change_type"`
|
||||
ObservedSizeBytes *int64 `json:"observed_size_bytes"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type SourceScanDetailView struct {
|
||||
SourceScanSummaryView
|
||||
Changes []SourceScanChangeView `json:"changes"`
|
||||
}
|
||||
|
||||
type SourceScanResult struct {
|
||||
SnapshotSHA256 string `json:"-"`
|
||||
ObservedItems int `json:"observed_items"`
|
||||
UnchangedItems int `json:"unchanged_items"`
|
||||
AddedItems int `json:"added_items"`
|
||||
UpdatedItems int `json:"updated_items"`
|
||||
OverLimitItems int `json:"over_limit_items"`
|
||||
MissingItems int `json:"missing_items"`
|
||||
PlannedUploads int `json:"planned_uploads"`
|
||||
Changes []SourceScanChange `json:"-"`
|
||||
}
|
||||
|
||||
type SourceScanChangeType string
|
||||
|
||||
const (
|
||||
SourceScanAdded SourceScanChangeType = "added"
|
||||
SourceScanUpdated SourceScanChangeType = "updated"
|
||||
SourceScanUnavailable SourceScanChangeType = "unavailable"
|
||||
)
|
||||
|
||||
type SourceScanChange struct {
|
||||
StableExternalID string
|
||||
ChangeType SourceScanChangeType
|
||||
PreviousRevision string
|
||||
ObservedRevision string
|
||||
ObservedSizeBytes *int64
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package governance
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// V1 per-source refresh schedule. The schedule JSONB lives on the ACTIVE
|
||||
// revision; next_refresh_at on source_connections is ALWAYS derived from it by
|
||||
// the server (clients can never push an arbitrary due time).
|
||||
|
||||
const MinRefreshInterval = 5 * time.Minute
|
||||
|
||||
type SourceSchedule struct {
|
||||
RefreshIntervalSeconds *int `json:"refresh_interval_seconds,omitempty"`
|
||||
}
|
||||
|
||||
// ParseSourceSchedule accepts the stored JSON and normalises it. Missing,
|
||||
// zero, or sub-5-minute values are rejected as "not configured" (interval 0,
|
||||
// no error) rather than silently accepted: a source that could stampede the
|
||||
// portal every few seconds is worse than a manual-only source.
|
||||
func ParseSourceSchedule(raw []byte) (time.Duration, error) {
|
||||
if len(raw) == 0 || string(raw) == "{}" {
|
||||
return 0, nil
|
||||
}
|
||||
var schedule SourceSchedule
|
||||
if err := json.Unmarshal(raw, &schedule); err != nil {
|
||||
return 0, errors.New("invalid source schedule")
|
||||
}
|
||||
if schedule.RefreshIntervalSeconds == nil || *schedule.RefreshIntervalSeconds == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
if *schedule.RefreshIntervalSeconds < 0 {
|
||||
return 0, errors.New("invalid source schedule")
|
||||
}
|
||||
interval := time.Duration(*schedule.RefreshIntervalSeconds) * time.Second
|
||||
if interval < MinRefreshInterval {
|
||||
return 0, errors.New("source refresh interval must be at least five minutes")
|
||||
}
|
||||
return interval, nil
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package governance
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestParseSourceSchedule(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
raw string
|
||||
want time.Duration
|
||||
wantErr bool
|
||||
}{
|
||||
{"empty object = manual only", "{}", 0, false},
|
||||
{"missing key", `{"other":1}`, 0, false},
|
||||
{"explicit zero disables", `{"refresh_interval_seconds":0}`, 0, false},
|
||||
{"valid hourly", `{"refresh_interval_seconds":3600}`, time.Hour, false},
|
||||
{"valid daily", `{"refresh_interval_seconds":86400}`, 24 * time.Hour, false},
|
||||
{"below floor rejected", `{"refresh_interval_seconds":60}`, 0, true},
|
||||
{"negative rejected", `{"refresh_interval_seconds":-5}`, 0, true},
|
||||
{"malformed rejected", `not json`, 0, true},
|
||||
{"string value rejected", `{"refresh_interval_seconds":"3600"}`, 0, true},
|
||||
}
|
||||
for _, test := range cases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got, err := ParseSourceSchedule([]byte(test.raw))
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Fatalf("error=%v wantErr=%v", err, test.wantErr)
|
||||
}
|
||||
if got != test.want {
|
||||
t.Fatalf("interval=%v want %v", got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSourceScheduleRoundTripsThroughJSON(t *testing.T) {
|
||||
seconds := 7200
|
||||
encoded, err := json.Marshal(SourceSchedule{RefreshIntervalSeconds: &seconds})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
interval, err := ParseSourceSchedule(encoded)
|
||||
if err != nil || interval != 2*time.Hour {
|
||||
t.Fatalf("interval=%v err=%v", interval, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package governance
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStateMachineContractSeparatesDimensionsAndReservedStates(t *testing.T) {
|
||||
content, err := os.ReadFile("../../docs/STATE_MACHINE.md")
|
||||
if err != nil {
|
||||
t.Fatalf("read state machine contract: %v", err)
|
||||
}
|
||||
|
||||
text := string(content)
|
||||
for _, required := range []string{
|
||||
"## State dimensions",
|
||||
"### Job",
|
||||
"pending | running | retry | completed | failed | cancelled",
|
||||
"### Scope policy",
|
||||
"unset | internal | external | blocked",
|
||||
"historical compatibility value: both",
|
||||
"### Source change",
|
||||
"### Review",
|
||||
"### Content",
|
||||
"### Ingest",
|
||||
"### Processing",
|
||||
"### Retrieval",
|
||||
"### Release",
|
||||
"## Reserved future values",
|
||||
"rolling_back",
|
||||
"must not be persisted before R4",
|
||||
} {
|
||||
if !strings.Contains(text, required) {
|
||||
t.Fatalf("state machine contract is missing %q", required)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package governance
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
// TestPublication is the safe projection of a test publication for the API and web console.
|
||||
// It deliberately omits knowledge_id, test_kb_id, source URL, SHA-256, spool path,
|
||||
// raw summaries and any credential material.
|
||||
type TestPublication struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
IngestState string `json:"ingest_state"`
|
||||
ProcessingState string `json:"processing_state"`
|
||||
RetrievalState string `json:"retrieval_state"`
|
||||
TargetScope string `json:"target_scope"`
|
||||
ChangeSetID string `json:"change_set_id"`
|
||||
ChangeType string `json:"change_type"`
|
||||
CanStart bool `json:"can_start"`
|
||||
RetryCount int `json:"retry_count"`
|
||||
LastError string `json:"last_error"`
|
||||
CanRetry bool `json:"can_retry"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type TestPublicationFilter struct {
|
||||
ProcessingState string
|
||||
// TargetScope filters the test queue by KB routing target (P4).
|
||||
TargetScope string
|
||||
Limit int
|
||||
Offset int
|
||||
}
|
||||
|
||||
type TestPublicationPage struct {
|
||||
Items []TestPublication `json:"items"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
type StartTestPublicationsRequest struct {
|
||||
PublicationIDs []string
|
||||
OperatorRef string
|
||||
Reason string
|
||||
Now time.Time
|
||||
}
|
||||
|
||||
type StartTestPublicationsResult struct {
|
||||
Selected int `json:"selected"`
|
||||
Started int `json:"started"`
|
||||
AlreadyStarted int `json:"already_started"`
|
||||
Unavailable int `json:"unavailable"`
|
||||
}
|
||||
|
||||
// AcceptanceRecord is the safe projection of an acceptance result for the API.
|
||||
// EvidenceSummary is returned as an object but only carries counts and booleans,
|
||||
// never remote bodies, paths or credentials.
|
||||
type AcceptanceRecord struct {
|
||||
CheckType string `json:"check_type"`
|
||||
State string `json:"state"`
|
||||
PolicyVersion string `json:"policy_version"`
|
||||
EvidenceSummary json.RawMessage `json:"evidence_summary"`
|
||||
ObservedAt time.Time `json:"observed_at"`
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package governance
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type UISettings struct {
|
||||
ID string `json:"id"`
|
||||
State string `json:"state"`
|
||||
DocumentRefreshSeconds int `json:"document_refresh_seconds"`
|
||||
ResourceRefreshSeconds int `json:"resource_refresh_seconds"`
|
||||
StalledAfterSeconds int `json:"stalled_after_seconds"`
|
||||
FinalizingAfterSeconds int `json:"finalizing_after_seconds"`
|
||||
UpdatedBy string `json:"updated_by"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ActivatedAt *time.Time `json:"activated_at"`
|
||||
RetiredAt *time.Time `json:"retired_at"`
|
||||
ErrorCode string `json:"error_code"`
|
||||
}
|
||||
|
||||
type CreateUISettingsCandidateRequest struct {
|
||||
DocumentRefreshSeconds int
|
||||
ResourceRefreshSeconds int
|
||||
StalledAfterSeconds int
|
||||
FinalizingAfterSeconds int
|
||||
UpdatedBy string
|
||||
Now time.Time
|
||||
}
|
||||
|
||||
func (request CreateUISettingsCandidateRequest) Valid() bool {
|
||||
return oneOfInt(request.DocumentRefreshSeconds, 15, 30, 60) &&
|
||||
oneOfInt(request.ResourceRefreshSeconds, 30, 60) &&
|
||||
oneOfInt(request.StalledAfterSeconds, 1800, 3600) &&
|
||||
oneOfInt(request.FinalizingAfterSeconds, 7200, 14400) &&
|
||||
validSettingsActor(request.UpdatedBy) && !request.Now.IsZero()
|
||||
}
|
||||
|
||||
func oneOfInt(value int, allowed ...int) bool {
|
||||
for _, candidate := range allowed {
|
||||
if value == candidate {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func validSettingsActor(value string) bool {
|
||||
trimmed := strings.TrimSpace(value)
|
||||
return trimmed == value && len(trimmed) >= 2 && len(trimmed) <= 128 && !strings.ContainsAny(trimmed, "\x00\r\n\t")
|
||||
}
|
||||
Reference in New Issue
Block a user