import { MetricReader } from "@opentelemetry/sdk-metrics"; import { ControlledAccount, ControlledAgent } from "../coValues/account.js"; import { WasmCrypto } from "../crypto/WasmCrypto.js"; import { type AgentSecret, AnyRawCoValue, type CoID, type CoValueCore, MessagePortLike, type RawAccount, RawAccountID, RawCoMap, type RawCoValue, StorageAPI } from "../exports.js"; import type { RawCoID, SessionID } from "../ids.js"; import { LocalNode } from "../localNode.js"; import type { Peer, SyncMessage, SyncWhen } from "../sync.js"; import { CoValueHeader } from "../coValueCore/verifiedState.js"; export declare function setCurrentTestCryptoProvider(crypto: WasmCrypto): void; export declare function randomAgentAndSessionID(): [ControlledAgent, SessionID]; export declare function agentAndSessionIDFromSecret(secret: AgentSecret): [ControlledAgent, SessionID]; export declare function nodeWithRandomAgentAndSessionID(): LocalNode; export declare function createTestNode(): LocalNode; export declare function createTwoConnectedNodes(node1Role: Peer["role"], node2Role: Peer["role"]): Promise<{ node1: { node: LocalNode; accountID: RawAccountID; accountSecret: AgentSecret; sessionID: SessionID; }; node2: { node: LocalNode; accountID: RawAccountID; accountSecret: AgentSecret; sessionID: SessionID; }; }>; export declare function createThreeConnectedNodes(node1Role: Peer["role"], node2Role: Peer["role"], node3Role: Peer["role"]): Promise<{ node1: { node: LocalNode; accountID: RawAccountID; accountSecret: AgentSecret; sessionID: SessionID; }; node2: { node: LocalNode; accountID: RawAccountID; accountSecret: AgentSecret; sessionID: SessionID; }; node3: { node: LocalNode; accountID: RawAccountID; accountSecret: AgentSecret; sessionID: SessionID; }; }>; export declare function createNConnectedNodes(...nodeRoles: Peer["role"][]): Promise<{ node: LocalNode; accountID: RawAccountID; accountSecret: AgentSecret; sessionID: SessionID; }[]>; export declare function connectTwoPeers(a: LocalNode, b: LocalNode, aRole: "client" | "server", bRole: "client" | "server"): void; export declare function newGroup(): { node: LocalNode; groupCore: import("../exports.js").AvailableCoValueCore; admin: ControlledAgent; }; export declare function groupWithTwoAdmins(): { group: import("../exports.js").RawGroup; groupCore: import("../exports.js").AvailableCoValueCore; admin: ControlledAgent; otherAdmin: ControlledAccount; node: LocalNode; }; export declare function newGroupHighLevel(): { admin: ControlledAgent; node: LocalNode; group: import("../exports.js").RawGroup; }; export declare function groupWithTwoAdminsHighLevel(): { admin: ControlledAgent; node: LocalNode; group: import("../exports.js").RawGroup; otherAdmin: ControlledAccount; }; export declare function shouldNotResolve(promise: Promise, ops: { timeout: number; }): Promise; export declare function waitFor(callback: () => boolean | void | Promise): Promise; export declare function loadCoValueOrFail(node: LocalNode, id: CoID, skipRetry?: boolean): Promise; export declare function blockMessageTypeOnOutgoingPeer(peer: Peer, messageType: SyncMessage["action"], opts: { id?: string; once?: boolean; matcher?: (msg: SyncMessage) => boolean; }): { blockedMessages: SyncMessage[]; sendBlockedMessages: () => Promise; unblock: () => void; }; export declare function hotSleep(ms: number): number; /** * This is a test metric reader that uses an in-memory metric exporter and exposes a method to get the value of a metric given its name and attributes. * * This is useful for testing the values of metrics that are collected by the SDK. * * TODO: We may want to rethink how we access metrics (see `getMetricValue` method) to make it more flexible. */ declare class TestMetricReader extends MetricReader { private _exporter; protected onShutdown(): Promise; protected onForceFlush(): Promise; getMetricValue(name: string, attributes?: { [key: string]: string | number; }): Promise; collectAndExport(): Promise; } export declare function createTestMetricReader(): TestMetricReader; export declare function tearDownTestMetricReader(): void; export declare class SyncMessagesLog { static messages: SyncTestMessage[]; static add(message: SyncTestMessage): void; static clear(): void; static getMessages(coValueMapping: { [key: string]: CoValueCore; }): string[]; static debugMessages(coValueMapping: { [key: string]: CoValueCore; }): void; } export declare function getSyncServerConnectedPeer(opts: { syncServerName?: string; ourName?: string; syncServer?: LocalNode; peerId: string; persistent?: boolean; }): { peer: Peer; peerStateOnServer: import("../PeerState.js").PeerState; peerOnServer: Peer; }; export declare const TEST_NODE_CONFIG: { withAsyncPeers: boolean; }; export declare function setupTestNode(opts?: { isSyncServer?: boolean; connected?: boolean; secret?: AgentSecret; syncWhen?: SyncWhen; enableFullStorageReconciliation?: boolean; experimental_clockSyncFromServerPings?: boolean; }): { node: LocalNode; connectToSyncServer: (opts?: { syncServerName?: string; ourName?: string; syncServer?: LocalNode; persistent?: boolean; skipReconciliation?: boolean; }) => { peerState: import("../PeerState.js").PeerState; peer: Peer; peerStateOnServer: import("../PeerState.js").PeerState; peerOnServer: Peer; }; addStorage: (opts?: { ourName?: string; storage?: StorageAPI; }) => { storage: StorageAPI | import("../exports.js").StorageApiSync; }; addAsyncStorage: (opts?: { ourName?: string; filename?: string; storageName?: string; }) => Promise<{ storage: import("../exports.js").StorageApiAsync; }>; restart: () => Promise; spawnNewSession: () => /*elided*/ any; disconnect: () => void; }; export declare function setupTestAccount(opts?: { isSyncServer?: boolean; connected?: boolean; storage?: StorageAPI; accountID?: RawAccountID; accountSecret?: AgentSecret; experimental_clockSyncFromServerPings?: boolean; }): Promise<{ node: LocalNode; accountID: RawAccountID; account: RawAccount; connectToSyncServer: (opts?: { syncServerName?: string; ourName?: string; syncServer?: LocalNode; }) => { peerState: import("../PeerState.js").PeerState; peer: Peer; peerStateOnServer: import("../PeerState.js").PeerState; peerOnServer: Peer; getCurrentPeerState: () => import("../PeerState.js").PeerState; }; addStorage: (opts?: { ourName?: string; storage?: StorageAPI; }) => { storage: StorageAPI | import("../exports.js").StorageApiSync; }; addAsyncStorage: (opts?: { ourName?: string; storageName?: string; }) => Promise<{ storage: import("../exports.js").StorageApiAsync; }>; spawnNewSession: () => Promise; disconnect: () => void; }>; export type LazyLoadMessage = { action: "lazyLoad"; id: RawCoID; }; export type LazyLoadResultMessage = { action: "lazyLoadResult"; id: RawCoID; header: boolean; sessions: { [sessionID: string]: number; }; }; export type SyncTestMessage = { from: string; to: string; msg: SyncMessage | LazyLoadMessage | LazyLoadResultMessage; }; export declare function connectedPeersWithMessagesTracking(opts: { peer1: { id: string; role: Peer["role"]; name?: string; }; peer2: { id: string; role: Peer["role"]; name?: string; }; persistent?: boolean; }): { peer1: Peer; peer2: Peer; }; export declare function createAccountInNode(node: LocalNode): ControlledAccount; export declare function createUnloadedCoValue(node: LocalNode, type?: AnyRawCoValue["type"]): { coValue: CoValueCore; id: `co_z${string}`; header: CoValueHeader; }; export declare function fillCoMapWithLargeData(map: RawCoMap): RawCoMap<{ [key: string]: import("../jsonValue.js").JsonValue | undefined; }, import("../jsonValue.js").JsonObject | null>; export declare function importContentIntoNode(coValue: CoValueCore, node: LocalNode, chunks?: number): void; /** * Type guard to check if a message is a SyncMessage. */ export declare function isSyncMessage(msg: unknown): msg is SyncMessage; /** * Creates a MessageChannel that logs all sync messages exchanged between ports. * Similar to connectedPeersWithMessagesTracking but for MessageChannel. */ export declare function createTrackedMessageChannel(opts: { port1Name?: string; port2Name?: string; }): { port1: import("worker_threads").MessagePort; port2: import("worker_threads").MessagePort; }; /** * Creates a mock worker target that simulates receiving a port * and calling a callback with the received port (simulating a connection handshake). */ export declare function createMockWorkerWithAccept(onPortReceived: (port: MessagePortLike) => Promise): { postMessage: import("vitest").Mock; }; export {}; //# sourceMappingURL=testUtils.d.ts.map