Files
knowledge-governance/internal/objectgateway/unknown_integration_test.go
T
姚章浩 a55319d972
build / build (push) Failing after 2m29s
fix(objectgateway): 取消整桶独占前置并按维护停写更新
现象:共享桶部署下网关启动即报 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。
2026-11-04 09:45:47 +08:00

70 lines
2.1 KiB
Go

package objectgateway_test
import (
"context"
"errors"
"testing"
"github.com/jackc/pgx/v5/pgxpool"
g "knowledge-governance/internal/objectgateway"
)
type stoppedBeforeSend struct {
g.Backend
calls int
}
func (b *stoppedBeforeSend) Put(context.Context, string, []byte, string) (g.Version, error) {
b.calls++
return g.Version{}, errors.New("injected uncertain send with no visible version")
}
func TestGatewayAbsenceNeverSettlesUnknown(t *testing.T) {
ctx, pool, real := fixture(t)
backend := &stoppedBeforeSend{Backend: real}
grant := g.Grant{Epoch: 1, Owner: g.Digest([]byte(t.Name())), Plan: g.Digest([]byte("plan"))}
gateway := &g.Gateway{Pool: pool, Scope: real.Bucket, Backend: backend, MaxBytes: 1 << 20}
if e := gateway.InstallPlan(ctx, planFor(grant, request(t.Name(), grant))); e != nil {
t.Fatal(e)
}
if e := gateway.Advance(ctx, 0, grant); e != nil {
t.Fatal(e)
}
req := request(t.Name(), grant)
body := []byte("gateway fixture " + t.Name())
if _, e := gateway.Execute(ctx, req, body); !errors.Is(e, g.ErrHeld) {
t.Fatal(e)
}
restarted := *gateway
for i := 0; i < 2; i++ {
if _, e := restarted.Execute(ctx, req, body); !errors.Is(e, g.ErrHeld) {
t.Fatal("absent version treated as terminal", e)
}
}
if backend.calls != 1 {
t.Fatal("PUT replayed", backend.calls)
}
next := grant
next.Epoch++
if e := restarted.Advance(ctx, 1, next); !errors.Is(e, g.ErrHeld) {
t.Fatal("unknown operation allowed epoch handover", e)
}
var n int
if pool.QueryRow(ctx, "SELECT count(*) FROM kg_object_gateway_receipts WHERE scope=$1", gateway.Scope).Scan(&n) != nil || n != 0 {
t.Fatal("absence wrote false terminal receipt")
}
}
func TestGatewayReadOnlyPersistenceBlocksSend(t *testing.T) {
ctx, pool, backend := fixture(t)
cfg := pool.Config()
cfg.ConnConfig.RuntimeParams["default_transaction_read_only"] = "on"
other, e := pgxpool.NewWithConfig(ctx, cfg)
if e != nil {
t.Fatal(e)
}
defer other.Close()
gateway := &g.Gateway{Pool: other, Scope: backend.Bucket, Backend: backend, MaxBytes: 1 << 20}
if e = gateway.Ready(ctx); !errors.Is(e, g.ErrPersistence) {
t.Fatal("read-only persistence accepted", e)
}
}