/** * Signals supported by the subprocess durability harness. * * @example * ```ts * import type { SubprocessSignal } from '@lostgradient/weft/testing'; * const signal: SubprocessSignal = 'SIGKILL'; * ``` */ export type SubprocessSignal = 'SIGINT' | 'SIGKILL' | 'SIGTERM'; /** * Configuration for starting a Weft server in a child Bun process. * * @example * ```ts * import type { SubprocessServerOptions } from '@lostgradient/weft/testing'; * const options: SubprocessServerOptions = { entrypoint: './tmp/entrypoint.ts', databasePath: './tmp/weft.db' }; * ``` */ export interface SubprocessServerOptions { entrypoint: string; databasePath: string; port?: number; hostname?: string; cwd?: string; env?: Record; args?: readonly string[]; readyPattern?: RegExp; startupTimeoutMs?: number; exitTimeoutMs?: number; } declare const subprocessServerHandleBrand: unique symbol; /** Minimal public view of the child process managed by a {@link SubprocessServerHandle}. * @example * ```ts * import type { SubprocessServerProcess } from '@lostgradient/weft/testing'; * declare const server: { process: SubprocessServerProcess }; * const process: SubprocessServerProcess = server.process; * ``` */ export interface SubprocessServerProcess { readonly exited: Promise; readonly exitCode: number | null; readonly signalCode: SubprocessSignal | null; kill(signal?: SubprocessSignal): void; } /** * Handle for a running Weft server subprocess started by * {@link spawnServerSubprocess}. * * @example * ```ts * import { spawnServerSubprocess, type SubprocessServerHandle } from '@lostgradient/weft/testing'; * const server: SubprocessServerHandle = await spawnServerSubprocess({ entrypoint: './tmp/entrypoint.ts', databasePath: './tmp/weft.db' }); * await server.stop(); * ``` */ export interface SubprocessServerHandle extends AsyncDisposable { readonly [subprocessServerHandleBrand]: true; readonly process: SubprocessServerProcess; readonly url: string; readonly port: number; readonly databasePath: string; readonly command: readonly string[]; readonly stdout: string; readonly stderr: string; stop(signal?: SubprocessSignal): Promise; } /** * Starts a Weft server entrypoint in a real Bun subprocess and waits for the * server to print a readiness URL. * * @example * ```ts * import { spawnServerSubprocess } from '@lostgradient/weft/testing'; * const server = await spawnServerSubprocess({ entrypoint: './tmp/entrypoint.ts', databasePath: './tmp/weft.db' }); * await server.stop(); * ``` */ export declare function spawnServerSubprocess(options: SubprocessServerOptions): Promise; /** Kills a running server subprocess and starts a replacement. * @example * ```ts * import { killAndReboot, spawnServerSubprocess } from '@lostgradient/weft/testing'; * const server = await spawnServerSubprocess({ entrypoint: './tmp/entrypoint.ts', databasePath: './tmp/weft.db' }); * const rebooted = await killAndReboot(server); * await rebooted.stop(); * ``` */ export declare function killAndReboot(handle: SubprocessServerHandle, signal?: SubprocessSignal): Promise; /** Runs a callback with a server subprocess and tears it down afterward. * @example * ```ts * import { withSubprocessServer } from '@lostgradient/weft/testing'; * declare const options: Parameters[0]; * await withSubprocessServer(options, async (server) => fetch(`${server.url}/v1/health`)); * ``` */ export declare function withSubprocessServer(options: SubprocessServerOptions, callback: (handle: SubprocessServerHandle) => Promise): Promise; export {};