a55319d972
build / build (push) Failing after 2m29s
现象:共享桶部署下网关启动即报 gateway_auditor_key_required,残留过期 审计文件则每次 Execute 报 gateway_exclusive_writer_evidence_unverified; 用户已改为“停目标写入容器→更新→启动”的维护式更新。 根因:Gateway.Ready 强制 Isolation.Verify,main 强制 Ed25519 公钥,等于 把整桶独占证明当作发布前置;这与共享桶、沿用原 AK 的实际部署矛盾。 取舍:删除审计校验与相关 env 依赖,保留 journal、治理 PG 只读 authority、 plan/owner/attempt/epoch 绑定、intent-before-send、单次写与精确版本回滚。 create 仅在精确版本读回且仍为 current 时提交;发现外部 latest 只返回冲突, 不在 confirm 阶段删除(journal create intent 已提交,删除会变成无 delete intent/receipt 的未记账副作用并让 intent 永久 held)。同 key 不自动合并。 证据:真实二进制无审计/残留审计两环境通过;kg-pgtest-writeset 一次性库 + 随机 MinIO 桶跑 14 个网关用例(含共享桶共存写者、同 key 既有对象拒绝、 精确回滚)全过;umask 022 下 make verify 本地必需项全 success。
83 lines
4.4 KiB
Go
83 lines
4.4 KiB
Go
package v071
|
|
|
|
import (
|
|
"context"
|
|
"net/http/httptest"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
"knowledge-governance/internal/appconfig"
|
|
"knowledge-governance/internal/objectgateway"
|
|
postgresstore "knowledge-governance/internal/platform/postgres"
|
|
"knowledge-governance/internal/platform/postgres/pgtest"
|
|
)
|
|
|
|
// Exported only into the test binary, so the external-package test exercises
|
|
// librarystack.OpenProductionStack without an import cycle or duplicated fixture.
|
|
type R10AdmissionFixture struct {
|
|
Context context.Context
|
|
Config appconfig.Config
|
|
Snapshot string
|
|
Exec func(string)
|
|
State func() map[string]any
|
|
Unchanged func(map[string]any)
|
|
Save func(string, any)
|
|
}
|
|
|
|
func OpenR10AdmissionFixture(t *testing.T) R10AdmissionFixture {
|
|
t.Helper()
|
|
fx := openWriteSetFixtureWith(t, writeSetFixtureOptions{reset: true, embeddingDimension: 1024})
|
|
seedTargetData(t, fx)
|
|
r10Exec(t, fx, `ALTER TABLE knowledge_bases ADD COLUMN embedding_model_id text; ALTER TABLE knowledge_bases ADD COLUMN vector_store_id text;
|
|
CREATE TABLE models(id text PRIMARY KEY,name text,parameters jsonb,deleted_at timestamptz);
|
|
CREATE TABLE vector_stores(id text PRIMARY KEY,engine_type text,index_config jsonb,deleted_at timestamptz);
|
|
INSERT INTO models VALUES('r10-model','text-embedding-v4','{"embedding_parameters":{"dimension":1024}}',NULL);
|
|
INSERT INTO vector_stores VALUES('r10-vector','elasticsearch_v8','{}',NULL);
|
|
UPDATE knowledge_bases SET embedding_model_id='r10-model',vector_store_id='r10-vector'`)
|
|
if _, e := fx.pool.Exec(fx.ctx, `UPDATE vector_stores SET index_config=jsonb_build_object('index_name',$1::text)`, fx.index); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
dsn := pgtest.IsolatedDatabaseURL(t, os.Getenv("KG_LIBRARY_TEST_DATABASE_URL"))
|
|
governancePool, e := pgxpool.New(fx.ctx, dsn)
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
t.Cleanup(governancePool.Close)
|
|
if e = postgresstore.ApplyMigrations(fx.ctx, governancePool); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if _, e = governancePool.Exec(fx.ctx, objectgateway.Schema); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
reader := gatewayReadOnlyGovernance(t, fx.ctx, governancePool, dsn)
|
|
authority := &GatewayGovernanceAuthority{Pool: reader, ArchiveRoot: fx.archiveRoot, TargetID: "r10-admission", Provider: "minio", Bucket: fx.bucket}
|
|
endpoint := os.Getenv("KG_LIBRARY_TEST_S3_ENDPOINT")
|
|
scope := objectgateway.Digest([]byte("minio\x00" + endpoint + "\x00" + fx.bucket))
|
|
gateway := &objectgateway.Gateway{Pool: governancePool, Scope: scope, Backend: &objectgateway.S3Backend{Client: fx.objects.s3.client, Bucket: fx.bucket, MaxBytes: 1 << 20}, Authority: authority, MaxBytes: 1 << 20}
|
|
token := objectgateway.Digest([]byte("r10-admission-data"))
|
|
server := httptest.NewServer(objectgateway.HTTPServer{Gateway: gateway, DataToken: token, ControlToken: objectgateway.Digest([]byte("r10-admission-control"))})
|
|
t.Cleanup(server.Close)
|
|
config := appconfig.Config{LibraryProductionDatabaseURL: os.Getenv("KG_LIBRARY_TEST_DATABASE_URL"), LibraryProductionElasticURL: fx.searchBase, LibraryProductionIndex: fx.index, LibraryProductionTenantID: wsTargetTenant, LibraryProductionInternalKB: wsTargetKB, LibraryProductionS3Endpoint: endpoint, LibraryProductionS3Provider: "minio", LibraryProductionS3Bucket: fx.bucket, LibraryProductionS3AccessKey: os.Getenv("KG_LIBRARY_TEST_S3_ACCESS_KEY"), LibraryProductionS3SecretKey: os.Getenv("KG_LIBRARY_TEST_S3_SECRET_KEY"), LibraryArchiveRoot: fx.archiveRoot, LibraryObjectGatewayURL: server.URL, LibraryObjectGatewayToken: token}
|
|
snapshot := sealSourceSnapshot(t, fx, nil)
|
|
state := func() map[string]any {
|
|
out := r10State(t, fx)
|
|
for _, table := range []string{"knowledge_bases", "models", "vector_stores", "schema_migrations"} {
|
|
var raw []byte
|
|
if e := fx.pool.QueryRow(fx.ctx, "SELECT coalesce(jsonb_agg(to_jsonb(t) ORDER BY to_jsonb(t)::text),'[]') FROM "+table+" t").Scan(&raw); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
out[table] = string(raw)
|
|
}
|
|
for _, table := range []string{"kg_object_gateway_plans", "kg_object_gateway_intents", "kg_object_gateway_receipts", "kg_object_gateway_deliveries", "kg_object_gateway_grants"} {
|
|
var count int64
|
|
if e := governancePool.QueryRow(fx.ctx, "SELECT count(*) FROM "+table).Scan(&count); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
out[table] = count
|
|
}
|
|
return out
|
|
}
|
|
return R10AdmissionFixture{Context: fx.ctx, Config: config, Snapshot: snapshot, Exec: func(sql string) { r10Exec(t, fx, sql) }, State: state, Save: func(label string, value any) { r10Save(t, label, value) }}
|
|
}
|