Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

oracle-config.ts

50 lines1.8 KB

1import { oraclePropertyOptions, oracleRuns } from '../../db/tests/oracle-config'
2​
3type OfflineOracleConfigOptions = {
4 /** A property registered in packages/db/tests/oracle-config.ts. */
5 property: string
6 /** The random campaign's budget before TANSTACK_DB_ORACLE_RUNS_MULTIPLIER. */
7 defaultRuns: number
8 /** Fixed examples that fast-check counts against the same run budget. */
9 reservedRuns?: number
11​
12/**
13 * The budgets of one offline oracle property. `runs` sizes its fixed-seed
14 * lane. `random` holds the shared property options for its random lane: a seed
15 * alone reseeds it, and a path replay of `property` runs its recorded history
16 * once.
17 */
18export function readOfflineOracleConfig({
19 property,
20 defaultRuns,
21 reservedRuns = 0,
22}: OfflineOracleConfigOptions): {
23 runs: number
24 random: ReturnType<typeof oraclePropertyOptions>
25} {
26 // Both lanes share one budget: the scaled base plus the reserved fixed
27 // examples. A path replay keeps its single run.
28 const runs = oracleRuns(defaultRuns) + reservedRuns
29 const random = oraclePropertyOptions(defaultRuns, property)
30 return {
31 runs,
32 random: random.path === undefined ? { ...random, numRuns: runs } : random,
33 }
35​
36/**
37 * A lane that passes fixed `examples` keeps them during a path replay.
38 * fast-check counts the examples in the recorded path, so a replay without
39 * them would select a different value.
40 *
41 * The fast-check options for one lane. An `undefined` seed selects the random
42 * lane. A number selects the fixed lane, which keeps its ordinary budget.
43 */
44export function oracleLaneOptions(
45 config: ReturnType<typeof readOfflineOracleConfig>,
46 seed: number | undefined,
47):
48 ReturnType<typeof oraclePropertyOptions> | { numRuns: number; seed: number } {
49 return seed === undefined ? config.random : { numRuns: config.runs, seed }