Files
knowledge-governance/internal/httpapi/library_source_contract_test.go
T
姚章浩 8febe12d7d test(library): 隔离数据契约与 r11 身份自然键矩阵
真实本机 PG/ES/MinIO:v071 目录镜像 10 模式、结构引用/游标 15 模式、
8 表×2 外部范围身份矩阵、13 模式自然键(含软删除与合法同 parent 正例)、
备份期间三注入、收尾故障与授权撤销两个真实治理 PG 用例。

需隔离服务的用例在 test-scope.json 显式声明:普通 CI 跳过不算通过。
2026-11-01 11:35:09 +08:00

24 lines
1.1 KiB
Go

package httpapi
import (
"knowledge-governance/internal/governance"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
)
func TestContractSyncRejectsUnboundSourceBeforeCreatingJob(t *testing.T) {
store := &fakeLibraryStore{current: &governance.LibraryVersion{SnapshotID: "current"}, grant: &governance.LibraryReleaseAuthorization{Scope: "internal", SnapshotID: "foreign", ExpiresAt: time.Now().Add(time.Hour)}}
digest, _ := librarySyncParamsDigest("internal", "foreign")
store.grant.ParamsDigest = digest
config := Config{Store: store, ProductionReleaseRequestsEnabled: true, ProductionBackupRestoreVerified: true, LibraryProductionDatabaseURL: "postgres://unreachable.invalid/db", LibraryCapacityBudgetBytes: 1 << 40}
request := httptest.NewRequest(http.MethodPost, "/api/v1/library/syncs", strings.NewReader(`{"scope":"internal","target_snapshot_id":"foreign"}`))
response := httptest.NewRecorder()
librarySyncEnqueue(response, request, config)
if store.createN != 0 {
t.Fatalf("unbound foreign source created %d jobs; response=%s", store.createN, response.Body.String())
}
}