import { type AutomergeUrl, type DocHandle, type DocumentId, type DocumentProgress, type Heads, type Message, type QueryState, Repo, type StorageAdapterInterface, type SubductionPolicy } from '@automerge/automerge-repo'; import { type MemorySigner, SedimentreeId } from '@automerge/automerge-subduction'; import { type ExpectStatic } from 'vitest'; import { TestAdapter, type TestConnectionStateProvider, type TestTransportOptions } from '../testing/index.ts'; import { type AutomergeHost } from './automerge-host.ts'; export declare const HOST_AND_CLIENT: [string, string]; export declare const SUBDUCTION_SERVICE_NAME = "test-subduction-service"; export type QueryStateName = QueryState['state']; export declare const FIND_STATES: readonly QueryStateName[]; /** * Window for an assertion that waits on subduction doing its work. * * Every such wait is event-driven or polled, so this is a ceiling on how long a stuck sync takes to * report, never time the suite spends when healthy — a passing wait returns as soon as its condition * holds. It was 5 s, which is only ~2x the slowest test in the suite (2.5 s including teardown), and * CI blew through it three times in one day on a loaded shard: the failures landed at 5.17-5.22 s, * i.e. exactly this budget rather than the thing under test. 15 s restores real headroom while still * failing well inside the job. */ export declare const SYNC_WINDOW_MS = 15000; /** * Window for the handful of negative tests whose subject is that NOTHING happens — no transport at * all, or no handshake to observe — so there is no event to wait on and the window IS the * assertion. Every other negative assertion waits for the refusal itself; see {@link createDenyGate}. */ export declare const NO_TRAFFIC_WINDOW_MS = 500; /** * Drains until the document is evicted: eviction waits out a sync round still pending on it, so one * forced drain can leave it resident. */ export declare const waitForEviction: (expect: ExpectStatic, host: AutomergeHost, documentId: DocumentId) => Promise; /** Resolves once the document satisfies `predicate`, re-checked on each change event. */ export declare const waitForDoc: (handle: { doc(): T | undefined; on(event: 'change', listener: () => void): unknown; off(event: 'change', listener: () => void): unknown; }, predicate: (doc: T | undefined) => boolean, { timeout }?: { timeout?: number; }) => Promise; /** Resolves once `host` holds exactly `expected` heads for the document. */ export declare const waitForHostHeads: (host: AutomergeHost, documentId: DocumentId, expected: Heads, { timeout }?: { timeout?: number; }) => Promise; export declare const SUBDUCTION_MESSAGE_TYPE = "subduction-connection"; /** * A policy denial that latches when it fires. * * Lets a negative assertion rest on the refusal having happened — the peer asked and was told no — * instead of on a guessed delay that is either too short on a loaded box or wasted time on an idle * one. It also fails loudly if the denial never fires, where a sleep would have passed vacuously. */ export declare const createDenyGate: (message?: string) => { /** Body for a policy hook: latches the refusal, then refuses. */ deny: () => never; /** Same, for a predicate that denies by returning `false` rather than throwing. */ refuse: () => boolean; /** Resolve as soon as the gate has refused. */ waitForDenial: () => Promise; }; export declare const waitForQueryState: (progress: DocumentProgress, awaitStates: readonly QueryStateName[], { timeout }?: { timeout?: number; }) => Promise; /** * Read a document's contents from `repo`'s handle cache without issuing a query. * * After a deliberate policy denial the query has already settled `unavailable`, and `repo.find()` * rejects from then on however many times it is polled; the handle still updates when the holder's * re-driven push finally lands. */ export declare const peekDoc: (repo: Repo, url: AutomergeUrl) => T | undefined; export declare const findInStates: (repo: Repo, url: AutomergeUrl, awaitStates?: readonly QueryStateName[], { timeout }?: { timeout?: number; }) => Promise>; type ShareConfig = Exclude[0], undefined>['shareConfig']; export type ConnectedRepoOptions = { storages?: StorageAdapterInterface[]; connectionStateProvider?: TestConnectionStateProvider; shareConfig?: ShareConfig; /** * Per-peer subduction adapter role override. Defaults to `'connect'` for every * peer when omitted (matches the production wiring in `AutomergeHost`). */ roles?: Record; /** * Per-peer `subductionPolicy` override. Defaults to all-permissive for any * peer not listed here. Matches the production wiring in `AutomergeHost`. */ subductionPolicies?: Record; /** * Per-peer `signer` override. When set, the Subduction-level Ed25519 * identity is fixed for that peer, which is what * `SubductionPolicy.authorize{Connect,Fetch,Put}` see as `peerId` / * `requestor` / `author`. Without this, `Repo` mints a fresh * `MemorySigner` on construction and the peer-id is otherwise opaque to * the test, which makes per-peer assertions impossible. */ signers?: Record; /** * Optional per-connection `onMessage` hooks, keyed by index into `connections`. * Each hook is invoked for every message that traverses the indexed * `TestAdapter.createPair` pair, in either direction. */ onMessageByConnection?: Record void>; /** Per-connection transport gates, keyed by index into `connections`; overrides `connectionStateProvider`. */ connectionStateProviderByConnection?: Record; /** Per-connection transport behavior, keyed by index into `connections`. */ transportByConnection?: Record; subductionTimeouts?: NonNullable[0]>['subductionTimeouts']; }; export declare const createRepoTopology: (args: { peers: Peers; connections: [Peer, Peer][]; options?: ConnectedRepoOptions; onMessage?: (message: Message) => void; onMessageByConnection?: Record void>; }) => Promise<{ repos: Repo[]; adapters: [TestAdapter, TestAdapter][]; repoPairs: [Repo, Repo][]; }>; export declare const createHostClientRepoTopology: (options?: ConnectedRepoOptions) => Promise<{ repos: Repo[]; adapters: [TestAdapter, TestAdapter][]; repoPairs: [Repo, Repo][]; }>; /** * 3-peer star topology: `client` in the center, connected to both * `server1` and `server2`. The two servers are NOT connected to each * other. Used to probe per-peer policy granularity (does the bridge let * us deny just one server?). */ export declare const createStarTopology: (options?: ConnectedRepoOptions) => Promise<{ repos: Repo[]; adapters: [TestAdapter, TestAdapter][]; repoPairs: [Repo, Repo][]; }>; export declare const connectAdapters: (pairs: [TestAdapter, TestAdapter][], options?: { noEmitPeerCandidate?: boolean; repoPairs?: [Repo, Repo][]; }) => Promise; export declare const disconnectAdapters: (pairs: [TestAdapter, TestAdapter][]) => void; export declare const reconnectAdapters: (pairs: [TestAdapter, TestAdapter][], options?: { repoPairs?: [Repo, Repo][]; }) => Promise; export declare const shutdownRepo: (repo: Repo) => Promise; export declare const createRepo: (options?: ConstructorParameters[0], cleanupOptions?: { registerCleanup?: boolean; }) => Repo; /** * Barrier for "every pending subduction commit is durable and serveable". * * `Repo.flush()` forces the throttled subduction save and waits for the storage-bridge write. A * peer fetch that races an unflushed save settles success-empty with nothing to re-ask, so that * miss is permanent (`Document is unavailable`, a push that never fires) rather than slow. * * Deliberately says nothing about delivery: a positive assertion polls the receiver until the doc * lands, and a negative one latches on the refusal ({@link createDenyGate}), so neither needs a * guessed settle window. */ export declare const waitForSubductionSave: (repos: Repo[]) => Promise; export declare const createSqliteAdapter: (filename?: string) => Promise; export type HookName = 'authorizeConnect' | 'authorizeFetch' | 'authorizePut' | 'filterAuthorizedFetch'; export declare const PERMISSIVE_POLICY: SubductionPolicy; /** * A counting wrapper around a base policy. Returns the policy itself plus a * `counters` record (post-call counts per hook) and a `calls` log keyed by * hook with the raw argument tuple as observed at the bridge boundary. * * Useful for "how many times did `authorizeFetch` actually fire on the * proactive-push path?" style questions where the answer is otherwise * indistinguishable from "the hook fired but allowed everything". * * The base policy defaults to all-permissive; pass a partial override to * change individual hooks while still getting counters on the others. */ export declare const createCountingPolicy: (base?: Partial) => { policy: SubductionPolicy; counters: Record; calls: Array<{ hook: HookName; args: unknown[]; }>; }; /** * Map a base58check-encoded `DocumentId` to the 32-byte `SedimentreeId` that * subduction sees. Mirrors `toSedimentreeId(...)` from * `@automerge/automerge-repo/dist/subduction/helpers` (not re-exported from * the package root) and the inverse `sedimentreeIdToDocumentId` helper in * the edge DO. * * Implemented here rather than imported so a future upstream refactor of * `helpers.js` cannot silently change the test's encoding assumptions. */ export declare const documentIdToSedimentreeId: (documentId: DocumentId) => SedimentreeId; /** {@link documentIdToSedimentreeId} in the string form `SedimentreeId.toString()` produces. */ export declare const documentIdToSedimentreeIdString: (documentId: DocumentId) => string; /** * Build a per-sedimentree gate keyed by an allow-set of `SedimentreeId` * string representations (the same format `SedimentreeId.toString()` * produces). The chosen hook denies (throws) for any sedimentree NOT in the * allow set; the other three hooks stay permissive. * * The allow set is read on every call (it's a closure-captured `Set`), so * tests can mutate it mid-run when probing recovery. */ export declare const denyExceptSedimentrees: (allow: Set, hook: 'authorizePut' | 'authorizeFetch') => SubductionPolicy; /** * Build a per-peer gate. The chosen hook denies (throws) for peers whose * `peerId.toString()` matches one of the supplied strings; the other hooks * stay permissive. `authorizePut` uses the `requestor` argument as the * peer-identity key; change to `author` if/when a test requires it. */ export declare const denyPeers: (deniedPeerIds: Set, hook: 'authorizeConnect' | 'authorizePut' | 'authorizeFetch') => SubductionPolicy; export {}; //# sourceMappingURL=subduction-test-utils.d.ts.map