mirror of
https://github.com/allankoechke/turso.git
synced 2026-11-30 11:12:58 +00:00
Add `thesis`, a local runner for the Antithesis Test Composer templates in testing/antithesis/, replacing stress-composer/shuffle-run.sh. thesis runs a template as a single seeded timeline: first_ commands, randomly chosen driver steps, then finally_ and eventually_ commands. It seeds Python's global RNG in every command it launches, which the Antithesis SDK's get_random() and random_choice() fall back to outside Antithesis, so the same seed replays the same commands with the same random choices. It also evaluates SDK assertions, which do not raise on their own: a false always() or a reached unreachable() fails the run, and a failure prints the command that reproduces it. Run it from the repository root with: uv run --group antithesis thesis run testing/antithesis/stress-composer --seed 42 The antithesis dependency group builds pyturso from the checkout, so runs exercise local changes.
73 lines
1.9 KiB
Python
73 lines
1.9 KiB
Python
"""Discovery of Test Composer commands in a test template directory.
|
|
|
|
Test Composer recognizes executables by filename prefix. Files without a
|
|
recognized prefix (helpers, libraries, data) and non-executable files are
|
|
ignored, as they are on Antithesis.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from dataclasses import dataclass
|
|
from enum import Enum
|
|
from pathlib import Path
|
|
|
|
|
|
class Kind(str, Enum):
|
|
FIRST = "first"
|
|
PARALLEL_DRIVER = "parallel_driver"
|
|
SERIAL_DRIVER = "serial_driver"
|
|
SINGLETON_DRIVER = "singleton_driver"
|
|
ANYTIME = "anytime"
|
|
EVENTUALLY = "eventually"
|
|
FINALLY = "finally"
|
|
|
|
|
|
# Longest prefixes first so that e.g. "parallel_driver_" is not shadowed.
|
|
_PREFIXES = sorted(((f"{k.value}_", k) for k in Kind), key=lambda p: -len(p[0]))
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Command:
|
|
path: Path
|
|
kind: Kind
|
|
|
|
@property
|
|
def name(self) -> str:
|
|
return self.path.name
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Template:
|
|
path: Path
|
|
commands: tuple[Command, ...]
|
|
|
|
def of(self, *kinds: Kind) -> list[Command]:
|
|
return [c for c in self.commands if c.kind in kinds]
|
|
|
|
|
|
def classify(name: str) -> Kind | None:
|
|
for prefix, kind in _PREFIXES:
|
|
if name.startswith(prefix):
|
|
return kind
|
|
return None
|
|
|
|
|
|
def load_template(path: Path) -> Template:
|
|
path = path.resolve()
|
|
if not path.is_dir():
|
|
raise ValueError(f"{path}: not a directory")
|
|
commands = []
|
|
# Sorted so that the command list, and therefore every choice made from
|
|
# it, does not depend on directory iteration order.
|
|
for entry in sorted(path.iterdir()):
|
|
kind = classify(entry.name)
|
|
if kind is None or not entry.is_file():
|
|
continue
|
|
if not os.access(entry, os.X_OK):
|
|
continue
|
|
commands.append(Command(entry, kind))
|
|
if not commands:
|
|
raise ValueError(f"{path}: no Test Composer commands found")
|
|
return Template(path, tuple(commands))
|