/** * TestRuntime and harness for testing the CRE SDK runtime without WASM. * Registry is scoped per test via AsyncLocalStorage; use testWithRuntime to run tests with a registry. */ import type { Any } from '@bufbuild/protobuf/wkt'; import type { RuntimeHelpers } from '../impl/runtime-impl'; import { RuntimeImpl } from '../impl/runtime-impl'; import { TestWriter } from './test-writer'; /** Error message when response exceeds max size. Used by the harness when its await implements the size check. */ export declare const RESPONSE_BUFFER_TOO_SMALL = "response buffer too small"; export declare const DEFAULT_MAX_RESPONSE_SIZE_BYTES: number; export declare const REPORT_METADATA_HEADER_LENGTH = 109; export type Secrets = Map>; export type CapabilityHandler = (request: { id: string; method: string; payload: Any; }) => { response: { case: 'payload'; value: Any; }; } | { response: { case: 'error'; value: string; }; }; /** * Returns the capability handler for the given id from the current test's registry, if any. * Only defined when called inside a testWithRuntime scope (after the handler is registered). */ export declare function getTestCapabilityHandler(id: string): CapabilityHandler | undefined; /** * Registers a capability handler for the current test's registry. * Must be called inside a testWithRuntime scope; throws if no registry is active. */ export declare function registerTestCapability(id: string, handler: CapabilityHandler): void; /** * Gets a mock instance from the current test's registry, or undefined if not found or no registry active. * @internal Used by generated mocks for singleton pattern. */ export declare function __getTestMockInstance(id: string): T | undefined; /** * Stores a mock instance in the current test's registry. * @internal Used by generated mocks for singleton pattern. */ export declare function __setTestMockInstance(id: string, instance: T): void; /** * Test-only: returns the current registry store (for cleanup/isolation assertions). * Do not use in production code. */ export declare function __testOnlyRegistryStore(): object | undefined; /** * Test-only: runs a callback with a fresh registry and cleans up (for cleanup/failure tests). * Do not use in production code. */ export declare function __testOnlyRunWithRegistry(fn: () => void | Promise): Promise; export interface TestRuntimeState { timeProvider?: () => number; } export interface NewTestRuntimeOptions { timeProvider?: () => number; maxResponseSize?: number; } /** * Runs a test using the CRE runtime. */ export declare function test(title: string, fn: () => void | Promise): void; /** * Creates a test runtime. This must be called from within a test in this package. */ export declare function newTestRuntime(secrets?: Secrets | null, options?: NewTestRuntimeOptions): TestRuntime; /** * TestRuntime is a Runtime implementation for unit tests. Extends RuntimeImpl; construct via newTestRuntime. * Adds getLogs() and setTimeProvider(). Registry is accessed via getTestCapabilityHandler when inside testWithRuntime. */ export declare class TestRuntime extends RuntimeImpl { private readonly testWriter; private readonly state; constructor(helpers: RuntimeHelpers, maxResponseSize: bigint, testWriter: TestWriter, state: TestRuntimeState); getLogs(): string[]; setTimeProvider(timeProvider: () => number): void; }