merged from gramsrv upstream

This commit is contained in:
onysd 2026-09-01 12:06:31 +03:00
parent 79c64ee916
commit 21a0856587
651 changed files with 54774 additions and 4590 deletions

View file

@ -46,7 +46,7 @@ func TestResolveInheritedAuthKeyLayerUsesAuthKeyAuthorityOnly(t *testing.T) {
}{
{name: "auth key primary", keyLayer: 225, authorization: 227, want: 225, found: true},
{name: "authorization mirror is not protocol evidence", keyLayer: 0, authorization: 225},
{name: "unsupported primary is authoritative unknown", keyLayer: 229, authorization: 227, found: true},
{name: "unsupported primary is authoritative unknown", keyLayer: 230, authorization: 227, found: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@ -104,6 +104,34 @@ func TestResolveInheritedAuthKeyLayerNormalizesBoundTempToPermanent(t *testing.T
}
}
func TestPositiveBindingResolutionIsSharedByLayerAndDispatchPaths(t *testing.T) {
rawAuthKeyID := [8]byte{0x31, 1}
permAuthKeyID := [8]byte{0x32, 1}
const sessionID = int64(311)
auth := &captureAuthService{
resolvedAuthKeyID: permAuthKeyID,
hasResolved: true,
authKeyClientInfos: map[[8]byte]domain.AuthKeyClientInfo{
permAuthKeyID: {Layer: 227},
},
}
sessions := &captureSessions{}
r := New(Config{DC: 2, TempKeyResolveCacheTTL: time.Minute}, Deps{
Auth: auth, Sessions: sessions,
}, zaptest.NewLogger(t), clock.System)
if layer, found, err := r.ResolveInheritedAuthKeyLayer(context.Background(), rawAuthKeyID); err != nil || !found || layer != 227 {
t.Fatalf("inherited layer = (%d,%v,%v), want (227,true,nil)", layer, found, err)
}
if got, err := r.effectiveAuthKeyID(context.Background(), rawAuthKeyID, sessionID); err != nil || got != permAuthKeyID {
t.Fatalf("effective auth key = (%x,%v), want (%x,nil)", got, err, permAuthKeyID)
}
freezeAndPublishLayer(t, r, rawAuthKeyID, sessionID, 10, 1, 227)
if auth.resolveCount != 1 {
t.Fatalf("ResolveAuthKey calls across inherited/dispatch/publication = %d, want 1", auth.resolveCount)
}
}
func TestResolveInheritedAuthKeyLayerMarksOnlyAvailabilityFailures(t *testing.T) {
boom := errors.New("postgres temporarily unavailable")
for _, tt := range []struct {
@ -254,8 +282,8 @@ func TestBindTempAuthKeyLayerPrecedenceAndRawShadow(t *testing.T) {
auth := &captureAuthService{authKeyClientInfos: map[[8]byte]domain.AuthKeyClientInfo{
permAuthKeyID: {Layer: 225},
}}
// Model the store-owned bind transaction. The router must only reload
// this merged permanent primary; it must not derive or persist a winner
// Model the store-owned bind transaction. Bind returns the exact committed
// tuple; the router must not re-read a later permanent row or derive a winner
// from its process-local exact-session registry after Bind returns.
auth.bindTempHook = func(domain.TempAuthKeyBinding) error {
auth.authKeyClientInfos[rawAuthKeyID] = domain.AuthKeyClientInfo{Layer: tt.want, LayerObservationID: 42}
@ -273,6 +301,10 @@ func TestBindTempAuthKeyLayerPrecedenceAndRawShadow(t *testing.T) {
if err != nil || !ok {
t.Fatalf("bind = (%v,%v), want (true,nil)", ok, err)
}
if auth.authKeyInfoLookups != 0 || auth.authorizationLookups != 0 {
t.Fatalf("bind re-read durable Layer state: key=%d authorization=%d",
auth.authKeyInfoLookups, auth.authorizationLookups)
}
if got := auth.authKeyClientInfos[rawAuthKeyID].Layer; got != tt.want {
t.Fatalf("raw shadow = %d, want %d", got, tt.want)
}
@ -324,7 +356,7 @@ func TestResolveInheritedBoundTempUnsupportedPermanentBlocksRawShadow(t *testing
hasResolved: true,
authKeyClientInfos: map[[8]byte]domain.AuthKeyClientInfo{
rawAuthKeyID: {Layer: 225},
permAuthKeyID: {Layer: 229},
permAuthKeyID: {Layer: 230},
},
}
r := New(Config{DC: 2}, Deps{Auth: auth}, zaptest.NewLogger(t), clock.System)
@ -347,11 +379,11 @@ func TestBindTempAuthKeyFuturePermanentClearsInheritedUntilFreshExplicit(t *test
hasResolved: true,
authKeyClientInfos: map[[8]byte]domain.AuthKeyClientInfo{
rawAuthKeyID: {Layer: 225},
permAuthKeyID: {Layer: 229, LayerObservationID: 44},
permAuthKeyID: {Layer: 230, LayerObservationID: 44},
},
}
auth.bindTempHook = func(domain.TempAuthKeyBinding) error {
auth.authKeyClientInfos[rawAuthKeyID] = domain.AuthKeyClientInfo{Layer: 229, LayerObservationID: 44}
auth.authKeyClientInfos[rawAuthKeyID] = domain.AuthKeyClientInfo{Layer: 230, LayerObservationID: 44}
return nil
}
sessions := &inheritedLayerCaptureSessions{}
@ -389,7 +421,7 @@ func TestBindTempAuthKeyFuturePermanentClearsInheritedUntilFreshExplicit(t *test
func TestSupportedExplicitEvidenceClearsUnsupportedCacheState(t *testing.T) {
authKeyID := [8]byte{0x63, 1}
auth := &captureAuthService{authKeyClientInfos: map[[8]byte]domain.AuthKeyClientInfo{
authKeyID: {Layer: 229},
authKeyID: {Layer: 230},
}}
r := New(Config{DC: 2}, Deps{Auth: auth}, zaptest.NewLogger(t), clock.System)
if layer, found, err := r.ResolveInheritedAuthKeyLayer(context.Background(), authKeyID); err != nil || !found || layer != 0 {