@smthrs/evals 0.0.0-stage → 1.0.0-rc.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +142 -0
- package/LICENSE +21 -0
- package/README.md +66 -2
- package/dist/cjs/Baseline.d.ts +120 -0
- package/dist/cjs/Baseline.d.ts.map +1 -0
- package/dist/cjs/Baseline.js +160 -0
- package/dist/cjs/Baseline.js.map +7 -0
- package/dist/cjs/CaseExecutor.d.ts +85 -0
- package/dist/cjs/CaseExecutor.d.ts.map +1 -0
- package/dist/cjs/CaseExecutor.js +59 -0
- package/dist/cjs/CaseExecutor.js.map +7 -0
- package/dist/cjs/EvalError.d.ts +64 -0
- package/dist/cjs/EvalError.d.ts.map +1 -0
- package/dist/cjs/EvalError.js +54 -0
- package/dist/cjs/EvalError.js.map +7 -0
- package/dist/cjs/Gate.d.ts +55 -0
- package/dist/cjs/Gate.d.ts.map +1 -0
- package/dist/cjs/Gate.js +88 -0
- package/dist/cjs/Gate.js.map +7 -0
- package/dist/cjs/Regression.d.ts +116 -0
- package/dist/cjs/Regression.d.ts.map +1 -0
- package/dist/cjs/Regression.js +192 -0
- package/dist/cjs/Regression.js.map +7 -0
- package/dist/cjs/Report.d.ts +114 -0
- package/dist/cjs/Report.d.ts.map +1 -0
- package/dist/cjs/Report.js +161 -0
- package/dist/cjs/Report.js.map +7 -0
- package/dist/cjs/Runner.d.ts +229 -0
- package/dist/cjs/Runner.d.ts.map +1 -0
- package/dist/cjs/Runner.js +453 -0
- package/dist/cjs/Runner.js.map +7 -0
- package/dist/cjs/Suite.d.ts +139 -0
- package/dist/cjs/Suite.d.ts.map +1 -0
- package/dist/cjs/Suite.js +221 -0
- package/dist/cjs/Suite.js.map +7 -0
- package/dist/cjs/Trials.d.ts +93 -0
- package/dist/cjs/Trials.d.ts.map +1 -0
- package/dist/cjs/Trials.js +82 -0
- package/dist/cjs/Trials.js.map +7 -0
- package/dist/cjs/index.d.ts +76 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +51 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/internal/CanonicalJson.d.ts +44 -0
- package/dist/cjs/internal/CanonicalJson.d.ts.map +1 -0
- package/dist/cjs/internal/CanonicalJson.js +114 -0
- package/dist/cjs/internal/CanonicalJson.js.map +7 -0
- package/dist/cjs/internal/controlCharacters.d.ts +44 -0
- package/dist/cjs/internal/controlCharacters.d.ts.map +1 -0
- package/dist/cjs/internal/controlCharacters.js +42 -0
- package/dist/cjs/internal/controlCharacters.js.map +7 -0
- package/dist/cjs/internal/scorerLabel.d.ts +33 -0
- package/dist/cjs/internal/scorerLabel.d.ts.map +1 -0
- package/dist/cjs/internal/scorerLabel.js +28 -0
- package/dist/cjs/internal/scorerLabel.js.map +7 -0
- package/dist/cjs/internal/tupleKey.d.ts +20 -0
- package/dist/cjs/internal/tupleKey.d.ts.map +1 -0
- package/dist/cjs/internal/tupleKey.js +25 -0
- package/dist/cjs/internal/tupleKey.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/Baseline.d.ts +120 -0
- package/dist/esm/Baseline.d.ts.map +1 -0
- package/dist/esm/Baseline.js +208 -0
- package/dist/esm/Baseline.js.map +1 -0
- package/dist/esm/CaseExecutor.d.ts +85 -0
- package/dist/esm/CaseExecutor.d.ts.map +1 -0
- package/dist/esm/CaseExecutor.js +60 -0
- package/dist/esm/CaseExecutor.js.map +1 -0
- package/dist/esm/EvalError.d.ts +64 -0
- package/dist/esm/EvalError.d.ts.map +1 -0
- package/dist/esm/EvalError.js +65 -0
- package/dist/esm/EvalError.js.map +1 -0
- package/dist/esm/Gate.d.ts +55 -0
- package/dist/esm/Gate.d.ts.map +1 -0
- package/dist/esm/Gate.js +90 -0
- package/dist/esm/Gate.js.map +1 -0
- package/dist/esm/Regression.d.ts +116 -0
- package/dist/esm/Regression.d.ts.map +1 -0
- package/dist/esm/Regression.js +200 -0
- package/dist/esm/Regression.js.map +1 -0
- package/dist/esm/Report.d.ts +114 -0
- package/dist/esm/Report.d.ts.map +1 -0
- package/dist/esm/Report.js +188 -0
- package/dist/esm/Report.js.map +1 -0
- package/dist/esm/Runner.d.ts +229 -0
- package/dist/esm/Runner.d.ts.map +1 -0
- package/dist/esm/Runner.js +455 -0
- package/dist/esm/Runner.js.map +1 -0
- package/dist/esm/Suite.d.ts +139 -0
- package/dist/esm/Suite.d.ts.map +1 -0
- package/dist/esm/Suite.js +255 -0
- package/dist/esm/Suite.js.map +1 -0
- package/dist/esm/Trials.d.ts +93 -0
- package/dist/esm/Trials.d.ts.map +1 -0
- package/dist/esm/Trials.js +117 -0
- package/dist/esm/Trials.js.map +1 -0
- package/dist/esm/index.d.ts +76 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +76 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal/CanonicalJson.d.ts +44 -0
- package/dist/esm/internal/CanonicalJson.d.ts.map +1 -0
- package/dist/esm/internal/CanonicalJson.js +202 -0
- package/dist/esm/internal/CanonicalJson.js.map +1 -0
- package/dist/esm/internal/controlCharacters.d.ts +44 -0
- package/dist/esm/internal/controlCharacters.d.ts.map +1 -0
- package/dist/esm/internal/controlCharacters.js +65 -0
- package/dist/esm/internal/controlCharacters.js.map +1 -0
- package/dist/esm/internal/scorerLabel.d.ts +33 -0
- package/dist/esm/internal/scorerLabel.d.ts.map +1 -0
- package/dist/esm/internal/scorerLabel.js +33 -0
- package/dist/esm/internal/scorerLabel.js.map +1 -0
- package/dist/esm/internal/tupleKey.d.ts +20 -0
- package/dist/esm/internal/tupleKey.d.ts.map +1 -0
- package/dist/esm/internal/tupleKey.js +20 -0
- package/dist/esm/internal/tupleKey.js.map +1 -0
- package/docs/README.md +128 -0
- package/docs/api.md +626 -0
- package/docs/concepts/determinism.md +64 -0
- package/docs/concepts/fixed-suites.md +71 -0
- package/docs/concepts/step-keys.md +60 -0
- package/docs/guides/author-a-suite.md +115 -0
- package/docs/guides/gate-a-run-in-ci.md +129 -0
- package/docs/guides/maintain-a-baseline.md +91 -0
- package/docs/guides/run-a-suite.md +150 -0
- package/docs/installation.md +32 -0
- package/docs/quickstart.md +238 -0
- package/docs/troubleshooting.md +153 -0
- package/package.json +198 -3
- package/src/Baseline.ts +266 -0
- package/src/CaseExecutor.ts +104 -0
- package/src/EvalError.ts +74 -0
- package/src/Gate.ts +128 -0
- package/src/Regression.ts +321 -0
- package/src/Report.ts +268 -0
- package/src/Runner.ts +789 -0
- package/src/Suite.ts +358 -0
- package/src/Trials.ts +155 -0
- package/src/index.ts +76 -0
- package/src/internal/CanonicalJson.ts +234 -0
- package/src/internal/controlCharacters.ts +66 -0
- package/src/internal/scorerLabel.ts +35 -0
- package/src/internal/tupleKey.ts +20 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Runner.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Deterministic fixed-suite execution and bound scorer evaluation.\n *\n * A run executes every case through the injected {@link CaseExecutor}, then\n * grades each execution with the scorers bound to the flow it executed. The\n * timestamp and the run identity come from the caller, so two runs of the same\n * suite over the same inputs produce byte-identical observations.\n *\n * @since 0.1.0\n */\n\nimport * as ScorerRunner from \"@smthrs/scorers/Runner\"\nimport * as Sampling from \"@smthrs/scorers/Sampling\"\nimport * as Scorer from \"@smthrs/scorers/Scorer\"\nimport type * as ScoreStore from \"@smthrs/scorers/ScoreStore\"\nimport * as Cause from \"effect/Cause\"\nimport * as Context from \"effect/Context\"\nimport * as Effect from \"effect/Effect\"\nimport * as Layer from \"effect/Layer\"\nimport { CaseExecutor, type Execution, type Service as CaseExecutorService } from \"./CaseExecutor.ts\"\nimport { EvalError } from \"./EvalError.ts\"\nimport { flattenControlCharacters } from \"./internal/controlCharacters.ts\"\nimport { scorerLabel } from \"./internal/scorerLabel.ts\"\nimport { tupleKey } from \"./internal/tupleKey.ts\"\nimport type { Binding, Case, Suite } from \"./Suite.ts\"\nimport * as Trials from \"./Trials.ts\"\n\n/**\n * One score observation emitted by a suite run.\n *\n * `scorer` is the scorer key, a digest of the scorer's own declaration, which\n * is what a baseline matches on. `scorerName` is the human name from the same\n * declaration, carried alongside so a report can be read without grepping for\n * the digest. `at` is the run's timestamp, not the scorer's: a run's\n * observations all carry one instant so a baseline stays reproducible.\n *\n * @category models\n * @since 0.1.0\n */\nexport type Observation =\n & {\n readonly case: string\n readonly scorer: string\n readonly scorerName?: string | undefined\n readonly stepKey: string\n readonly at: string\n }\n & (\n | {\n readonly kind: \"score\"\n readonly score: number\n readonly reason?: string | undefined\n readonly meta?: unknown\n }\n | { readonly kind: \"inconclusive\"; readonly reason: string; readonly meta?: unknown }\n )\n\n/**\n * A request sent to the scorers batch runner.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface ScoreRequest {\n readonly case: string\n readonly stepKey: string\n readonly binding: Binding\n readonly input: {\n readonly input: unknown\n readonly output: unknown\n readonly groundTruth?: unknown\n readonly context?: unknown\n readonly latencyMs?: number\n }\n}\n\n/**\n * A blocking scorer job, matching the `Runner` module of `@smthrs/scorers`.\n *\n * @category models\n * @since 0.1.0\n */\nexport type ScoreJob = ScorerRunner.Job\n\n/**\n * Structural adapter for `@smthrs/scorers`' blocking batch runner.\n *\n * A runner that implements `runBatchCorrelated` tags every observation with\n * its job identity and may return results in any order. A runner that implements\n * only `runBatch` is correlated positionally: it must return exactly one\n * observation per job, in order, and each observation must echo its job's\n * `targetStepKey` and `scorerKey`. A run refuses the order-only protocol before\n * scoring when two jobs share that pair, because their results could not be\n * attributed to a case.\n *\n * A run fails with `scorer_protocol` when either protocol is broken.\n * `@smthrs/scorers`' `Runner.Service` implements `runBatchCorrelated`, so its\n * service value can be used directly and `ambiguous_score_job` never applies\n * to it.\n *\n * @category services\n * @since 0.1.0\n */\nexport interface ScoreBatchRunner {\n readonly runBatch: (\n jobs: ReadonlyArray<ScoreJob>,\n options?: { readonly concurrency?: number | undefined }\n ) => Effect.Effect<ReadonlyArray<ScoreObservation>, unknown>\n readonly runBatchCorrelated?:\n | ((\n jobs: ReadonlyArray<ScoreJob>,\n options?: { readonly concurrency?: number | undefined }\n ) => Effect.Effect<ReadonlyArray<BatchResult>, unknown>)\n | undefined\n}\n\n/**\n * A score result aligned with a {@link ScoreRequest}.\n *\n * @category models\n * @since 0.1.0\n */\nexport type ScoreObservation = ScoreStore.Observation\n\n/**\n * A batch result tagged with the identity of the job that produced it.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface BatchResult {\n readonly identity: string\n readonly observation: ScoreObservation\n}\n\n/**\n * Per-case result retained by the deterministic runner.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface CaseResult {\n readonly case: string\n readonly execution?: Execution | undefined\n readonly error?: EvalError | undefined\n readonly observations: ReadonlyArray<Observation>\n readonly trials?: Trials.Summary | undefined\n}\n\n/**\n * Stable result of a suite run.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface RunResult {\n readonly runId: string\n readonly suite: string\n readonly cases: ReadonlyArray<CaseResult>\n readonly observations: ReadonlyArray<Observation>\n readonly trials?: Trials.Aggregate | undefined\n readonly k?: number | undefined\n}\n\n/**\n * Options for a deterministic suite run.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface RunOptions {\n readonly scorer?: ScoreBatchRunner | undefined\n readonly runId: string\n readonly sampleId?: string | undefined\n readonly trials?: number | undefined\n readonly k?: number | undefined\n readonly at: string\n}\n\n/**\n * Injectable batch-runner service used when a caller wants a reusable adapter.\n *\n * {@link run} does not require it: a run scores with `options.scorer` when one\n * is passed, otherwise with this service when one is provided, otherwise\n * in process through {@link makeInline}.\n *\n * @category services\n * @since 0.1.0\n */\nexport class Runner extends Context.Service<Runner, ScoreBatchRunner>()(\"flows/evals/Runner\") {}\n\n/** The longest cause summary a public reason carries. */\nconst maxReasonLength = 2048\n\nconst boundedReason = (reason: string): string =>\n reason.length <= maxReasonLength ? reason : `${reason.slice(0, maxReasonLength)}[truncated]`\n\nconst scorerKeyOf = (binding: Binding): string => binding.scorer.scorerKey\n\n// A scorer is a flow and every flow carries a name, so a run always has one to\n// report. A stored observation may still lack it, which is why `scorerLabel`\n// and the `Observation` field both keep the absent case.\nconst scorerNameOf = (binding: Binding): string => binding.scorer.name\n\nconst label = (binding: Binding): string =>\n scorerLabel({ scorer: scorerKeyOf(binding), scorerName: scorerNameOf(binding) })\n\nconst inconclusive = (request: ScoreRequest, reason: string, at: string): Observation => {\n return {\n case: request.case,\n scorer: scorerKeyOf(request.binding),\n scorerName: scorerNameOf(request.binding),\n stepKey: request.stepKey,\n kind: \"inconclusive\",\n reason,\n at\n }\n}\n\n// A case failure always locates itself. An executor that named the offending\n// value keeps its own path; one that named nothing still gets the case, because\n// a failure with no path leaves a caller nothing to branch on but prose.\nconst casePath = (name: string): string => `cases['${name}']`\n\n// The executor boundary handles every non-interruption cause, not only typed\n// failures: an executor that wraps a parser in `Effect.sync` dies with a\n// defect, and one case's defect must not abort its siblings or the report.\n// The wrapped message is flattened because a gate prints it to a CI log, where\n// a newline from the target would let it forge a workflow command; the\n// original message survives untouched on `cause`.\nconst caseError = (suiteCase: Case, cause: Cause.Cause<unknown>): EvalError => {\n const reason = Cause.squash(cause)\n return reason instanceof EvalError\n ? new EvalError({\n code: reason.code,\n message: flattenControlCharacters(`Target failed for case '${suiteCase.name}': ${reason.message}`),\n path: reason.path ?? casePath(suiteCase.name),\n cause: reason\n })\n : new EvalError({\n code: \"executor\",\n message: flattenControlCharacters(`Target failed for case '${suiteCase.name}': ${String(reason)}`),\n path: casePath(suiteCase.name),\n cause: reason\n })\n}\n\n// A step key is a runtime value the target returns, so unlike a suite name it\n// is flattened rather than rejected: it reaches baselines, reports and the\n// gate summary, and a control character in any of them corrupts a CI log line.\n// An executor written in plain JavaScript can return any shape, so the two\n// fields every scorer and baseline reads are checked here, where the failure\n// can still name the case and the field.\nconst malformedExecution = (suiteCase: Case, execution: Execution): EvalError | undefined => {\n const shape: { readonly stepKey?: unknown; readonly latencyMs?: unknown } =\n typeof execution === \"object\" && execution !== null ? execution : {}\n if (typeof shape.stepKey !== \"string\") {\n return new EvalError({\n code: \"executor\",\n message: `executor returned a stepKey that is not a string (${typeof shape.stepKey})`,\n path: `${casePath(suiteCase.name)}.stepKey`\n })\n }\n if (typeof shape.latencyMs !== \"number\" || !Number.isFinite(shape.latencyMs) || shape.latencyMs < 0) {\n return new EvalError({\n code: \"executor\",\n message: `executor returned a latencyMs that is not a finite non-negative number (${\n typeof shape.latencyMs === \"number\" ? String(shape.latencyMs) : typeof shape.latencyMs\n })`,\n path: `${casePath(suiteCase.name)}.latencyMs`\n })\n }\n return undefined\n}\n\nconst runCase = (executor: CaseExecutorService, suiteCase: Case): Effect.Effect<CaseResult> =>\n Effect.suspend(() => executor.run(structuredClone(suiteCase))).pipe(\n Effect.flatMap((execution) => {\n const malformed = malformedExecution(suiteCase, execution)\n return malformed === undefined ? Effect.succeed(execution) : Effect.fail(malformed)\n }),\n Effect.map((execution): CaseResult => ({\n case: suiteCase.name,\n execution: { ...execution, stepKey: flattenControlCharacters(execution.stepKey) },\n observations: []\n })),\n Effect.catchCause((cause) =>\n Cause.hasInterrupts(cause)\n ? Effect.interrupt\n : Effect.succeed<CaseResult>({ case: suiteCase.name, error: caseError(suiteCase, cause), observations: [] })\n ),\n Effect.withSpan(\"Eval.case\", { attributes: { case: suiteCase.name } })\n )\n\n// A declared case value is ground truth even when it is `null`, `false`, `0`\n// or the empty string; only an absent `expected` defers to the binding.\nconst groundTruthFor = (suiteCase: Case, binding: Binding): { readonly groundTruth?: unknown } => {\n const groundTruth = suiteCase.expected !== undefined ? suiteCase.expected : binding.groundTruth\n return groundTruth === undefined ? {} : { groundTruth: structuredClone(groundTruth) }\n}\n\nconst requestFor = (suiteCase: Case, execution: Execution, binding: Binding): ScoreRequest => ({\n case: suiteCase.name,\n stepKey: execution.stepKey,\n binding: {\n ...structuredClone({\n sampling: binding.sampling,\n ...(binding.groundTruth === undefined ? {} : { groundTruth: binding.groundTruth }),\n ...(binding.context === undefined ? {} : { context: binding.context })\n }),\n scorer: binding.scorer,\n appliesTo: binding.appliesTo\n },\n input: {\n input: structuredClone(suiteCase.input),\n output: execution.output,\n ...(groundTruthFor(suiteCase, binding)),\n ...(binding.context === undefined ? {} : { context: structuredClone(binding.context) }),\n latencyMs: execution.latencyMs\n }\n})\n\nconst observationFor = (request: ScoreRequest, result: ScoreObservation, at: string): Observation => {\n const source = result as {\n readonly kind: unknown\n readonly score?: unknown\n readonly reason?: unknown\n readonly meta?: unknown\n }\n const kind = source.kind\n if (kind !== \"score\" && kind !== \"inconclusive\") {\n return inconclusive(\n request,\n boundedReason(`Scorer ${label(request.binding)} returned an unusable observation kind '${String(kind)}'`),\n at\n )\n }\n const reason = source.reason\n if (kind === \"inconclusive\") {\n return inconclusive(\n request,\n typeof reason === \"string\" && reason.length > 0\n ? boundedReason(reason)\n : boundedReason(`Scorer ${label(request.binding)} returned an inconclusive observation with no reason`),\n at\n )\n }\n const score = source.score\n if (typeof score !== \"number\" || !Number.isFinite(score) || score < 0 || score > 1) {\n return inconclusive(\n request,\n boundedReason(`Scorer ${label(request.binding)} returned a score outside [0, 1]: ${String(score)}`),\n at\n )\n }\n const meta = source.meta\n return {\n case: request.case,\n scorer: scorerKeyOf(request.binding),\n scorerName: scorerNameOf(request.binding),\n stepKey: request.stepKey,\n kind: \"score\",\n score,\n ...(typeof reason === \"string\" ? { reason: boundedReason(reason) } : {}),\n ...(meta === undefined ? {} : { meta }),\n at\n }\n}\n\nconst executeInline = (job: ScoreJob): Effect.Effect<ScoreObservation> =>\n job.score.pipe(\n Effect.flatMap(Scorer.validate),\n Effect.map((result): ScoreStore.ScoreObservation => ({\n ...job.observation,\n kind: \"score\",\n score: result.score,\n ...(result.reason === undefined ? {} : { reason: result.reason }),\n ...(result.meta === undefined ? {} : { meta: result.meta }),\n at: job.at\n })),\n Effect.catchCause((cause) =>\n Cause.hasInterrupts(cause)\n ? Effect.interrupt\n : Effect.succeed(ScorerRunner.inconclusive(job, cause))\n )\n )\n\n/**\n * Builds the in-process batch runner a run scores with by default.\n *\n * Each job's scorer runs in the current process, its result is checked by\n * `@smthrs/scorers`' own `Scorer.validate`, and a scorer that fails becomes an\n * inconclusive observation naming its cause rather than failing the run. It\n * honours the {@link ScoreBatchRunner} protocol, so it is also the reference\n * a custom adapter can be compared against.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const makeInline = (): ScoreBatchRunner => {\n const runBatchCorrelated = (\n jobs: ReadonlyArray<ScoreJob>,\n options?: { readonly concurrency?: number | undefined }\n ): Effect.Effect<ReadonlyArray<BatchResult>> =>\n Effect.forEach(\n jobs,\n (job) => executeInline(job).pipe(Effect.map((observation) => ({ identity: job.identity, observation }))),\n { concurrency: options?.concurrency ?? 1 }\n )\n return {\n runBatchCorrelated,\n runBatch: (jobs, options) =>\n runBatchCorrelated(jobs, options).pipe(Effect.map((results) => results.map((result) => result.observation)))\n }\n}\n\n/**\n * Provides the in-process batch runner built by {@link makeInline}.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerInline: Layer.Layer<Runner> = Layer.succeed(Runner)(makeInline())\n\ninterface ScoreContext {\n readonly at: string\n readonly runId: string\n readonly sampleId: string\n readonly concurrency: number\n}\n\nconst buildJobs = (\n cases: ReadonlyArray<CaseResult>,\n suite: Suite,\n { at, runId, sampleId, concurrency }: ScoreContext\n): Effect.Effect<\n { readonly requests: ReadonlyArray<ScoreRequest>; readonly jobs: ReadonlyArray<ScoreJob> },\n EvalError\n> =>\n Effect.gen(function*() {\n // `cases` is the result of one `Effect.forEach` over `suite.cases`, so the\n // two arrays are index-aligned by construction; nothing here has to look a\n // case back up by name.\n const candidates = cases.flatMap((caseResult, index) => {\n const execution = caseResult.execution\n if (execution === undefined) return []\n const suiteCase = suite.cases[index]!\n return suite.bindings.flatMap((binding, bindingIndex) =>\n binding.appliesTo === execution.target\n ? [{ request: requestFor(suiteCase, execution, binding), bindingIndex }]\n : []\n )\n })\n const sampled = yield* Effect.forEach(\n candidates,\n ({ request, bindingIndex }) =>\n Sampling.decide(\n request.binding.sampling,\n request.stepKey,\n scorerKeyOf(request.binding)\n ).pipe(\n Effect.map((selected) => selected ? request : undefined),\n Effect.mapError((cause) =>\n new EvalError({\n code: \"invalid_suite\",\n message: `Invalid sampling policy for scorer ${label(request.binding)}`,\n path: `bindings[${bindingIndex}].sampling`,\n cause\n })\n )\n ),\n { concurrency }\n )\n const requests = sampled.filter((request): request is ScoreRequest => request !== undefined)\n const jobs: Array<ScoreJob> = requests.map((request, index) => ({\n identity: tupleKey(\n suite.name,\n runId,\n sampleId,\n request.case,\n request.stepKey,\n scorerKeyOf(request.binding),\n `${index}`\n ),\n observation: { targetStepKey: request.stepKey, scorerKey: scorerKeyOf(request.binding) },\n score: Effect.suspend(() => request.binding.scorer.score(request.input)),\n at: Date.parse(at)\n }))\n return { requests, jobs }\n })\n\nconst batchFallback = (\n jobs: ReadonlyArray<ScoreJob>,\n cause: Cause.Cause<unknown>\n): Effect.Effect<ReadonlyArray<ScoreObservation>> =>\n Cause.hasInterrupts(cause)\n ? Effect.interrupt\n : Effect.succeed(jobs.map((job) => ScorerRunner.inconclusive(job, cause)))\n\nconst scoreCorrelated = (\n jobs: ReadonlyArray<ScoreJob>,\n scorer: ScoreBatchRunner,\n runBatchCorrelated: NonNullable<ScoreBatchRunner[\"runBatchCorrelated\"]>,\n { concurrency }: ScoreContext\n): Effect.Effect<ReadonlyArray<ScoreObservation>, EvalError> =>\n Effect.gen(function*() {\n const batchResults = yield* Effect.suspend(() => runBatchCorrelated.call(scorer, jobs, { concurrency })).pipe(\n Effect.catchCause((cause) =>\n batchFallback(jobs, cause).pipe(\n Effect.map((observations) =>\n observations.map((observation, index) => ({\n identity: jobs[index]!.identity,\n observation\n }))\n )\n )\n )\n )\n if (batchResults.length !== jobs.length) {\n return yield* Effect.fail(\n new EvalError({\n code: \"scorer_protocol\",\n message:\n `Correlated scorer batch returned ${batchResults.length} results for ${jobs.length} jobs; a batch runner must return exactly one result per job identity`,\n path: \"runBatchCorrelated\"\n })\n )\n }\n const jobIndexByIdentity = new Map(jobs.map((job, index) => [job.identity, index] as const))\n const byIdentity = new Map<string, ScoreObservation>()\n let unknown: { readonly identity: string; readonly index: number } | undefined\n for (const [index, result] of batchResults.entries()) {\n const jobIndex = jobIndexByIdentity.get(result.identity)\n if (jobIndex !== undefined && byIdentity.has(result.identity)) {\n return yield* Effect.fail(\n new EvalError({\n code: \"scorer_protocol\",\n message:\n `Correlated scorer batch returned duplicate identity '${result.identity}' for job ${jobIndex} at result index ${index}`,\n path: `runBatchCorrelated[${index}]`\n })\n )\n }\n if (jobIndex === undefined) unknown = { identity: result.identity, index }\n byIdentity.set(result.identity, result.observation)\n }\n if (unknown !== undefined) {\n const missingJobIndex = jobs.findIndex((job) => !byIdentity.has(job.identity))\n const missingIdentity = jobs[missingJobIndex]!.identity\n return yield* Effect.fail(\n new EvalError({\n code: \"scorer_protocol\",\n message:\n `Correlated scorer batch returned unknown identity '${unknown.identity}' at result index ${unknown.index}; job ${missingJobIndex} identity '${missingIdentity}' is absent`,\n path: `runBatchCorrelated[${unknown.index}]`\n })\n )\n }\n return jobs.map((job) => byIdentity.get(job.identity)!)\n })\n\nconst scoreOrderOnly = (\n jobs: ReadonlyArray<ScoreJob>,\n requests: ReadonlyArray<ScoreRequest>,\n scorer: ScoreBatchRunner,\n { concurrency }: ScoreContext\n): Effect.Effect<ReadonlyArray<ScoreObservation>, EvalError> =>\n Effect.gen(function*() {\n const pairIndexes = new Map<string, number>()\n for (const [index, job] of jobs.entries()) {\n const pair = tupleKey(job.observation.targetStepKey, job.observation.scorerKey)\n const previous = pairIndexes.get(pair)\n if (previous !== undefined) {\n const first = requests[previous]!\n const second = requests[index]!\n return yield* Effect.fail(\n new EvalError({\n code: \"ambiguous_score_job\",\n message:\n `Cannot attribute score jobs for cases '${first.case}' and '${second.case}': both use step key '${job.observation.targetStepKey}' and scorer ${\n label(second.binding)\n }. Give each case its own step key, or provide a batch runner that implements runBatchCorrelated`,\n path: \"runBatch\"\n })\n )\n }\n pairIndexes.set(pair, index)\n }\n const results = yield* Effect.suspend(() => scorer.runBatch(jobs, { concurrency })).pipe(\n Effect.catchCause((cause) => batchFallback(jobs, cause))\n )\n if (results.length !== jobs.length) {\n return yield* Effect.fail(\n new EvalError({\n code: \"scorer_protocol\",\n message:\n `Scorer batch returned ${results.length} observations for ${jobs.length} jobs; a batch runner must return exactly one observation per job, in order`,\n path: \"runBatch\"\n })\n )\n }\n return results\n })\n\nconst score = (\n cases: ReadonlyArray<CaseResult>,\n suite: Suite,\n scorer: ScoreBatchRunner,\n context: ScoreContext\n): Effect.Effect<ReadonlyArray<CaseResult>, EvalError> =>\n Effect.gen(function*() {\n const { requests, jobs } = yield* buildJobs(cases, suite, context)\n if (requests.length === 0) return cases\n const runBatchCorrelated = scorer.runBatchCorrelated\n const protocol = runBatchCorrelated === undefined ? \"runBatch\" : \"runBatchCorrelated\"\n const results = yield* runBatchCorrelated === undefined\n ? scoreOrderOnly(jobs, requests, scorer, context)\n : scoreCorrelated(jobs, scorer, runBatchCorrelated, context)\n const { at } = context\n const observations: Array<Observation> = []\n for (const [index, request] of requests.entries()) {\n const result = results[index]!\n if (result.targetStepKey !== request.stepKey || result.scorerKey !== scorerKeyOf(request.binding)) {\n return yield* Effect.fail(\n new EvalError({\n code: \"scorer_protocol\",\n message: protocol === \"runBatchCorrelated\"\n ? `Correlated scorer batch identity '${\n jobs[index]!.identity\n }' returned step '${result.targetStepKey}' and scorer '${result.scorerKey}' where job ${index} asked for scorer '${\n scorerKeyOf(request.binding)\n }' at step '${request.stepKey}'`\n : `Scorer batch returned an observation for '${result.scorerKey}' at step '${result.targetStepKey}' where job ${index} asked for '${\n scorerKeyOf(request.binding)\n }' at step '${request.stepKey}'; results must stay aligned with their jobs`,\n path: `${protocol}[${index}]`\n })\n )\n }\n observations.push(observationFor(request, result, at))\n }\n const byCase = new Map<string, Array<Observation>>()\n for (const observation of observations) {\n const bucket = byCase.get(observation.case)\n if (bucket === undefined) byCase.set(observation.case, [observation])\n else bucket.push(observation)\n }\n return cases.map((caseResult) => ({\n ...caseResult,\n observations: byCase.get(caseResult.case) ?? []\n }))\n })\n\n/**\n * Runs a fixed suite with bounded execution and declaration-order results.\n *\n * Cases run through the provided {@link CaseExecutor} at the suite's\n * concurrency and are returned in declaration order. Each executor receives\n * its own mutable case copy. Each scorer receives independent copies of the\n * original case input, expected value, and binding data. Every execution is then\n * graded by the bindings whose `appliesTo` is the flow the execution reports as\n * its target, matched by reference identity, so a binding attached to another\n * flow contributes no observations.\n *\n * Scoring goes through `options.scorer` when the caller passes one, the\n * {@link Runner} service when one is provided, and {@link makeInline}\n * otherwise. A case whose target failed keeps its typed error, locates itself\n * with the executor's own `path` or with `cases['<name>']`, and produces no\n * observations; a scorer that failed produces an inconclusive observation. The\n * run itself fails only with `invalid_run_options` for a non-canonical run\n * identity or timestamp, `invalid_suite` for an unusable sampling policy,\n * `ambiguous_score_job` when an order-only runner cannot distinguish two jobs,\n * or `scorer_protocol` for a batch runner that broke the\n * {@link ScoreBatchRunner} contract.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const run = (\n suite: Suite,\n options: RunOptions\n): Effect.Effect<RunResult, EvalError, CaseExecutor> =>\n Effect.gen(function*() {\n const executor = yield* CaseExecutor\n const injected = yield* Effect.serviceOption(Runner)\n const scorer = options.scorer ?? (injected._tag === \"Some\" ? injected.value : makeInline())\n const atMillis = Date.parse(options.at)\n if (options.runId.trim().length === 0) {\n return yield* Effect.fail(\n new EvalError({\n code: \"invalid_run_options\",\n message: \"Deterministic runs require a non-empty runId\",\n path: \"options.runId\"\n })\n )\n }\n if (\n !/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/u.test(options.at) ||\n !Number.isFinite(atMillis) ||\n new Date(atMillis).toISOString() !== options.at\n ) {\n return yield* Effect.fail(\n new EvalError({\n code: \"invalid_run_options\",\n message:\n `Deterministic runs require a canonical UTC timestamp such as 2026-01-01T00:00:00.000Z, got '${options.at}'`,\n path: \"options.at\"\n })\n )\n }\n const n = options.trials ?? suite.trials ?? 1\n const k = options.k ?? 1\n if (!Number.isSafeInteger(n) || n < 1 || n > 1000 || !Number.isSafeInteger(k) || k < 1 || k > n) {\n return yield* Effect.fail(\n new EvalError({\n code: \"invalid_trials\",\n message: \"trials must be an integer from 1 to 1000 and k must be an integer from 1 to trials\",\n path: \"options.trials\"\n })\n )\n }\n const at = options.at\n const runId = options.runId\n const sampleId = options.sampleId ?? \"default\"\n // Await each batch before starting the next: concurrency within a trial is\n // bounded by the suite, and neither scheduling nor scorer latency reorders trials.\n const batches = yield* Effect.forEach(Array.from({ length: n }, (_, index) => index), (index) =>\n Effect.gen(function*() {\n const cases = yield* Effect.forEach(suite.cases, (suiteCase) =>\n runCase(executor, suiteCase), {\n concurrency: suite.concurrency,\n discard: false\n })\n return yield* score(cases, suite, scorer, {\n concurrency: suite.concurrency,\n at,\n runId,\n sampleId: n === 1 ? sampleId : tupleKey(sampleId, String(index))\n })\n }), { concurrency: 1 })\n const outcomes: Array<[string, ReadonlyArray<boolean>]> = []\n const cases = suite.cases.map((suiteCase, index) => {\n const attempts = batches.map((batch) =>\n batch[index]!\n )\n const passed = attempts.map((attempt) =>\n attempt.error === undefined && attempt.observations.length > 0 &&\n attempt.observations.every((observation) => observation.kind === \"score\" && observation.score === 1)\n )\n outcomes.push([suiteCase.name, passed])\n return {\n ...attempts[0]!,\n error: attempts.find((attempt) => attempt.error !== undefined)?.error,\n observations: attempts.flatMap((attempt) => attempt.observations),\n trials: Trials.summarize(passed, k)\n }\n })\n return {\n runId,\n suite: suite.name,\n cases,\n observations: cases.flatMap((caseResult) => caseResult.observations),\n // fromEntries defines own properties, so a case named `__proto__` stays a case.\n trials: Trials.aggregate(Object.fromEntries(outcomes), k),\n k\n }\n }).pipe(Effect.withSpan(\"Eval.run\", { attributes: { suite: suite.name, runId: options.runId } }))\n\n/**\n * Provides a batch runner that is never available.\n *\n * Every bound score under this layer becomes an inconclusive observation, which\n * a gate grades as an undecidable run rather than a red. Provide it to state\n * that a suite must not score, and {@link layerInline} to score in process.\n *\n * @category layers\n * @since 0.1.0\n */\nexport const layerNoop: Layer.Layer<Runner> = Layer.sync(Runner)(() => {\n const unavailable = new EvalError({ code: \"scorer_unavailable\", message: \"No scorer batch runner is available\" })\n return {\n runBatch: () => Effect.fail(unavailable),\n runBatchCorrelated: (jobs) =>\n Effect.succeed(jobs.map((job) => ({\n identity: job.identity,\n observation: ScorerRunner.inconclusive(job, unavailable)\n })))\n }\n})\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,mBAA8B;AAC9B,eAA0B;AAC1B,aAAwB;AAExB,YAAuB;AACvB,cAAyB;AACzB,aAAwB;AACxB,YAAuB;AACvB,0BAAkF;AAClF,uBAA0B;AAC1B,+BAAyC;AACzC,yBAA4B;AAC5B,sBAAyB;AAEzB,aAAwB;AAoKjB,MAAM,eAAe,QAAQ,QAAkC,EAAE,oBAAoB,EAAE;AAAC;AAG/F,MAAM,kBAAkB;AAExB,MAAM,gBAAgB,CAAC,WACrB,OAAO,UAAU,kBAAkB,SAAS,GAAG,OAAO,MAAM,GAAG,eAAe,CAAC;AAEjF,MAAM,cAAc,CAAC,YAA6B,QAAQ,OAAO;AAKjE,MAAM,eAAe,CAAC,YAA6B,QAAQ,OAAO;AAElE,MAAM,QAAQ,CAAC,gBACb,gCAAY,EAAE,QAAQ,YAAY,OAAO,GAAG,YAAY,aAAa,OAAO,EAAE,CAAC;AAEjF,MAAM,eAAe,CAAC,SAAuB,QAAgB,OAA4B;AACvF,SAAO;AAAA,IACL,MAAM,QAAQ;AAAA,IACd,QAAQ,YAAY,QAAQ,OAAO;AAAA,IACnC,YAAY,aAAa,QAAQ,OAAO;AAAA,IACxC,SAAS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
|
2
|
+
* Fixed evaluation suite declarations.
|
|
3
|
+
*
|
|
4
|
+
* A suite is the fixed input half of an evaluation: named cases, the scorer
|
|
5
|
+
* bindings that grade them, and the concurrency the runner is allowed. It is
|
|
6
|
+
* validated once and then never changes, because the run that produced a
|
|
7
|
+
* committed baseline has to be reproducible from the suite value that was
|
|
8
|
+
* validated.
|
|
9
|
+
*
|
|
10
|
+
* @since 0.1.0
|
|
11
|
+
*/
|
|
12
|
+
import type * as ScorerBinding from "@smthrs/scorers/Binding";
|
|
13
|
+
import * as Effect from "effect/Effect";
|
|
14
|
+
import { EvalError } from "./EvalError.ts";
|
|
15
|
+
/**
|
|
16
|
+
* A scorer binding accepted from `@smthrs/scorers`.
|
|
17
|
+
*
|
|
18
|
+
* The binding's `appliesTo` flow is matched against an execution's `target` by
|
|
19
|
+
* reference identity, so a binding only ever grades the exact flow value it was
|
|
20
|
+
* declared against.
|
|
21
|
+
*
|
|
22
|
+
* @category models
|
|
23
|
+
* @since 0.1.0
|
|
24
|
+
*/
|
|
25
|
+
export type Binding = ScorerBinding.Binding;
|
|
26
|
+
/**
|
|
27
|
+
* One immutable fixed-suite case.
|
|
28
|
+
*
|
|
29
|
+
* `input` is handed to the executor and `expected` is offered to a bound scorer
|
|
30
|
+
* as ground truth. A declared `expected`, including `null`, wins over the
|
|
31
|
+
* binding's `groundTruth`; only an absent one defers to the binding. Both are
|
|
32
|
+
* snapshots taken by {@link make}: mutating the object a caller passed in never
|
|
33
|
+
* changes the suite.
|
|
34
|
+
*
|
|
35
|
+
* @category models
|
|
36
|
+
* @since 0.1.0
|
|
37
|
+
*/
|
|
38
|
+
export interface Case {
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly input: unknown;
|
|
41
|
+
readonly expected?: unknown | undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Options for constructing a suite.
|
|
45
|
+
*
|
|
46
|
+
* @category models
|
|
47
|
+
* @since 0.1.0
|
|
48
|
+
*/
|
|
49
|
+
export interface MakeOptions {
|
|
50
|
+
readonly name: string;
|
|
51
|
+
readonly cases: ReadonlyArray<Case>;
|
|
52
|
+
readonly bindings?: ReadonlyArray<Binding> | undefined;
|
|
53
|
+
readonly concurrency: number;
|
|
54
|
+
readonly trials?: number | undefined;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A validated, named collection of fixed cases and scorer bindings.
|
|
58
|
+
*
|
|
59
|
+
* The suite, cases, bindings, and their inert data are deeply frozen snapshots.
|
|
60
|
+
* Executable scorer and target identities remain unchanged.
|
|
61
|
+
*
|
|
62
|
+
* @category models
|
|
63
|
+
* @since 0.1.0
|
|
64
|
+
*/
|
|
65
|
+
export interface Suite {
|
|
66
|
+
readonly name: string;
|
|
67
|
+
readonly cases: ReadonlyArray<Case>;
|
|
68
|
+
readonly bindings: ReadonlyArray<Binding>;
|
|
69
|
+
readonly concurrency: number;
|
|
70
|
+
readonly trials?: number | undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The declared ceilings a suite is validated against.
|
|
74
|
+
*
|
|
75
|
+
* They exist so a mistake fails at construction with a sentence instead of
|
|
76
|
+
* exhausting memory in a runner: `concurrency` bounds the fibers a run may hold
|
|
77
|
+
* open, `cases` bounds one suite, and `fixtureLength` bounds one JSON Lines
|
|
78
|
+
* fixture.
|
|
79
|
+
*
|
|
80
|
+
* @category models
|
|
81
|
+
* @since 0.1.0
|
|
82
|
+
*/
|
|
83
|
+
export declare const limits: {
|
|
84
|
+
readonly concurrency: 1024;
|
|
85
|
+
readonly cases: 10000;
|
|
86
|
+
/** Longest JSON Lines fixture, in UTF-16 code units. */
|
|
87
|
+
readonly fixtureLength: number;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Builds and validates a fixed suite.
|
|
91
|
+
*
|
|
92
|
+
* When the effect runs, it reads every option, case field, and binding field
|
|
93
|
+
* exactly once, then validates and copies only what it read. Validating one
|
|
94
|
+
* value and copying another let a getter hand the suite something validation
|
|
95
|
+
* never saw. Every case and binding is then copied, including a binding's
|
|
96
|
+
* sampling policy, so the suite is a snapshot the caller can no longer reach:
|
|
97
|
+
* mutating an array, case input, or ratio policy afterwards leaves the
|
|
98
|
+
* validated suite unchanged. Data is checked before `structuredClone` and
|
|
99
|
+
* deeply frozen afterwards. Only plain objects, arrays, and cloneable
|
|
100
|
+
* primitives are admitted, with enumerable string-keyed data properties.
|
|
101
|
+
* Functions, class instances, mutable built-ins, and accessors fail with
|
|
102
|
+
* `invalid_suite` naming the offending path. Cycles and shared references are
|
|
103
|
+
* supported; null-prototype records become ordinary objects in the clone.
|
|
104
|
+
*
|
|
105
|
+
* Fails with `invalid_suite` for an empty or control-character name, no cases,
|
|
106
|
+
* more than `limits.cases` cases, a duplicate case name, or a concurrency that
|
|
107
|
+
* is not a safe integer in `[1, limits.concurrency]`.
|
|
108
|
+
*
|
|
109
|
+
* @category constructors
|
|
110
|
+
* @since 0.1.0
|
|
111
|
+
*/
|
|
112
|
+
export declare const make: (options: MakeOptions) => Effect.Effect<Suite, EvalError>;
|
|
113
|
+
/**
|
|
114
|
+
* Options used when decoding JSON Lines.
|
|
115
|
+
*
|
|
116
|
+
* @category models
|
|
117
|
+
* @since 0.1.0
|
|
118
|
+
*/
|
|
119
|
+
export interface JsonLinesOptions {
|
|
120
|
+
readonly name: string;
|
|
121
|
+
readonly bindings?: ReadonlyArray<Binding> | undefined;
|
|
122
|
+
readonly concurrency: number;
|
|
123
|
+
readonly trials?: number | undefined;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Loads the `{ name, input, expected? }` JSON Lines fixture format.
|
|
127
|
+
*
|
|
128
|
+
* Blank lines are skipped, a leading byte-order mark is stripped, and both LF
|
|
129
|
+
* and CRLF terminate a line. A malformed line fails with `invalid_suite`
|
|
130
|
+
* carrying the 1-based line number in both the message and the path; a fixture
|
|
131
|
+
* larger than `limits.fixtureLength` is rejected before any of it is parsed.
|
|
132
|
+
* The first non-blank line after `limits.cases` cases fails with
|
|
133
|
+
* `invalid_suite` at `cases` before it or any later line is parsed or decoded.
|
|
134
|
+
*
|
|
135
|
+
* @category constructors
|
|
136
|
+
* @since 0.1.0
|
|
137
|
+
*/
|
|
138
|
+
export declare const fromJsonLines: (text: string, options: JsonLinesOptions) => Effect.Effect<Suite, EvalError>;
|
|
139
|
+
//# sourceMappingURL=Suite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Suite.d.ts","sourceRoot":"","sources":["../../src/Suite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,KAAK,aAAa,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG1C;;;;;;;;;GASG;AACH,MAAM,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,CAAA;AAE3C;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CACxC;AAED;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,CAAA;IACnC,QAAQ,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,SAAS,CAAA;IACtD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACrC;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,CAAA;IACnC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,CAAA;IACzC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACrC;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,MAAM;;;IAGjB,wDAAwD;;CAEhD,CAAA;AAkJV;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,IAAI,GAAI,SAAS,WAAW,KAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,CAqBtE,CAAA;AAEJ;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,SAAS,CAAA;IACtD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CACrC;AAQD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,EAAE,SAAS,gBAAgB,KAAG,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,CAsClG,CAAA"}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var Suite_exports = {};
|
|
30
|
+
__export(Suite_exports, {
|
|
31
|
+
fromJsonLines: () => fromJsonLines,
|
|
32
|
+
limits: () => limits,
|
|
33
|
+
make: () => make
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(Suite_exports);
|
|
36
|
+
var Effect = __toESM(require("effect/Effect"), 1);
|
|
37
|
+
var Schema = __toESM(require("effect/Schema"), 1);
|
|
38
|
+
var import_EvalError = require("./EvalError.js");
|
|
39
|
+
var import_controlCharacters = require("./internal/controlCharacters.js");
|
|
40
|
+
const limits = {
|
|
41
|
+
concurrency: 1024,
|
|
42
|
+
cases: 1e4,
|
|
43
|
+
/** Longest JSON Lines fixture, in UTF-16 code units. */
|
|
44
|
+
fixtureLength: 8 * 1024 * 1024
|
|
45
|
+
};
|
|
46
|
+
const invalid = (message, path, cause) => new import_EvalError.EvalError({ code: "invalid_suite", message, path, ...cause === void 0 ? {} : { cause } });
|
|
47
|
+
const cloneMessage = "Suite data must be structured-cloneable so the suite cannot change after it is validated";
|
|
48
|
+
const validateData = (value, path, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
49
|
+
if (typeof value === "function" || typeof value === "symbol") throw invalid(cloneMessage, path);
|
|
50
|
+
if (value === null || typeof value !== "object") return;
|
|
51
|
+
if (seen.has(value)) return;
|
|
52
|
+
seen.add(value);
|
|
53
|
+
const array = Array.isArray(value);
|
|
54
|
+
const prototype = Object.getPrototypeOf(value);
|
|
55
|
+
if (array ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) {
|
|
56
|
+
throw invalid("Suite data must contain only plain objects, arrays, and structured-cloneable primitives", path);
|
|
57
|
+
}
|
|
58
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
59
|
+
if (array && key === "length") continue;
|
|
60
|
+
const childPath = typeof key === "string" && array && /^(0|[1-9]\d*)$/.test(key) ? `${path}[${key}]` : `${path}.${String(key)}`;
|
|
61
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
62
|
+
if (typeof key === "symbol" || !descriptor.enumerable || !("value" in descriptor)) {
|
|
63
|
+
throw invalid("Suite data properties must be enumerable string-keyed data fields", childPath);
|
|
64
|
+
}
|
|
65
|
+
validateData(descriptor.value, childPath, seen);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const freezeData = (value, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
69
|
+
if (value === null || typeof value !== "object" || seen.has(value)) return value;
|
|
70
|
+
seen.add(value);
|
|
71
|
+
for (const child of Object.values(value)) freezeData(child, seen);
|
|
72
|
+
return Object.freeze(value);
|
|
73
|
+
};
|
|
74
|
+
const clone = (value, path) => Effect.try({
|
|
75
|
+
try: () => {
|
|
76
|
+
validateData(value, path);
|
|
77
|
+
return freezeData(structuredClone(value));
|
|
78
|
+
},
|
|
79
|
+
catch: (cause) => cause instanceof import_EvalError.EvalError ? cause : invalid(cloneMessage, path, cause)
|
|
80
|
+
});
|
|
81
|
+
const validate = (options) => {
|
|
82
|
+
if (options.name.trim().length === 0) return invalid("Suite name must not be empty", "name");
|
|
83
|
+
const nameControl = (0, import_controlCharacters.controlCharacter)(options.name);
|
|
84
|
+
if (nameControl !== void 0) {
|
|
85
|
+
return invalid(`Suite name must not contain the control character ${nameControl}`, "name");
|
|
86
|
+
}
|
|
87
|
+
if (!Number.isSafeInteger(options.trials) || options.trials < 1 || options.trials > 1e3) {
|
|
88
|
+
return invalid("Suite trials must be an integer from 1 to 1000", "trials");
|
|
89
|
+
}
|
|
90
|
+
if (options.cases.length === 0) return invalid("Suite must contain at least one case", "cases");
|
|
91
|
+
if (options.cases.length > limits.cases) {
|
|
92
|
+
return invalid(`Suite must contain at most ${limits.cases} cases, got ${options.cases.length}`, "cases");
|
|
93
|
+
}
|
|
94
|
+
if (!Number.isSafeInteger(options.concurrency) || options.concurrency < 1) {
|
|
95
|
+
return invalid(
|
|
96
|
+
`Suite concurrency must be a positive safe integer, got ${String(options.concurrency)}`,
|
|
97
|
+
"concurrency"
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
if (options.concurrency > limits.concurrency) {
|
|
101
|
+
return invalid(
|
|
102
|
+
`Suite concurrency must be at most ${limits.concurrency}, got ${options.concurrency}`,
|
|
103
|
+
"concurrency"
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
const names = /* @__PURE__ */ new Set();
|
|
107
|
+
for (const [index, suiteCase] of options.cases.entries()) {
|
|
108
|
+
if (suiteCase.name.trim().length === 0) {
|
|
109
|
+
return invalid("Suite case name must not be empty", `cases[${index}].name`);
|
|
110
|
+
}
|
|
111
|
+
const caseControl = (0, import_controlCharacters.controlCharacter)(suiteCase.name);
|
|
112
|
+
if (caseControl !== void 0) {
|
|
113
|
+
return invalid(
|
|
114
|
+
`Suite case name must not contain the control character ${caseControl}`,
|
|
115
|
+
`cases[${index}].name`
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
if (names.has(suiteCase.name)) {
|
|
119
|
+
return invalid(`Duplicate suite case: ${suiteCase.name}`, `cases[${index}].name`);
|
|
120
|
+
}
|
|
121
|
+
names.add(suiteCase.name);
|
|
122
|
+
}
|
|
123
|
+
return void 0;
|
|
124
|
+
};
|
|
125
|
+
const readCase = (suiteCase) => ({
|
|
126
|
+
name: suiteCase.name,
|
|
127
|
+
input: suiteCase.input,
|
|
128
|
+
expected: suiteCase.expected
|
|
129
|
+
});
|
|
130
|
+
const readBinding = (binding) => {
|
|
131
|
+
const read = {
|
|
132
|
+
scorer: binding.scorer,
|
|
133
|
+
appliesTo: binding.appliesTo,
|
|
134
|
+
sampling: binding.sampling
|
|
135
|
+
};
|
|
136
|
+
const groundTruth = binding.groundTruth;
|
|
137
|
+
if (groundTruth !== void 0) read.groundTruth = groundTruth;
|
|
138
|
+
const context = binding.context;
|
|
139
|
+
if (context !== void 0) read.context = context;
|
|
140
|
+
return read;
|
|
141
|
+
};
|
|
142
|
+
const copyCase = (suiteCase, index) => Effect.gen(function* () {
|
|
143
|
+
const input = yield* clone(suiteCase.input, `cases[${index}].input`);
|
|
144
|
+
if (suiteCase.expected === void 0) return Object.freeze({ name: suiteCase.name, input });
|
|
145
|
+
const expected = yield* clone(suiteCase.expected, `cases[${index}].expected`);
|
|
146
|
+
return Object.freeze({ name: suiteCase.name, input, expected });
|
|
147
|
+
});
|
|
148
|
+
const copyBinding = (binding, index) => Effect.gen(function* () {
|
|
149
|
+
const sampling = binding.sampling === void 0 ? void 0 : yield* clone(binding.sampling, `bindings[${index}].sampling`);
|
|
150
|
+
const copied = {
|
|
151
|
+
scorer: binding.scorer,
|
|
152
|
+
appliesTo: binding.appliesTo,
|
|
153
|
+
sampling
|
|
154
|
+
};
|
|
155
|
+
if (binding.groundTruth !== void 0) {
|
|
156
|
+
copied.groundTruth = yield* clone(binding.groundTruth, `bindings[${index}].groundTruth`);
|
|
157
|
+
}
|
|
158
|
+
if (binding.context !== void 0) {
|
|
159
|
+
copied.context = yield* clone(binding.context, `bindings[${index}].context`);
|
|
160
|
+
}
|
|
161
|
+
return Object.freeze(copied);
|
|
162
|
+
});
|
|
163
|
+
const make = (options) => Effect.suspend(() => {
|
|
164
|
+
const name = options.name;
|
|
165
|
+
const concurrency = options.concurrency;
|
|
166
|
+
const cases = [...options.cases].map(readCase);
|
|
167
|
+
const bindings = [...options.bindings ?? []].map(readBinding);
|
|
168
|
+
const trials = options.trials ?? 1;
|
|
169
|
+
const snapshot = { name, concurrency, cases, bindings, trials };
|
|
170
|
+
const error = validate(snapshot);
|
|
171
|
+
if (error !== void 0) return Effect.fail(error);
|
|
172
|
+
return Effect.gen(function* () {
|
|
173
|
+
const copiedCases = yield* Effect.forEach(cases, copyCase);
|
|
174
|
+
const copiedBindings = yield* Effect.forEach(bindings, copyBinding);
|
|
175
|
+
return Object.freeze({
|
|
176
|
+
name,
|
|
177
|
+
cases: Object.freeze(copiedCases),
|
|
178
|
+
bindings: Object.freeze(copiedBindings),
|
|
179
|
+
concurrency,
|
|
180
|
+
trials
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
const jsonCase = Schema.Struct({
|
|
185
|
+
name: Schema.String,
|
|
186
|
+
input: Schema.Unknown,
|
|
187
|
+
expected: Schema.optional(Schema.Unknown)
|
|
188
|
+
});
|
|
189
|
+
const fromJsonLines = (text, options) => Effect.gen(function* () {
|
|
190
|
+
if (text.length > limits.fixtureLength) {
|
|
191
|
+
return yield* Effect.fail(
|
|
192
|
+
invalid(
|
|
193
|
+
`JSON Lines fixture must be at most ${limits.fixtureLength} characters, got ${text.length}`,
|
|
194
|
+
"text"
|
|
195
|
+
)
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
const cases = [];
|
|
199
|
+
const body = text.startsWith("\uFEFF") ? text.slice(1) : text;
|
|
200
|
+
for (const [index, line] of body.split(/\r?\n/).entries()) {
|
|
201
|
+
const trimmed = line.trim();
|
|
202
|
+
if (trimmed.length === 0) continue;
|
|
203
|
+
if (cases.length === limits.cases) {
|
|
204
|
+
return yield* Effect.fail(
|
|
205
|
+
invalid(`Suite must contain at most ${limits.cases} cases, got ${cases.length + 1}`, "cases")
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
const decoded = yield* Effect.try({
|
|
209
|
+
try: () => JSON.parse(trimmed),
|
|
210
|
+
catch: (cause) => invalid(`Invalid JSON on line ${index + 1}`, `line[${index + 1}]`, cause)
|
|
211
|
+
}).pipe(
|
|
212
|
+
Effect.flatMap(Schema.decodeUnknownEffect(jsonCase)),
|
|
213
|
+
Effect.mapError(
|
|
214
|
+
(cause) => cause instanceof import_EvalError.EvalError ? cause : invalid(`Invalid suite case on line ${index + 1}`, `line[${index + 1}]`, cause)
|
|
215
|
+
)
|
|
216
|
+
);
|
|
217
|
+
cases.push(decoded);
|
|
218
|
+
}
|
|
219
|
+
return yield* make({ ...options, cases });
|
|
220
|
+
});
|
|
221
|
+
//# sourceMappingURL=Suite.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Suite.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Fixed evaluation suite declarations.\n *\n * A suite is the fixed input half of an evaluation: named cases, the scorer\n * bindings that grade them, and the concurrency the runner is allowed. It is\n * validated once and then never changes, because the run that produced a\n * committed baseline has to be reproducible from the suite value that was\n * validated.\n *\n * @since 0.1.0\n */\n\nimport type * as ScorerBinding from \"@smthrs/scorers/Binding\"\nimport * as Effect from \"effect/Effect\"\nimport * as Schema from \"effect/Schema\"\nimport { EvalError } from \"./EvalError.ts\"\nimport { controlCharacter } from \"./internal/controlCharacters.ts\"\n\n/**\n * A scorer binding accepted from `@smthrs/scorers`.\n *\n * The binding's `appliesTo` flow is matched against an execution's `target` by\n * reference identity, so a binding only ever grades the exact flow value it was\n * declared against.\n *\n * @category models\n * @since 0.1.0\n */\nexport type Binding = ScorerBinding.Binding\n\n/**\n * One immutable fixed-suite case.\n *\n * `input` is handed to the executor and `expected` is offered to a bound scorer\n * as ground truth. A declared `expected`, including `null`, wins over the\n * binding's `groundTruth`; only an absent one defers to the binding. Both are\n * snapshots taken by {@link make}: mutating the object a caller passed in never\n * changes the suite.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Case {\n readonly name: string\n readonly input: unknown\n readonly expected?: unknown | undefined\n}\n\n/**\n * Options for constructing a suite.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface MakeOptions {\n readonly name: string\n readonly cases: ReadonlyArray<Case>\n readonly bindings?: ReadonlyArray<Binding> | undefined\n readonly concurrency: number\n readonly trials?: number | undefined\n}\n\n/**\n * A validated, named collection of fixed cases and scorer bindings.\n *\n * The suite, cases, bindings, and their inert data are deeply frozen snapshots.\n * Executable scorer and target identities remain unchanged.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface Suite {\n readonly name: string\n readonly cases: ReadonlyArray<Case>\n readonly bindings: ReadonlyArray<Binding>\n readonly concurrency: number\n readonly trials?: number | undefined\n}\n\n/**\n * The declared ceilings a suite is validated against.\n *\n * They exist so a mistake fails at construction with a sentence instead of\n * exhausting memory in a runner: `concurrency` bounds the fibers a run may hold\n * open, `cases` bounds one suite, and `fixtureLength` bounds one JSON Lines\n * fixture.\n *\n * @category models\n * @since 0.1.0\n */\nexport const limits = {\n concurrency: 1024,\n cases: 10_000,\n /** Longest JSON Lines fixture, in UTF-16 code units. */\n fixtureLength: 8 * 1024 * 1024\n} as const\n\nconst invalid = (message: string, path: string, cause?: unknown): EvalError =>\n new EvalError({ code: \"invalid_suite\", message, path, ...(cause === undefined ? {} : { cause }) })\n\nconst cloneMessage = \"Suite data must be structured-cloneable so the suite cannot change after it is validated\"\n\n// Validate before structuredClone can erase a prototype or invoke a getter.\n// Only records and arrays can be protected completely with Object.freeze.\nconst validateData = (value: unknown, path: string, seen = new WeakSet<object>()): void => {\n if (typeof value === \"function\" || typeof value === \"symbol\") throw invalid(cloneMessage, path)\n if (value === null || typeof value !== \"object\") return\n if (seen.has(value)) return\n seen.add(value)\n const array = Array.isArray(value)\n const prototype = Object.getPrototypeOf(value)\n if (array ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) {\n throw invalid(\"Suite data must contain only plain objects, arrays, and structured-cloneable primitives\", path)\n }\n for (const key of Reflect.ownKeys(value)) {\n if (array && key === \"length\") continue\n const childPath = typeof key === \"string\" && array && /^(0|[1-9]\\d*)$/.test(key)\n ? `${path}[${key}]`\n : `${path}.${String(key)}`\n const descriptor = Object.getOwnPropertyDescriptor(value, key)!\n if (typeof key === \"symbol\" || !descriptor.enumerable || !(\"value\" in descriptor)) {\n throw invalid(\"Suite data properties must be enumerable string-keyed data fields\", childPath)\n }\n validateData(descriptor.value, childPath, seen)\n }\n}\n\nconst freezeData = (value: unknown, seen = new WeakSet<object>()): unknown => {\n if (value === null || typeof value !== \"object\" || seen.has(value)) return value\n seen.add(value)\n for (const child of Object.values(value)) freezeData(child, seen)\n return Object.freeze(value)\n}\n\nconst clone = (value: unknown, path: string): Effect.Effect<unknown, EvalError> =>\n Effect.try({\n try: () => {\n validateData(value, path)\n return freezeData(structuredClone(value))\n },\n catch: (cause) => cause instanceof EvalError ? cause : invalid(cloneMessage, path, cause)\n })\n\nconst validate = (options: MakeOptions & { readonly trials: number }): EvalError | undefined => {\n if (options.name.trim().length === 0) return invalid(\"Suite name must not be empty\", \"name\")\n const nameControl = controlCharacter(options.name)\n if (nameControl !== undefined) {\n return invalid(`Suite name must not contain the control character ${nameControl}`, \"name\")\n }\n if (!Number.isSafeInteger(options.trials) || options.trials < 1 || options.trials > 1000) {\n return invalid(\"Suite trials must be an integer from 1 to 1000\", \"trials\")\n }\n if (options.cases.length === 0) return invalid(\"Suite must contain at least one case\", \"cases\")\n if (options.cases.length > limits.cases) {\n return invalid(`Suite must contain at most ${limits.cases} cases, got ${options.cases.length}`, \"cases\")\n }\n if (!Number.isSafeInteger(options.concurrency) || options.concurrency < 1) {\n return invalid(\n `Suite concurrency must be a positive safe integer, got ${String(options.concurrency)}`,\n \"concurrency\"\n )\n }\n if (options.concurrency > limits.concurrency) {\n return invalid(\n `Suite concurrency must be at most ${limits.concurrency}, got ${options.concurrency}`,\n \"concurrency\"\n )\n }\n const names = new Set<string>()\n for (const [index, suiteCase] of options.cases.entries()) {\n if (suiteCase.name.trim().length === 0) {\n return invalid(\"Suite case name must not be empty\", `cases[${index}].name`)\n }\n const caseControl = controlCharacter(suiteCase.name)\n if (caseControl !== undefined) {\n return invalid(\n `Suite case name must not contain the control character ${caseControl}`,\n `cases[${index}].name`\n )\n }\n if (names.has(suiteCase.name)) {\n return invalid(`Duplicate suite case: ${suiteCase.name}`, `cases[${index}].name`)\n }\n names.add(suiteCase.name)\n }\n return undefined\n}\n\n// Every field is read exactly once, into these two shapes, before anything is\n// validated or copied. Reading a field twice let a getter return the name that\n// passed validation and then a different one into the suite, which is the same\n// hole a baseline record had.\nconst readCase = (suiteCase: Case): Case => ({\n name: suiteCase.name,\n input: suiteCase.input,\n expected: suiteCase.expected\n})\n\nconst readBinding = (binding: Binding): Binding => {\n const read: { -readonly [K in keyof Binding]: Binding[K] } = {\n scorer: binding.scorer,\n appliesTo: binding.appliesTo,\n sampling: binding.sampling\n }\n const groundTruth = binding.groundTruth\n if (groundTruth !== undefined) read.groundTruth = groundTruth\n const context = binding.context\n if (context !== undefined) read.context = context\n return read\n}\n\nconst copyCase = (suiteCase: Case, index: number): Effect.Effect<Case, EvalError> =>\n Effect.gen(function*() {\n const input = yield* clone(suiteCase.input, `cases[${index}].input`)\n if (suiteCase.expected === undefined) return Object.freeze({ name: suiteCase.name, input })\n const expected = yield* clone(suiteCase.expected, `cases[${index}].expected`)\n return Object.freeze({ name: suiteCase.name, input, expected })\n })\n\nconst copyBinding = (binding: Binding, index: number): Effect.Effect<Binding, EvalError> =>\n Effect.gen(function*() {\n // `scorer` and `appliesTo` are executable identities matched by reference,\n // so they are carried over unchanged; sampling, ground truth, and context\n // are inert data that must not remain caller-owned.\n const sampling = binding.sampling === undefined\n ? undefined\n : yield* clone(binding.sampling, `bindings[${index}].sampling`)\n const copied: { -readonly [K in keyof Binding]: Binding[K] } = {\n scorer: binding.scorer,\n appliesTo: binding.appliesTo,\n sampling: sampling as Binding[\"sampling\"]\n }\n if (binding.groundTruth !== undefined) {\n copied.groundTruth = yield* clone(binding.groundTruth, `bindings[${index}].groundTruth`)\n }\n if (binding.context !== undefined) {\n copied.context = yield* clone(binding.context, `bindings[${index}].context`)\n }\n return Object.freeze(copied)\n })\n\n/**\n * Builds and validates a fixed suite.\n *\n * When the effect runs, it reads every option, case field, and binding field\n * exactly once, then validates and copies only what it read. Validating one\n * value and copying another let a getter hand the suite something validation\n * never saw. Every case and binding is then copied, including a binding's\n * sampling policy, so the suite is a snapshot the caller can no longer reach:\n * mutating an array, case input, or ratio policy afterwards leaves the\n * validated suite unchanged. Data is checked before `structuredClone` and\n * deeply frozen afterwards. Only plain objects, arrays, and cloneable\n * primitives are admitted, with enumerable string-keyed data properties.\n * Functions, class instances, mutable built-ins, and accessors fail with\n * `invalid_suite` naming the offending path. Cycles and shared references are\n * supported; null-prototype records become ordinary objects in the clone.\n *\n * Fails with `invalid_suite` for an empty or control-character name, no cases,\n * more than `limits.cases` cases, a duplicate case name, or a concurrency that\n * is not a safe integer in `[1, limits.concurrency]`.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const make = (options: MakeOptions): Effect.Effect<Suite, EvalError> =>\n Effect.suspend(() => {\n const name = options.name\n const concurrency = options.concurrency\n const cases = [...options.cases].map(readCase)\n const bindings = [...(options.bindings ?? [])].map(readBinding)\n const trials = options.trials ?? 1\n const snapshot = { name, concurrency, cases, bindings, trials }\n const error = validate(snapshot)\n if (error !== undefined) return Effect.fail(error)\n return Effect.gen(function*() {\n const copiedCases = yield* Effect.forEach(cases, copyCase)\n const copiedBindings = yield* Effect.forEach(bindings, copyBinding)\n return Object.freeze({\n name,\n cases: Object.freeze(copiedCases),\n bindings: Object.freeze(copiedBindings),\n concurrency,\n trials\n })\n })\n })\n\n/**\n * Options used when decoding JSON Lines.\n *\n * @category models\n * @since 0.1.0\n */\nexport interface JsonLinesOptions {\n readonly name: string\n readonly bindings?: ReadonlyArray<Binding> | undefined\n readonly concurrency: number\n readonly trials?: number | undefined\n}\n\nconst jsonCase = Schema.Struct({\n name: Schema.String,\n input: Schema.Unknown,\n expected: Schema.optional(Schema.Unknown)\n})\n\n/**\n * Loads the `{ name, input, expected? }` JSON Lines fixture format.\n *\n * Blank lines are skipped, a leading byte-order mark is stripped, and both LF\n * and CRLF terminate a line. A malformed line fails with `invalid_suite`\n * carrying the 1-based line number in both the message and the path; a fixture\n * larger than `limits.fixtureLength` is rejected before any of it is parsed.\n * The first non-blank line after `limits.cases` cases fails with\n * `invalid_suite` at `cases` before it or any later line is parsed or decoded.\n *\n * @category constructors\n * @since 0.1.0\n */\nexport const fromJsonLines = (text: string, options: JsonLinesOptions): Effect.Effect<Suite, EvalError> =>\n Effect.gen(function*() {\n if (text.length > limits.fixtureLength) {\n return yield* Effect.fail(\n invalid(\n `JSON Lines fixture must be at most ${limits.fixtureLength} characters, got ${text.length}`,\n \"text\"\n )\n )\n }\n const cases: Array<Case> = []\n const body = text.startsWith(\"\\uFEFF\") ? text.slice(1) : text\n for (const [index, line] of body.split(/\\r?\\n/).entries()) {\n const trimmed = line.trim()\n if (trimmed.length === 0) continue\n // Stop at the ceiling before parsing or decoding the excess line: a\n // fixture under the length limit can still hold hundreds of thousands\n // of tiny lines, and reporting the count only in make() would parse and\n // materialize every one of them first.\n if (cases.length === limits.cases) {\n return yield* Effect.fail(\n invalid(`Suite must contain at most ${limits.cases} cases, got ${cases.length + 1}`, \"cases\")\n )\n }\n const decoded = yield* Effect.try({\n try: () => JSON.parse(trimmed) as unknown,\n catch: (cause) => invalid(`Invalid JSON on line ${index + 1}`, `line[${index + 1}]`, cause)\n }).pipe(\n Effect.flatMap(Schema.decodeUnknownEffect(jsonCase)),\n Effect.mapError((cause) =>\n cause instanceof EvalError\n ? cause\n : invalid(`Invalid suite case on line ${index + 1}`, `line[${index + 1}]`, cause)\n )\n )\n cases.push(decoded)\n }\n return yield* make({ ...options, cases })\n })\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,aAAwB;AACxB,aAAwB;AACxB,uBAA0B;AAC1B,+BAAiC;AA0E1B,MAAM,SAAS;AAAA,EACpB,aAAa;AAAA,EACb,OAAO;AAAA;AAAA,EAEP,eAAe,IAAI,OAAO;AAC5B;AAEA,MAAM,UAAU,CAAC,SAAiB,MAAc,UAC9C,IAAI,2BAAU,EAAE,MAAM,iBAAiB,SAAS,MAAM,GAAI,UAAU,SAAY,CAAC,IAAI,EAAE,MAAM,EAAG,CAAC;AAEnG,MAAM,eAAe;AAIrB,MAAM,eAAe,CAAC,OAAgB,MAAc,OAAO,oBAAI,QAAgB,MAAY;AACzF,MAAI,OAAO,UAAU,cAAc,OAAO,UAAU,SAAU,OAAM,QAAQ,cAAc,IAAI;AAC9F,MAAI,UAAU,QAAQ,OAAO,UAAU,SAAU;AACjD,MAAI,KAAK,IAAI,KAAK,EAAG;AACrB,OAAK,IAAI,KAAK;AACd,QAAM,QAAQ,MAAM,QAAQ,KAAK;AACjC,QAAM,YAAY,OAAO,eAAe,KAAK;AAC7C,MAAI,QAAQ,cAAc,MAAM,YAAY,cAAc,OAAO,aAAa,cAAc,MAAM;AAChG,UAAM,QAAQ,2FAA2F,IAAI;AAAA,EAC/G;AACA,aAAW,OAAO,QAAQ,QAAQ,KAAK,GAAG;AACxC,QAAI,SAAS,QAAQ,SAAU;AAC/B,UAAM,YAAY,OAAO,QAAQ,YAAY,SAAS,iBAAiB,KAAK,GAAG,IAC3E,GAAG,IAAI,IAAI,GAAG,MACd,GAAG,IAAI,IAAI,OAAO,GAAG,CAAC;AAC1B,UAAM,aAAa,OA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,CAAC,KAAK,KAAK;AAAA,IAC5F,CAAC,EAAE;AAAA,MACD,OAAO,QAAQ,OAAO,oBAAoB,QAAQ,CAAC;AAAA,MACnD,OAAO;AAAA,QAAS,CAAC,UACf,iBAAiB,6BACb,QACA,QAAQ,8BAA8B,QAAQ,CAAC,IAAI,QAAQ,QAAQ,CAAC,KAAK,KAAK;AAAA,MACpF;AAAA,IACF;AACA,UAAM,KAAK,OAAO;AAAA,EACpB;AACA,SAAO,OAAO,KAAK,EAAE,GAAG,SAAS,MAAM,CAAC;AAC1C,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repeated-run statistics for live model evaluations.
|
|
3
|
+
*
|
|
4
|
+
* A live case runs `n` times and passes `c` of them. {@link passAtK} is the
|
|
5
|
+
* chance that at least one of `k` runs passes, the capability a best-of-k
|
|
6
|
+
* caller sees; {@link passHatK} is the chance that all `k` pass, the
|
|
7
|
+
* consistency a user sees on every attempt. Both are exact for sampling `k` of
|
|
8
|
+
* the `n` recorded runs without replacement.
|
|
9
|
+
*
|
|
10
|
+
* Every function is pure and throws an `EvalError` with code `invalid_trials`
|
|
11
|
+
* for counts outside the documented bounds.
|
|
12
|
+
*
|
|
13
|
+
* @since 0.1.0
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Repeated-run statistics for one case.
|
|
17
|
+
*
|
|
18
|
+
* `rate` equals `passAt1`; `stderr` is the standard error of the pass rate,
|
|
19
|
+
* `sqrt(rate * (1 - rate) / n)`, and 0 for a single run.
|
|
20
|
+
*
|
|
21
|
+
* @since 0.1.0
|
|
22
|
+
* @category models
|
|
23
|
+
*/
|
|
24
|
+
export interface Summary {
|
|
25
|
+
readonly n: number;
|
|
26
|
+
readonly passes: number;
|
|
27
|
+
readonly rate: number;
|
|
28
|
+
readonly passAt1: number;
|
|
29
|
+
readonly passAtK: number;
|
|
30
|
+
readonly passHatK: number;
|
|
31
|
+
readonly stderr: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Repeated-run statistics across cases.
|
|
35
|
+
*
|
|
36
|
+
* `passAt1`, `passAtK`, and `passHatK` are means over cases, and `allPass` is
|
|
37
|
+
* the fraction of cases whose every run passed.
|
|
38
|
+
*
|
|
39
|
+
* @since 0.1.0
|
|
40
|
+
* @category models
|
|
41
|
+
*/
|
|
42
|
+
export interface Aggregate {
|
|
43
|
+
readonly cases: number;
|
|
44
|
+
readonly passAt1: number;
|
|
45
|
+
readonly passAtK: number;
|
|
46
|
+
readonly passHatK: number;
|
|
47
|
+
readonly allPass: number;
|
|
48
|
+
readonly perCase: Readonly<Record<string, Summary>>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The unbiased pass@k estimator, `1 - C(n - c, k) / C(n, k)` (Chen et al.,
|
|
52
|
+
* 2021): the chance that at least one of `k` runs drawn from `n` passes. It is
|
|
53
|
+
* computed as a product, so large `n` neither overflows nor loses precision.
|
|
54
|
+
*
|
|
55
|
+
* Throws `invalid_trials` unless `n`, `c`, and `k` are integers with
|
|
56
|
+
* `0 <= c <= n` and `1 <= k <= n`.
|
|
57
|
+
*
|
|
58
|
+
* @since 0.1.0
|
|
59
|
+
* @category statistics
|
|
60
|
+
*/
|
|
61
|
+
export declare const passAtK: (n: number, c: number, k: number) => number;
|
|
62
|
+
/**
|
|
63
|
+
* pass^k, `C(c, k) / C(n, k)`: the chance that all `k` runs drawn from `n`
|
|
64
|
+
* without replacement pass, the consistency measure of tau-bench.
|
|
65
|
+
*
|
|
66
|
+
* Throws `invalid_trials` under the same bounds as {@link passAtK}.
|
|
67
|
+
*
|
|
68
|
+
* @since 0.1.0
|
|
69
|
+
* @category statistics
|
|
70
|
+
*/
|
|
71
|
+
export declare const passHatK: (n: number, c: number, k: number) => number;
|
|
72
|
+
/**
|
|
73
|
+
* Summarizes one case's run outcomes at `k`.
|
|
74
|
+
*
|
|
75
|
+
* Throws `invalid_trials` for no outcomes or a `k` outside `1..n`.
|
|
76
|
+
*
|
|
77
|
+
* @since 0.1.0
|
|
78
|
+
* @category statistics
|
|
79
|
+
*/
|
|
80
|
+
export declare const summarize: (outcomes: ReadonlyArray<boolean>, k: number) => Summary;
|
|
81
|
+
/**
|
|
82
|
+
* Summarizes every case at `k` and averages over cases.
|
|
83
|
+
*
|
|
84
|
+
* A case with fewer than `k` runs is summarized at `k = n`, its own run
|
|
85
|
+
* count, so a short case still contributes rather than failing the whole
|
|
86
|
+
* aggregate. No cases aggregate to zeros. Throws `invalid_trials` for a case
|
|
87
|
+
* with no runs or a `k` that is not a positive integer.
|
|
88
|
+
*
|
|
89
|
+
* @since 0.1.0
|
|
90
|
+
* @category statistics
|
|
91
|
+
*/
|
|
92
|
+
export declare const aggregate: (cases: Readonly<Record<string, ReadonlyArray<boolean>>>, k: number) => Aggregate;
|
|
93
|
+
//# sourceMappingURL=Trials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Trials.d.ts","sourceRoot":"","sources":["../../src/Trials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH;;;;;;;;GAQG;AACH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,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