Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270/** Deterministic workload types and failure rendering shared by this package's runners and property files. A workload drives one concurrent map through a mapper adapter: each generated call blocks on its own gate, and the runner releases gates one per step in a generated order. Everything the mapper does is decided by the workload, so two implementations fed the same workload produce directly comparable traces. @module */
import { caughtValueText, } from '@monochromatic-dev/module-caught-value/ts';
//region Types
/** One generated call: its stable id and what its mapper call does. `throwSync` throws from a synchronous function body on entry (never waiting for its gate); the other behaviors block on the call's gate first. */export type CallSpec = { /** Stable identifier appearing in every trace entry. */ readonly id: string; /** Outcome the mapper call produces. */ readonly behavior: 'resolve' | 'reject' | 'throwSync' | 'skip';};
/** Fully generated map workload: calls, source shape, bounds, and release order. */export type MapWorkload = { /** Concurrency bound for the run. */ readonly concurrency: number; /** Whether the run rejects on the first mapper failure. */ readonly stopOnError: boolean; /** Backpressure bound for the streaming variant. */ readonly backpressure: number; /** Whether iterated elements are plain values or already-resolved promises. */ readonly elementKind: 'value' | 'promise'; /** Whether the source is walked synchronously or asynchronously. */ readonly sourceKind: 'sync' | 'async'; /** Calls to run, in scheduling order. */ readonly calls: readonly CallSpec[]; /** Ids released one per step; a permutation of the call ids. */ readonly releaseOrder: readonly string[];};
/** Pull and close telemetry recorded from the instrumented source. */export type SourceTelemetry = { /** Number of `next` calls the run made on the source. */ pulls: number; /** Number of `return` calls the run made on the source. */ closes: number;};
/** One mapper call as the runner drives it: the awaited element, its position, and the outcome it produces. */export type WorkloadMapper = ( element: string, index: number,) => string | symbol | PromiseLike<string | symbol>;
/** Minimal mapper surface the runners drive: one implementation adapter per mapper under comparison. */export type MapAdapter = { /** The implementation's `pMapSkip` sentinel, returned by skip calls. */ readonly skip: symbol; /** Runs one concurrent map over the instrumented source and normalizes its settlement. */ readonly run: (call: MapAdapterCall,) => Promise<MapAdapterOutcome>; /** Runs one streaming map over the instrumented source. */ readonly stream: (call: MapAdapterCall,) => AsyncIterable<string | symbol>;};
/** One adapter-driven concurrent map: source, mapper, and bounds. */export type MapAdapterCall = { /** Instrumented source walked by the implementation. */ readonly iterable: Iterable<string | Promise<string>> | AsyncIterable<string | Promise<string>>; /** Workload mapper producing ids, failures, and skip sentinels. */ readonly mapper: WorkloadMapper; /** Concurrency bound for the run. */ readonly concurrency: number; /** Whether the run rejects on the first mapper failure. */ readonly stopOnError: boolean; /** Backpressure bound for the streaming variant. */ readonly backpressure: number;};
/** Normalized settlement of one concurrent map. */export type MapAdapterOutcome = { /** Whether the run resolved or rejected. */ readonly status: 'resolved' | 'rejected'; /** Result ids in result order; empty for a rejected run. */ readonly values: readonly string[]; /** Rejection error name; empty for a resolved run. */ readonly reasonName: string; /** Rejection error message; empty for a resolved run. */ readonly reasonMessage: string; /** Messages of every `AggregateError` member; empty unless the run rejected with one. */ readonly aggregated: readonly string[];};
/** Observable trace of one concurrent-map workload run. */export type MapTrace = { /** Call ids in the order their mapper calls started. */ readonly startOrder: readonly string[]; /** Running-call count observed from inside each started mapper, in start order. */ readonly activeAtStart: readonly number[]; /** Highest number of simultaneously running mapper calls observed. */ readonly maxOverlap: number; /** Source pulls and closes observed during the run. */ readonly telemetry: SourceTelemetry; /** Normalized settlement of the run. */ readonly outcome: MapAdapterOutcome;};
/** Observable trace of one streaming-map workload run. */export type IterableTrace = { /** Yielded ids in yield order. */ readonly yielded: readonly string[]; /** Error name the iteration threw; empty when it completed. */ readonly thrownName: string; /** Error message the iteration threw; empty when it completed. */ readonly thrownMessage: string; /** Source pulls and closes observed during the run. */ readonly telemetry: SourceTelemetry; /** Highest observed count of mapper results resolved but not yet collected. */ readonly maxBacklog: number;};
//endregion Types
//region Failures
/** Builds the deterministic failure a rejecting mapper call throws, so both implementations under comparison fail with text compared exactly. @param id - Id of the failing call. @returns Error whose message is derived only from the call id. @example ```ts failureFor('c3').message; // => 'failure c3' ``` */export function failureFor(id: string,): Error { return new Error(`failure ${id}`,);}
/** Renders a rejection reason for comparison across implementations. @param reason - Rejection reason observed by the runner. @returns Name and message of the reason, normalized for deep comparison. @example ```ts describeRejection(new TypeError('bad',),); // => { reasonName: 'TypeError', reasonMessage: 'bad' } ``` */export function describeRejection(reason: unknown,): { readonly reasonName: string; readonly reasonMessage: string;} { if (Error.isError(reason,)) return { reasonName: reason.name, reasonMessage: reason.message, };
return { reasonName: 'ThrownValue', reasonMessage: caughtValueText(reason,), };}
//endregion Failures