Skip to content

fga model test: allow configuring MaxTypesPerAuthorizationModel for embedded server #640

Description

@nverbos-godaddy

Description

fga model test uses an embedded OpenFGA server with memory.New() which defaults MaxTypesPerAuthorizationModel to 100. This limit cannot be configured via a flag or environment variable, causing tests to fail for authorization models with more than 100 type definitions — even though the production OpenFGA server supports configuring this limit via --max-types-per-authorization-model or OPENFGA_MAX_TYPES_PER_AUTHORIZATION_MODEL.

Steps to reproduce

  1. Create an authorization model with >100 type definitions (e.g., using modular fga.mod composition)
  2. Run fga model test --tests tests.fga.yaml
  3. Test fails with:
    Error: error running tests due to rpc error: code = Code(2053) desc = The number of type definitions in an authorization model exceeds the allowed limit of 100
    

Root cause

In internal/storetest/localstore.go, the embedded server is created with:

datastore := memory.New()
fgaServer, err := server.NewServerWithOpts(
    server.WithDatastore(datastore),
)

memory.New() sets maxTypesPerAuthorizationModel to the default of 100. The existing memory.WithMaxTypesPerAuthorizationModel() option is never used.

Suggested fix

Expose a --max-types-per-authorization-model flag (or respect the OPENFGA_MAX_TYPES_PER_AUTHORIZATION_MODEL environment variable) on fga model test, and pass it through to the memory backend:

datastore := memory.New(
    memory.WithMaxTypesPerAuthorizationModel(maxTypes),
)

This would bring the CLI's local test behavior in line with the production server's configurability.

Workaround

We currently work around this in CI by dynamically generating partial fga.mod files for each module test (including only a subset of modules) to keep each test under 100 types. The full model is restored afterward for deployment via fga model write, which connects to the production server without this limitation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions