This commit is contained in:
Andras Schmelczer 2026-09-27 13:58:54 +01:00
commit e151208e15

View file

@ -1,3 +1,5 @@
import { generateStatefulTrace } from "./stateful-workload";
import { compileProgram, type Program } from "./model";
import type {
ExpectedDocument,
TestDefinition,
@ -6,7 +8,8 @@ import type {
import { Random } from "../../test-support/random";
export interface Trace {
version: 1;
version: 1 | 2;
program?: Program;
seed: number;
iterations: number;
/** Old traces omit this and retain their original two-client behavior. */
@ -20,7 +23,7 @@ type Document = ExpectedDocument & { content: string };
* Every round checks the whole history, including earlier bytes and UUIDs.
* A shuffled cycle covers nine actions; most revisit existing documents.
*/
export function generateTrace(seed: number, iterations: number): Trace {
export function generateLegacyTrace(seed: number, iterations: number): Trace {
const random = new Random(seed);
const clients = 2 + random.int(2);
const steps: TestStep[] = [];
@ -295,16 +298,21 @@ export function generateTrace(seed: number, iterations: number): Trace {
export function traceTest(trace: Trace): TestDefinition {
if (
trace.version !== 1 ||
!Array.isArray(trace.steps) ||
!trace.steps.length ||
![1, 2].includes(trace.version) ||
(trace.version === 1 &&
(!Array.isArray(trace.steps) || !trace.steps.length)) ||
(trace.version === 2 &&
(!trace.program || trace.clients !== trace.program.clients)) ||
(trace.clients !== undefined &&
(!Number.isInteger(trace.clients) || trace.clients < 2))
)
throw new Error("Invalid/empty replay trace");
return {
clients: trace.clients ?? 2,
description: `Seed ${trace.seed}; ${trace.iterations} generated conflict scenarios`,
steps: trace.steps
description: `Seed ${trace.seed}; ${trace.iterations} generated rounds`,
steps:
trace.version === 2 ? compileProgram(trace.program!) : trace.steps
};
}
export const generateTrace = generateStatefulTrace;