import type { TestEvents, TestOperationDto, TestProgressDto, TestResultsArgs, TestResultsPage, TestTarget } from '@histoire/cli/protocol/tests';
import type { HistoireTestRunSummary } from '@histoire/shared';
import type { RuntimeCatalog } from '../../catalog/publication.js';
import type { ExecutionService } from '../../execution-service.js';
import type { ExecutionTask } from '../../execution-types.js';
import type { ProjectRuntimeHandle } from '../../types.js';
import type { ProjectionLimits } from './projection.js';
import type { StoreLimits } from './store.js';
/** Runner progress as reported by the existing runner. */
type RunProgress = Pick<TestProgressDto, 'phase' | 'completed' | 'total'>;
/** Builds one story/variant/all task; the default is the existing `createHistoireTestTask`. */
export type StoryTaskFactory = (target: {
    storyId?: string;
    variantId?: string;
}, onRunProgress: (progress: RunProgress) => void) => ExecutionTask<HistoireTestRunSummary>;
/** Inputs of the per-generation test service. */
export interface TestsServiceOptions {
    /** Active runtime generation; supplies the context and the activity fence. */
    handle: Pick<ProjectRuntimeHandle, 'context' | 'epoch' | 'isActive'>;
    /** Canonical catalog of the generation. */
    catalog: RuntimeCatalog | undefined;
    /** Terminal-scoped execution owner over the shared lane. */
    execution: ExecutionService;
    /** Parent event sink; dropped by the adapter once the generation retires. */
    emit: <K extends keyof TestEvents & string>(event: K, data: TestEvents[K]) => void;
    /** Aborted when the generation is released: stop publishing. */
    signal: AbortSignal;
    /** Replaces the runner task factory (tests only). */
    createStoryTask?: StoryTaskFactory;
    /** Replaces projection bounds (tests only). */
    projection?: ProjectionLimits;
    /** Replaces retention bounds (tests only). */
    store?: StoreLimits;
    /** Minimum gap between `tests.progress` events. */
    progressIntervalMs?: number;
}
/** What a caller learns on admission. */
export interface AdmittedRun {
    /** Snapshot right after admission (queued). */
    operation: TestOperationDto;
    /** Resolves, never rejects, with the final snapshot once the lane released and the result was published or suppressed. */
    settled: Promise<TestOperationDto>;
    /** Batch stories without a produced result (carry them into a successor); empty for single targets. */
    pending: () => string[];
}
/**
 * Terminal-owned test operations for one runtime generation. Every run goes
 * through the terminal-scoped owner of the shared FIFO lane: cancelling it
 * touches only terminal submissions, and the lane stays occupied until the
 * runner confirmed cleanup.
 * @param options Generation-scoped capabilities.
 */
export declare function createTestsService(options: TestsServiceOptions): {
    /**
     * Admits a test run for an exact target and returns promptly after admission.
     * @param target All, one story or one variant.
     * @param expectedRevision Refuses when the catalog moved on.
     */
    run(target: TestTarget, expectedRevision?: string): AdmittedRun;
    /**
     * Admits an affected-subset batch: per-story tasks are captured now and run
     * sequentially inside ONE lane submission (never enqueued individually).
     * @param storyIds Exact story IDs; duplicates collapse, unknown IDs reject the whole batch.
     * @param expectedRevision Refuses when the catalog moved on.
     */
    runAffected(storyIds: readonly string[], expectedRevision?: string): AdmittedRun;
    /**
     * Snapshot of an active or retained operation.
     * @param operationId Exact operation.
     */
    get: (operationId: string) => TestOperationDto;
    /** One page of retained cases, or an explicit unavailable reason. */
    results(args: TestResultsArgs): TestResultsPage;
    /**
     * Requests cancellation of exactly this operation. The state becomes
     * `cancelling` and stays so until the lane confirmed cleanup.
     * @param operationId Exact operation.
     */
    cancel(operationId: string): TestOperationDto;
    /** Operations admitted and not yet concluded. */
    readonly activeCount: number;
};
/** Service type returned by {@link createTestsService}. */
export type TestsService = ReturnType<typeof createTestsService>;
export {};
//# sourceMappingURL=service.d.ts.map