package testweknora import ( "context" "knowledge-governance/internal/platform/weknora" ) // IdentityProvider is implemented by the production WeKnora access client. Unit // fakes may omit it; a handler must then treat stored identities as unverifiable // and never write/delete/adopt an object across instances. type IdentityProvider interface { TargetIdentity(context.Context, string) (weknora.InstanceIdentity, error) } func resolveIdentity(ctx context.Context, client any, knowledgeBaseID string) (weknora.InstanceIdentity, bool, error) { provider, ok := client.(IdentityProvider) if !ok { return weknora.InstanceIdentity{}, false, nil } identity, err := provider.TargetIdentity(ctx, knowledgeBaseID) if err != nil { return weknora.InstanceIdentity{}, true, err } identity.BaseURL = weknora.NormalizeInstanceURL(identity.BaseURL) return identity, true, nil } // identityMatches requires BOTH the instance address and the owning tenant to // match. A cloned instance can expose the same knowledge base id and tenant id; // an empty stored identity is never treated as "matches anything". func identityMatches(storedURL string, storedTenant uint64, current weknora.InstanceIdentity) bool { if storedURL == "" || storedTenant == 0 { return false } return weknora.NormalizeInstanceURL(storedURL) == weknora.NormalizeInstanceURL(current.BaseURL) && storedTenant == current.TenantID }