import PQueue from 'p-queue'; import { EventEmitter } from 'node:events'; import type { Region } from '../index.js'; export declare enum Events { CHECK_REGISTERED = "CHECK_REGISTERED", CHECK_INPROGRESS = "CHECK_INPROGRESS", CHECK_ATTEMPT_RESULT = "CHECK_ATTEMPT_RESULT", CHECK_FAILED = "CHECK_FAILED", CHECK_SUCCESSFUL = "CHECK_SUCCESSFUL", CHECK_FINISHED = "CHECK_FINISHED", RUN_STARTED = "RUN_STARTED", RUN_FINISHED = "RUN_FINISHED", ERROR = "ERROR", MAX_SCHEDULING_DELAY_EXCEEDED = "MAX_SCHEDULING_DELAY_EXCEEDED", STREAM_LOGS = "STREAM_LOGS", CANCEL = "CANCEL", DETACH = "DETACH", MAX_FAILURES_REACHED = "MAX_FAILURES_REACHED" } export type PrivateRunLocation = { type: 'PRIVATE'; id: string; slugName: string; }; export type PublicRunLocation = { type: 'PUBLIC'; region: keyof Region; }; export type RunLocation = PublicRunLocation | PrivateRunLocation; export type CheckRunId = string; export type SequenceId = string; export type CheckFailure = { timedOut?: boolean; }; export declare const DEFAULT_CHECK_RUN_TIMEOUT_SECONDS = 600; export declare const DEFAULT_PLAYWRIGHT_CHECK_RUN_TIMEOUT_SECONDS = 1200; export declare const MAX_SCHEDULING_DELAY_SECONDS = 900; export default abstract class AbstractCheckRunner extends EventEmitter { checks: Map; testSessionId?: string; timeouts: Map; schedulingDelayExceededTimeout?: NodeJS.Timeout; accountId: string; timeout: number; verbose: boolean; protected detach: boolean; queue: PQueue; readonly maxFailures?: number; private _maxFailuresReached; private stopped; private failProcessing?; constructor(accountId: string, timeout: number, verbose: boolean, detach?: boolean, maxFailures?: number); get maxFailuresReached(): boolean; abstract scheduleChecks(checkRunSuiteId: string): Promise<{ testSessionId?: string; /** Present when the run was dispatched asynchronously (POST /v1/test-sessions/run). */ schedulingId?: string; checks: Array<{ check: any; sequenceId: SequenceId; }>; }>; run(): Promise; /** * Watches the run's scheduling operation and rejects with * {@link TestSessionSchedulingFailedError} if the background dispatch fails. * Never resolves: on successful dispatch the results keep streaming over * MQTT and there is nothing to report. Watching is best-effort — polling * errors (abort, network issues) never fail the run. */ private watchScheduling; /** * Detach-mode counterpart of {@link watchScheduling}: waits for the * scheduling operation to finish and throws if dispatch failed. Polling * errors are swallowed (best-effort), matching the watch. */ private assertSchedulingSucceeded; private configureResultListener; private processMessage; processCheckResult(result: any): Promise; private allChecksFinished; /** * Resolves once `maxFailures` checks have failed while other checks are * still unfinished; never resolves otherwise (including when the failure * that reaches the limit is the last check, which finishes the run * normally). A failure is a check's final outcome: failed retry attempts * and cancelled results do not count, so a check that passes on retry never * stops the run. * * The stop happens synchronously in the CHECK_FINISHED listener, which every * terminal path emits right after the outcome event. Stopping before the * promise resolves keeps any result processed in the meantime from being * reported. */ private maxFailuresReachedOrNever; private setAllTimeouts; /** * Restart the result timeout for a check that is still running, without * the scheduling-delay headroom. Called when the run starts and on every * retry attempt. The timeout guards against a * result that never arrives, not against a long but progressing retry * sequence; the backend caps retries by count and cumulative time, so the * total wait stays bounded. Only call this while the check is not terminal. */ private resetTimeout; private armTimeout; /** Drops every pending timer and queued result: nothing more is reported. */ private stop; private disableAllTimeouts; private startSchedulingDelayTimeout; /** * `fn` for a timer: an error it throws, e.g. from a reporter listening to * the events it emits, fails the run instead of ending the process as an * uncaught exception. */ private failingRun; private disableTimeout; private getShortLinks; }