Sanity Library Reference Docs
    Preparing search index...
    interface CreateBenchOptions {
        access?: WorkflowAccess;
        attributes?: UserAttributes;
        client?: TestClient;
        currentUser?: Actor;
        documents?: StoreDocument[];
        executionContext?: DeclaredExecutionContext;
        grants?: Grant[];
        now?: string;
        resourceClients?: ResourceClientResolver;
        serveResources?: WorkflowResource[];
        tag?: string;
        workflowResource?: WorkflowResource;
    }
    Index

    Properties

    The bench's default identity (actor + grants + optional attributes), registered as the default token on the fake client — the engine token-resolves it like production. Defaults to ALL_ACCESS — wildcard user + wildcard grants. Pass a restrictive value to test denial paths.

    Mutually exclusive with the currentUser / grants / attributes shortcuts (which compose into the same shape internally).

    attributes?: UserAttributes

    Shortcut for access.attributes — advisory $attributes bag for soft gates.

    client?: TestClient

    Shared TestClient. If omitted, the bench creates its own — two benches without a shared client are completely isolated, regardless of tag. Pass the same client to two benches to test tag-scoped visibility across a shared store.

    currentUser?: Actor

    Shortcut for access.actor. Composed with grants / attributes.

    documents?: StoreDocument[]

    Subject documents seeded into the store.

    executionContext?: DeclaredExecutionContext

    Declared execution context stamped (with the inferred runtime) on every history entry the bench's engine calls append. Defaults to { kind: "test" }; override to exercise provenance rendering.

    grants?: Grant[]

    Shortcut for access.grants. Composed with currentUser / attributes.

    now?: string

    Freeze the bench clock at this ISO instant from construction, so $now and every engine timestamp are deterministic. Equivalent to calling BenchState.setNow immediately after createBench. Omit to start on the wall clock (advance / setNow can freeze it later).

    resourceClients?: ResourceClientResolver

    Cross-resource read routing for the bench engine scope — a served resource is also part of the declared surface for written refs. The escape hatch for resolver logic beyond same-store siblings; prefer CreateBenchOptions.serveResources, which is consulted first when both are given. Omit for single-resource benches.

    serveResources?: WorkflowResource[]

    Sibling datasets the bench serves (and thereby declares) from its own store — the common cross-resource case. Each listed resource routes to a withConfig-derived handle over the bench's store, so reads reach it and runtime-supplied refs into it are admitted. Only dataset resources can be siblings of the bench's store; anything else needs CreateBenchOptions.resourceClients.

    tag?: string

    Engine-scope environment partition. Defaults to BENCH_TAG. Pass different tags to two benches sharing a client to assert partition isolation; pass the same tag to assert visibility through a shared partition.

    The tag must be ASCII lowercase + digits + dashes, no leading dash, no dots — validated at construction.

    workflowResource?: WorkflowResource

    Workflow resource the bench's engine operates against. Mirrors @sanity/client's ClientConfigResource. Defaults to { type: "dataset", id: "test.test" } so all bench-minted GDR URIs read as dataset:test:test:<docId>.