mirror of
https://github.com/allankoechke/turso.git
synced 2026-11-30 11:12:58 +00:00
Local Antithesis test suite runner
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.
This commit is contained in:
@@ -55,7 +55,7 @@ limbo/
|
||||
├── testing/ # simulator/, concurrent-simulator/, differential-oracle/
|
||||
├── sync/ # engine/, sdk-kit/ (Turso Cloud sync)
|
||||
├── sdk-kit/ # High-level SDK abstraction
|
||||
└── tools/ # dbhash utility
|
||||
└── tools/ # dbhash utility, thesis (local Antithesis runner)
|
||||
```
|
||||
|
||||
## Where to Look
|
||||
|
||||
@@ -443,6 +443,15 @@ testing (DST) tool for the following:
|
||||
- Discovering bugs that the DST did not catch (and improve the DST)
|
||||
- Discovering bugs that the DST does not cover (for example, non-simulated I/O)
|
||||
|
||||
The test templates live in `testing/antithesis/`. You can run one locally, without an Antithesis account, with
|
||||
[`thesis`](tools/thesis):
|
||||
|
||||
```bash
|
||||
uv run --group antithesis thesis run testing/antithesis/stress-composer --seed 42
|
||||
```
|
||||
|
||||
See [`testing/antithesis/README.md`](testing/antithesis/README.md#running-a-template-locally) for details.
|
||||
|
||||
If you have an Antithesis account, you first need to configure some
|
||||
environment variables:
|
||||
|
||||
|
||||
@@ -10,11 +10,17 @@ version = "0.1.0"
|
||||
[tool.uv]
|
||||
package = false
|
||||
|
||||
[dependency-groups]
|
||||
# Runs the Antithesis test templates locally: uv run --group antithesis thesis run testing/antithesis/<template>
|
||||
antithesis = ["antithesis>=0.1.17", "pyturso", "thesis"]
|
||||
|
||||
[tool.uv.sources]
|
||||
limbo_test = { workspace = true }
|
||||
pyturso = { workspace = true }
|
||||
thesis = { workspace = true }
|
||||
|
||||
[tool.uv.workspace]
|
||||
members = ["testing", "scripts", "bindings/python"]
|
||||
members = ["testing", "scripts", "bindings/python", "tools/thesis"]
|
||||
|
||||
[tool.ruff]
|
||||
line-length = 120
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
# Antithesis Test Suite
|
||||
|
||||
Each directory here is an Antithesis [test template](https://antithesis.com/docs/test_templates/): executables whose
|
||||
filename prefix (`first_`, `parallel_driver_`, `singleton_driver_`, `anytime_`, `eventually_`, `finally_`, ...) tells
|
||||
Test Composer when to run them. `Dockerfile.antithesis` copies them to `/opt/antithesis/test/v1/`.
|
||||
|
||||
## Running a Template Locally
|
||||
|
||||
Use [`thesis`](../../tools/thesis) to run a template on your machine as a single seeded timeline. From the repository
|
||||
root:
|
||||
|
||||
```sh
|
||||
uv run --group antithesis thesis run testing/antithesis/stress-composer --seed 42 --steps 500 --timeout 2m
|
||||
```
|
||||
|
||||
The `antithesis` dependency group builds `pyturso` from your checkout, so the run tests your local changes (the first
|
||||
run takes a few minutes to compile). `thesis` seeds the SDK's `get_random()` and `random_choice()`, so the same seed
|
||||
replays the same commands with the same random choices. It also evaluates SDK assertions: a failing `always()` or a
|
||||
reached `unreachable()` fails the run, as does a command exiting non-zero. On failure it prints a command to reproduce
|
||||
the run up to the failing step, e.g.:
|
||||
|
||||
```
|
||||
thesis: reproduce with: thesis run .../testing/antithesis/stress-composer --seed 42 --steps 57
|
||||
```
|
||||
|
||||
Commands run one at a time in a fresh temporary directory, which is kept on failure with each command's output. Other
|
||||
useful flags: `--duration 10m` or `--forever` instead of `--steps`, `--strict` to also fail on `sometimes()` and
|
||||
`reachable()` assertions that never fired, and `-v` to stream command output. See the
|
||||
[`thesis` README](../../tools/thesis/README.md) for details and for what a seed does not make reproducible.
|
||||
|
||||
## How to Dump Artifacts from a Test Run
|
||||
|
||||
To dump the stress tool's log and the database from an Antithesis test run, follow these steps. Note that they require
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Get list of parallel*.py files into an array
|
||||
test_drivers=($(find . -name "parallel*.py"))
|
||||
|
||||
# Exit if no files found
|
||||
[ ${#test_drivers[@]} -eq 0 ] && exit 1
|
||||
|
||||
while true; do
|
||||
# Pick a random file from the array
|
||||
file=${test_drivers[$RANDOM % ${#test_drivers[@]}]}
|
||||
python "$file" || exit $?
|
||||
done
|
||||
96
tools/thesis/README.md
Normal file
96
tools/thesis/README.md
Normal file
@@ -0,0 +1,96 @@
|
||||
# thesis
|
||||
|
||||
A local, seeded runner for [Antithesis Test Composer](https://antithesis.com/docs/test_templates/) templates.
|
||||
|
||||
From the repository root:
|
||||
|
||||
```console
|
||||
$ uv run --group antithesis thesis run testing/antithesis/stress-composer --seed 42 --steps 500
|
||||
```
|
||||
|
||||
The `antithesis` dependency group (in the root `pyproject.toml`) installs `thesis`, the Antithesis SDK, and `pyturso`
|
||||
built from your checkout, so the templates run against your local changes.
|
||||
|
||||
`thesis` runs a test template the way Antithesis would run one timeline of it, but on your machine, one command at a
|
||||
time, with all randomness derived from a single seed. Running again with the same seed replays the same commands
|
||||
making the same random decisions, and a failure prints the exact command to reproduce it.
|
||||
|
||||
## How it works
|
||||
|
||||
**Randomness.** Outside Antithesis, the SDK's `get_random()` and `random_choice()` fall back to Python's
|
||||
`random.getrandbits()`. `thesis` puts a `sitecustomize.py` at the front of `PYTHONPATH` that seeds Python's global RNG
|
||||
from `THESIS_SEED` before the command starts. Each command gets its own seed, derived from the run seed and the
|
||||
command's position in the timeline. Commands that are not Python still see `THESIS_SEED` and can use it themselves.
|
||||
If you already have a `sitecustomize` module, it still runs after ours.
|
||||
|
||||
**Assertions.** The SDK's `always()` and friends do not raise; they emit a message. `thesis` sets
|
||||
`ANTITHESIS_SDK_LOCAL_OUTPUT` to a per-command file, reads the messages back after each command and evaluates them:
|
||||
|
||||
| Assertion | Fails the run when |
|
||||
| --- | --- |
|
||||
| `always`, `always_or_unreachable` | the condition is false |
|
||||
| `unreachable` | it is reached |
|
||||
| `sometimes` | never true during the run (only with `--strict`) |
|
||||
| `reachable` | never reached during the run (only with `--strict`) |
|
||||
|
||||
A command exiting non-zero or exceeding `--timeout` also fails the run, like on Antithesis.
|
||||
|
||||
**Timeline.** Commands are discovered by Test Composer prefix; files without one (like `helper_utils.py`) and
|
||||
non-executable files are ignored.
|
||||
|
||||
1. All `first_*` commands, in name order.
|
||||
2. Driver steps: each step runs one command chosen at random from `parallel_driver_*`, `serial_driver_*` and
|
||||
`anytime_*`. If the template has `singleton_driver_*` commands, the timeline may instead run exactly one singleton
|
||||
and no other drivers.
|
||||
3. All `finally_*`, then all `eventually_*` commands.
|
||||
|
||||
Commands run with a fresh, empty working directory as their cwd, so state from a previous run can't leak in. The
|
||||
workdir is deleted after a passing run and kept after a failing one.
|
||||
|
||||
## Usage
|
||||
|
||||
```
|
||||
thesis run TEMPLATE [--seed N] [--steps N | --duration 5m | --forever]
|
||||
[--timeout 60s] [--workdir DIR] [--keep-workdir]
|
||||
[--keep-going] [--strict] [-v | -q]
|
||||
```
|
||||
|
||||
Without `--seed`, a random seed is chosen and printed. The default is 100 driver steps.
|
||||
|
||||
On failure:
|
||||
|
||||
```
|
||||
FAIL at step 58 (parallel_driver_integritycheck.py, driver step 57)
|
||||
Always "Integrity check failed" violated at .../parallel_driver_integritycheck.py:40
|
||||
details: {"row": ["*** in database main ***\nPage 12: ..."]}
|
||||
last output (/tmp/thesis-42-x1y2/.thesis/000058-parallel_driver_integritycheck.py.log):
|
||||
Running integrity check...
|
||||
|
||||
thesis: 59 commands (57 driver steps) in 14.2s, seed 42
|
||||
thesis: properties: 3 passed, 1 failed, 0 unsatisfied
|
||||
thesis: reproduce with: thesis run /path/to/stress-composer --seed 42 --steps 57
|
||||
thesis: workdir kept at /tmp/thesis-42-x1y2
|
||||
```
|
||||
|
||||
The workdir's `.thesis/` directory has each command's output (`*.log`), its raw SDK messages (`*.sdk.jsonl`) and
|
||||
`timeline.jsonl`, which records every command with its seed, exit status and violations.
|
||||
|
||||
Commands inherit `thesis`'s environment, including `PATH`, so under `uv run` a template's `#!/usr/bin/env python3`
|
||||
resolves to the workspace venv, where `antithesis` and `turso` are importable.
|
||||
|
||||
## What a seed does not control
|
||||
|
||||
A seed reproduces the test's decisions, not the whole execution. A replay diverges if the system under test has its
|
||||
own sources of nondeterminism: its own RNG, wall-clock time, temp file names, or thread scheduling in a multi-threaded
|
||||
engine. That is also why `thesis` runs commands one at a time: running `parallel_driver_*` commands concurrently would
|
||||
make the result depend on the OS scheduler, which only the Antithesis hypervisor can control.
|
||||
|
||||
## Development
|
||||
|
||||
From the repository root:
|
||||
|
||||
```console
|
||||
$ uv run --package thesis --group dev pytest tools/thesis
|
||||
```
|
||||
|
||||
The tests use small fixture templates that call the real Antithesis SDK; they don't need `pyturso`.
|
||||
23
tools/thesis/pyproject.toml
Normal file
23
tools/thesis/pyproject.toml
Normal file
@@ -0,0 +1,23 @@
|
||||
[project]
|
||||
name = "thesis"
|
||||
version = "0.1.0"
|
||||
description = "Local, seeded runner for Antithesis Test Composer templates"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.13"
|
||||
dependencies = []
|
||||
|
||||
[project.scripts]
|
||||
thesis = "thesis.cli:main"
|
||||
|
||||
[dependency-groups]
|
||||
dev = ["pytest>=8", "antithesis>=0.1.17"]
|
||||
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[tool.hatch.build.targets.wheel]
|
||||
packages = ["src/thesis"]
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
testpaths = ["tests"]
|
||||
3
tools/thesis/src/thesis/__init__.py
Normal file
3
tools/thesis/src/thesis/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""Local, seeded runner for Antithesis Test Composer templates."""
|
||||
|
||||
__version__ = "0.1.0"
|
||||
37
tools/thesis/src/thesis/_boot/sitecustomize.py
Normal file
37
tools/thesis/src/thesis/_boot/sitecustomize.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""Seeds Python's global RNG in every process that thesis launches.
|
||||
|
||||
Outside Antithesis, the SDK's get_random() and random_choice() fall back to
|
||||
random.getrandbits(), so seeding the global RNG before the driver starts
|
||||
makes every random decision the driver takes reproducible.
|
||||
|
||||
thesis puts this directory at the front of PYTHONPATH. Afterwards we run any
|
||||
sitecustomize module that ours shadowed, so the environment is otherwise
|
||||
unchanged.
|
||||
"""
|
||||
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
|
||||
|
||||
def _seed() -> None:
|
||||
seed = os.environ.get("THESIS_SEED")
|
||||
if seed is not None:
|
||||
random.seed(int(seed))
|
||||
|
||||
|
||||
def _chain() -> None:
|
||||
import importlib.machinery
|
||||
import importlib.util
|
||||
|
||||
here = os.path.dirname(os.path.abspath(__file__))
|
||||
rest = [p for p in sys.path if os.path.abspath(p or os.curdir) != here]
|
||||
spec = importlib.machinery.PathFinder.find_spec("sitecustomize", rest)
|
||||
if spec is None or spec.loader is None:
|
||||
return
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
|
||||
_seed()
|
||||
_chain()
|
||||
119
tools/thesis/src/thesis/assertions.py
Normal file
119
tools/thesis/src/thesis/assertions.py
Normal file
@@ -0,0 +1,119 @@
|
||||
"""Evaluation of Antithesis SDK assertion messages.
|
||||
|
||||
The SDK reports each assertion as a JSON line of the form
|
||||
{"antithesis_assert": {...}}. Entries with "hit": false are catalog entries
|
||||
declaring that an assertion exists; entries with "hit": true are evaluations.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
|
||||
@dataclass
|
||||
class Property:
|
||||
id: str
|
||||
message: str
|
||||
display_type: str
|
||||
must_hit: bool
|
||||
location: dict[str, Any]
|
||||
hits: int = 0
|
||||
passes: int = 0
|
||||
failures: int = 0
|
||||
first_failure: dict[str, Any] | None = None
|
||||
first_failure_step: int | None = None
|
||||
|
||||
@property
|
||||
def where(self) -> str:
|
||||
file = self.location.get("file") or "?"
|
||||
line = self.location.get("begin_line")
|
||||
return f"{file}:{line}" if line else file
|
||||
|
||||
def failed(self) -> bool:
|
||||
"""The property was violated by some evaluation."""
|
||||
return self.failures > 0
|
||||
|
||||
def unsatisfied(self) -> bool:
|
||||
"""The property needed something to happen that never did."""
|
||||
if self.display_type in ("Sometimes", "Reachable"):
|
||||
return self.passes == 0
|
||||
return self.must_hit and self.hits == 0
|
||||
|
||||
|
||||
@dataclass
|
||||
class Violation:
|
||||
prop: Property
|
||||
details: Any
|
||||
step: int
|
||||
|
||||
|
||||
@dataclass
|
||||
class Assertions:
|
||||
properties: dict[str, Property] = field(default_factory=dict)
|
||||
|
||||
def _property(self, a: dict[str, Any]) -> Property:
|
||||
key = a.get("id") or a.get("message", "")
|
||||
prop = self.properties.get(key)
|
||||
if prop is None:
|
||||
prop = Property(
|
||||
id=key,
|
||||
message=a.get("message", ""),
|
||||
display_type=a.get("display_type", ""),
|
||||
must_hit=bool(a.get("must_hit", False)),
|
||||
location=a.get("location") or {},
|
||||
)
|
||||
self.properties[key] = prop
|
||||
return prop
|
||||
|
||||
def record(self, a: dict[str, Any], step: int) -> Violation | None:
|
||||
prop = self._property(a)
|
||||
if not a.get("hit", False):
|
||||
return None
|
||||
prop.hits += 1
|
||||
condition = bool(a.get("condition", False))
|
||||
if prop.display_type == "Unreachable":
|
||||
ok = False
|
||||
elif prop.display_type in ("Always", "AlwaysOrUnreachable"):
|
||||
ok = condition
|
||||
else:
|
||||
# Sometimes and Reachable never fail on an individual hit; they
|
||||
# fail only if nothing ever satisfies them.
|
||||
if condition or prop.display_type == "Reachable":
|
||||
prop.passes += 1
|
||||
return None
|
||||
if ok:
|
||||
prop.passes += 1
|
||||
return None
|
||||
prop.failures += 1
|
||||
if prop.first_failure is None:
|
||||
prop.first_failure = a.get("details")
|
||||
prop.first_failure_step = step
|
||||
return Violation(prop, a.get("details"), step)
|
||||
|
||||
def ingest(self, path: Path, step: int) -> list[Violation]:
|
||||
"""Reads one SDK output file and returns the violations it reports."""
|
||||
violations = []
|
||||
try:
|
||||
lines = path.read_text(encoding="utf-8").splitlines()
|
||||
except FileNotFoundError:
|
||||
return violations
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
try:
|
||||
msg = json.loads(line)
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
a = msg.get("antithesis_assert") if isinstance(msg, dict) else None
|
||||
if isinstance(a, dict):
|
||||
v = self.record(a, step)
|
||||
if v is not None:
|
||||
violations.append(v)
|
||||
return violations
|
||||
|
||||
def unsatisfied(self) -> list[Property]:
|
||||
return [p for p in self.properties.values() if p.unsatisfied()]
|
||||
103
tools/thesis/src/thesis/cli.py
Normal file
103
tools/thesis/src/thesis/cli.py
Normal file
@@ -0,0 +1,103 @@
|
||||
"""Command-line interface."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from . import __version__
|
||||
from .composer import load_template
|
||||
from .runner import Options, Runner, random_seed
|
||||
|
||||
|
||||
def parse_duration(s: str) -> float:
|
||||
m = re.fullmatch(r"(\d+(?:\.\d+)?)(s|m|h)?", s.strip())
|
||||
if not m:
|
||||
raise argparse.ArgumentTypeError(f"invalid duration: {s!r} (examples: 90, 30s, 5m, 1h)")
|
||||
return float(m.group(1)) * {"s": 1, "m": 60, "h": 3600, None: 1}[m.group(2)]
|
||||
|
||||
|
||||
def parse_seed(s: str) -> int:
|
||||
try:
|
||||
seed = int(s, 0)
|
||||
except ValueError:
|
||||
raise argparse.ArgumentTypeError(f"invalid seed: {s!r}") from None
|
||||
if seed < 0:
|
||||
raise argparse.ArgumentTypeError("seed must be non-negative")
|
||||
return seed
|
||||
|
||||
|
||||
def build_parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="thesis", description="Local, seeded runner for Antithesis Test Composer templates."
|
||||
)
|
||||
parser.add_argument("--version", action="version", version=f"thesis {__version__}")
|
||||
sub = parser.add_subparsers(dest="command", required=True)
|
||||
|
||||
run = sub.add_parser(
|
||||
"run", help="run a test template", description="Run a Test Composer template as one seeded timeline."
|
||||
)
|
||||
run.add_argument("template", type=Path, help="test template directory (e.g. testing/antithesis/stress-composer)")
|
||||
run.add_argument("--seed", type=parse_seed, help="run seed (default: random)")
|
||||
run.add_argument(
|
||||
"--steps", type=int, default=None, help="number of driver steps (default: 100, or unbounded with --duration)"
|
||||
)
|
||||
run.add_argument("--duration", type=parse_duration, help="stop starting driver steps after this long (e.g. 5m)")
|
||||
run.add_argument("--forever", action="store_true", help="run driver steps until a failure or Ctrl-C")
|
||||
run.add_argument("--timeout", type=parse_duration, help="kill a command that runs longer than this")
|
||||
run.add_argument("--workdir", type=Path, help="empty directory to run commands in (default: a fresh temp dir)")
|
||||
run.add_argument("--keep-workdir", action="store_true", help="keep the workdir even if the run passes")
|
||||
run.add_argument("--keep-going", action="store_true", help="continue after a failing step")
|
||||
run.add_argument(
|
||||
"--strict", action="store_true", help="also fail if a Sometimes/Reachable property was never satisfied"
|
||||
)
|
||||
out = run.add_mutually_exclusive_group()
|
||||
out.add_argument("-v", "--verbose", action="store_true", help="stream command output")
|
||||
out.add_argument("-q", "--quiet", action="store_true", help="print only failures and the summary")
|
||||
return parser
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
args = build_parser().parse_args(argv)
|
||||
if args.command == "run":
|
||||
return cmd_run(args)
|
||||
return 2
|
||||
|
||||
|
||||
def cmd_run(args: argparse.Namespace) -> int:
|
||||
if args.steps is not None and args.steps < 0:
|
||||
print("thesis: --steps must be non-negative", file=sys.stderr)
|
||||
return 2
|
||||
if args.forever and args.steps is not None:
|
||||
print("thesis: --forever and --steps are mutually exclusive", file=sys.stderr)
|
||||
return 2
|
||||
steps = args.steps
|
||||
if steps is None and not args.forever and args.duration is None:
|
||||
steps = 100
|
||||
try:
|
||||
template = load_template(args.template)
|
||||
runner = Runner(
|
||||
Options(
|
||||
template=template,
|
||||
seed=args.seed if args.seed is not None else random_seed(),
|
||||
steps=steps,
|
||||
duration=args.duration,
|
||||
timeout=args.timeout,
|
||||
workdir=args.workdir,
|
||||
keep_workdir=args.keep_workdir,
|
||||
strict=args.strict,
|
||||
keep_going=args.keep_going,
|
||||
verbose=args.verbose,
|
||||
quiet=args.quiet,
|
||||
)
|
||||
)
|
||||
except ValueError as e:
|
||||
print(f"thesis: {e}", file=sys.stderr)
|
||||
return 2
|
||||
return runner.run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
72
tools/thesis/src/thesis/composer.py
Normal file
72
tools/thesis/src/thesis/composer.py
Normal file
@@ -0,0 +1,72 @@
|
||||
"""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))
|
||||
319
tools/thesis/src/thesis/runner.py
Normal file
319
tools/thesis/src/thesis/runner.py
Normal file
@@ -0,0 +1,319 @@
|
||||
"""Seeded, sequential execution of a Test Composer template.
|
||||
|
||||
A run is a single timeline: first_ commands, then a sequence of randomly
|
||||
chosen driver steps, then finally_ and eventually_ commands. Every choice the
|
||||
runner makes comes from one RNG seeded with the run seed, and every command
|
||||
gets its own seed derived from the run seed and its position in the timeline.
|
||||
Running the same template with the same seed therefore replays the same
|
||||
commands with the same randomness, and a failure at driver step K can be
|
||||
reproduced with --steps K.
|
||||
|
||||
Commands run one at a time. Concurrency would make the outcome depend on the
|
||||
OS scheduler, which is exactly the nondeterminism a seed cannot capture.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import itertools
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import shlex
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
from collections import deque
|
||||
from collections.abc import Iterator
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from .assertions import Assertions, Violation
|
||||
from .composer import Command, Kind, Template
|
||||
|
||||
BOOT_DIR = Path(__file__).resolve().parent / "_boot"
|
||||
|
||||
|
||||
@dataclass
|
||||
class Options:
|
||||
template: Template
|
||||
seed: int
|
||||
steps: int | None = 100
|
||||
duration: float | None = None
|
||||
timeout: float | None = None
|
||||
workdir: Path | None = None
|
||||
keep_workdir: bool = False
|
||||
strict: bool = False
|
||||
keep_going: bool = False
|
||||
verbose: bool = False
|
||||
quiet: bool = False
|
||||
|
||||
|
||||
@dataclass
|
||||
class StepResult:
|
||||
index: int
|
||||
command: Command
|
||||
seed: int
|
||||
returncode: int | None
|
||||
timed_out: bool
|
||||
elapsed: float
|
||||
log: Path
|
||||
violations: list[Violation]
|
||||
|
||||
@property
|
||||
def ok(self) -> bool:
|
||||
return self.returncode == 0 and not self.timed_out and not self.violations
|
||||
|
||||
|
||||
def derive_seed(seed: int, index: int) -> int:
|
||||
"""The seed for the command at position index in the timeline."""
|
||||
digest = hashlib.sha256(f"thesis:{seed}:{index}".encode()).digest()
|
||||
return int.from_bytes(digest[:8], "little")
|
||||
|
||||
|
||||
def random_seed() -> int:
|
||||
return int.from_bytes(os.urandom(8), "little") >> 1
|
||||
|
||||
|
||||
class Runner:
|
||||
def __init__(self, opts: Options):
|
||||
self.opts = opts
|
||||
self.rng = random.Random(opts.seed)
|
||||
self.assertions = Assertions()
|
||||
self.index = 0
|
||||
self.driver_steps = 0
|
||||
self.failures: list[StepResult] = []
|
||||
self.workdir = self._make_workdir()
|
||||
self.state_dir = self.workdir / ".thesis"
|
||||
self.state_dir.mkdir()
|
||||
self.timeline = open(self.state_dir / "timeline.jsonl", "w", encoding="utf-8")
|
||||
|
||||
# -- output -------------------------------------------------------------
|
||||
|
||||
def say(self, msg: str = "") -> None:
|
||||
if not self.opts.quiet:
|
||||
print(msg, flush=True)
|
||||
|
||||
def err(self, msg: str = "") -> None:
|
||||
print(msg, file=sys.stderr, flush=True)
|
||||
|
||||
# -- setup --------------------------------------------------------------
|
||||
|
||||
def _make_workdir(self) -> Path:
|
||||
if self.opts.workdir is None:
|
||||
return Path(tempfile.mkdtemp(prefix=f"thesis-{self.opts.seed}-"))
|
||||
workdir = self.opts.workdir.resolve()
|
||||
workdir.mkdir(parents=True, exist_ok=True)
|
||||
if any(workdir.iterdir()):
|
||||
raise ValueError(f"{workdir}: working directory is not empty; a run must start from a clean state")
|
||||
return workdir
|
||||
|
||||
def _env(self, seed: int, sdk_output: Path) -> dict[str, str]:
|
||||
env = dict(os.environ)
|
||||
pythonpath = env.get("PYTHONPATH")
|
||||
env["PYTHONPATH"] = str(BOOT_DIR) + (os.pathsep + pythonpath if pythonpath else "")
|
||||
env["PYTHONHASHSEED"] = str(seed % 2**32)
|
||||
env["THESIS_SEED"] = str(seed)
|
||||
env["THESIS_STEP"] = str(self.index)
|
||||
env["ANTITHESIS_SDK_LOCAL_OUTPUT"] = str(sdk_output)
|
||||
return env
|
||||
|
||||
# -- execution ----------------------------------------------------------
|
||||
|
||||
def _exec(self, cmd: Command, env: dict[str, str], log: Path) -> tuple[int | None, bool]:
|
||||
with open(log, "wb") as out:
|
||||
proc = subprocess.Popen(
|
||||
[str(cmd.path)],
|
||||
cwd=self.workdir,
|
||||
env=env,
|
||||
stdin=subprocess.DEVNULL,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
start_new_session=True,
|
||||
)
|
||||
timed_out = threading.Event()
|
||||
|
||||
def expire() -> None:
|
||||
timed_out.set()
|
||||
_kill(proc)
|
||||
|
||||
timer = None
|
||||
if self.opts.timeout:
|
||||
timer = threading.Timer(self.opts.timeout, expire)
|
||||
timer.start()
|
||||
try:
|
||||
assert proc.stdout is not None
|
||||
for chunk in iter(lambda: proc.stdout.readline(), b""):
|
||||
out.write(chunk)
|
||||
if self.opts.verbose:
|
||||
sys.stdout.buffer.write(b" | " + chunk)
|
||||
sys.stdout.flush()
|
||||
proc.wait()
|
||||
except BaseException:
|
||||
_kill(proc)
|
||||
raise
|
||||
finally:
|
||||
if timer is not None:
|
||||
timer.cancel()
|
||||
return proc.returncode, timed_out.is_set()
|
||||
|
||||
def step(self, cmd: Command) -> StepResult:
|
||||
index = self.index
|
||||
seed = derive_seed(self.opts.seed, index)
|
||||
stem = f"{index:06d}-{cmd.name}"
|
||||
log = self.state_dir / f"{stem}.log"
|
||||
sdk_output = self.state_dir / f"{stem}.sdk.jsonl"
|
||||
|
||||
self.say(f"[{index:5d}] {cmd.name}")
|
||||
start = time.monotonic()
|
||||
returncode, timed_out = self._exec(cmd, self._env(seed, sdk_output), log)
|
||||
elapsed = time.monotonic() - start
|
||||
violations = self.assertions.ingest(sdk_output, index)
|
||||
self.index += 1
|
||||
|
||||
result = StepResult(index, cmd, seed, returncode, timed_out, elapsed, log, violations)
|
||||
self.timeline.write(
|
||||
json.dumps(
|
||||
{
|
||||
"index": index,
|
||||
"command": cmd.name,
|
||||
"kind": cmd.kind.value,
|
||||
"seed": seed,
|
||||
"returncode": returncode,
|
||||
"timed_out": timed_out,
|
||||
"elapsed": round(elapsed, 3),
|
||||
"violations": [v.prop.message for v in violations],
|
||||
}
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
self.timeline.flush()
|
||||
if not result.ok:
|
||||
self.failures.append(result)
|
||||
self.report_failure(result)
|
||||
return result
|
||||
|
||||
# -- timeline -----------------------------------------------------------
|
||||
|
||||
def _drivers_remaining(self, deadline: float | None) -> bool:
|
||||
if self.opts.steps is not None and self.driver_steps >= self.opts.steps:
|
||||
return False
|
||||
if deadline is not None and time.monotonic() >= deadline:
|
||||
return False
|
||||
return True
|
||||
|
||||
def _drivers(self) -> Iterator[Command]:
|
||||
"""Yields the driver steps of the timeline, counting each one."""
|
||||
t = self.opts.template
|
||||
deadline = time.monotonic() + self.opts.duration if self.opts.duration else None
|
||||
pool = t.of(Kind.PARALLEL_DRIVER, Kind.SERIAL_DRIVER, Kind.ANYTIME)
|
||||
singletons = t.of(Kind.SINGLETON_DRIVER)
|
||||
|
||||
# A timeline that runs a singleton driver runs no other drivers.
|
||||
if singletons:
|
||||
singleton = self.rng.choice(singletons + ([None] if pool else []))
|
||||
if singleton is not None:
|
||||
if self._drivers_remaining(deadline):
|
||||
self.driver_steps += 1
|
||||
yield singleton
|
||||
return
|
||||
while pool and self._drivers_remaining(deadline):
|
||||
cmd = self.rng.choice(pool)
|
||||
self.driver_steps += 1
|
||||
yield cmd
|
||||
|
||||
def _run_timeline(self) -> bool:
|
||||
"""Runs the timeline and returns False if it stopped on a failure."""
|
||||
t = self.opts.template
|
||||
timeline = itertools.chain(t.of(Kind.FIRST), self._drivers(), t.of(Kind.FINALLY), t.of(Kind.EVENTUALLY))
|
||||
for cmd in timeline:
|
||||
if not self.step(cmd).ok and not self.opts.keep_going:
|
||||
return False
|
||||
return True
|
||||
|
||||
def run(self) -> int:
|
||||
o = self.opts
|
||||
self.say(f"thesis: template {o.template.path}")
|
||||
self.say(f"thesis: seed {o.seed}, workdir {self.workdir}")
|
||||
start = time.monotonic()
|
||||
interrupted = False
|
||||
try:
|
||||
self._run_timeline()
|
||||
except KeyboardInterrupt:
|
||||
interrupted = True
|
||||
self.err("\nthesis: interrupted")
|
||||
finally:
|
||||
self.timeline.close()
|
||||
elapsed = time.monotonic() - start
|
||||
|
||||
unsatisfied = self.assertions.unsatisfied()
|
||||
failed = bool(self.failures) or (o.strict and bool(unsatisfied))
|
||||
self.summary(elapsed, unsatisfied)
|
||||
if self.failures or interrupted:
|
||||
self.err(f"thesis: reproduce with: {self.repro_command()}")
|
||||
|
||||
if failed or interrupted or o.keep_workdir:
|
||||
self.err(f"thesis: workdir kept at {self.workdir}")
|
||||
else:
|
||||
shutil.rmtree(self.workdir, ignore_errors=True)
|
||||
if interrupted:
|
||||
return 130
|
||||
return 1 if failed else 0
|
||||
|
||||
# -- reporting ----------------------------------------------------------
|
||||
|
||||
def report_failure(self, r: StepResult) -> None:
|
||||
self.err(f"\nFAIL at step {r.index} ({r.command.name}, driver step {self.driver_steps})")
|
||||
if r.timed_out:
|
||||
self.err(f" command timed out after {self.opts.timeout}s")
|
||||
elif r.returncode != 0:
|
||||
self.err(f" command exited with status {r.returncode}")
|
||||
for v in r.violations:
|
||||
self.err(f' {v.prop.display_type} "{v.prop.message}" violated at {v.prop.where}')
|
||||
if v.details:
|
||||
self.err(f" details: {json.dumps(v.details, default=str)}")
|
||||
tail = _tail(r.log, 20)
|
||||
if tail:
|
||||
self.err(f" last output ({r.log}):")
|
||||
for line in tail:
|
||||
self.err(f" {line}")
|
||||
self.err()
|
||||
|
||||
def summary(self, elapsed: float, unsatisfied: list) -> None:
|
||||
props = self.assertions.properties.values()
|
||||
failed = sum(1 for p in props if p.failed())
|
||||
passed = sum(1 for p in props if not p.failed() and not p.unsatisfied())
|
||||
self.err(
|
||||
f"thesis: {self.index} commands ({self.driver_steps} driver steps) in {elapsed:.1f}s, seed {self.opts.seed}"
|
||||
)
|
||||
self.err(f"thesis: properties: {passed} passed, {failed} failed, {len(unsatisfied)} unsatisfied")
|
||||
for p in unsatisfied:
|
||||
self.err(f' unsatisfied: {p.display_type} "{p.message}" ({p.where})')
|
||||
exit_failures = sum(1 for f in self.failures if f.returncode != 0 or f.timed_out)
|
||||
if exit_failures:
|
||||
self.err(f"thesis: {exit_failures} command(s) exited abnormally")
|
||||
|
||||
def repro_command(self) -> str:
|
||||
o = self.opts
|
||||
args = ["thesis", "run", str(o.template.path), "--seed", str(o.seed), "--steps", str(self.driver_steps)]
|
||||
if o.timeout:
|
||||
args += ["--timeout", str(o.timeout)]
|
||||
return shlex.join(args)
|
||||
|
||||
|
||||
def _kill(proc: subprocess.Popen) -> None:
|
||||
try:
|
||||
os.killpg(proc.pid, 9)
|
||||
except (ProcessLookupError, PermissionError):
|
||||
pass
|
||||
|
||||
|
||||
def _tail(path: Path, n: int) -> list[str]:
|
||||
try:
|
||||
with open(path, encoding="utf-8", errors="replace") as f:
|
||||
return [line.rstrip("\n") for line in deque(f, maxlen=n)]
|
||||
except FileNotFoundError:
|
||||
return []
|
||||
214
tools/thesis/tests/test_run.py
Normal file
214
tools/thesis/tests/test_run.py
Normal file
@@ -0,0 +1,214 @@
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from thesis.cli import main
|
||||
from thesis.composer import Kind, load_template
|
||||
|
||||
SHEBANG = f"#!{sys.executable} -u\n"
|
||||
|
||||
# Appends every random decision the command makes to trace.txt in the
|
||||
# workdir, so tests can compare what two runs actually did.
|
||||
RECORD = """
|
||||
import os, sys
|
||||
from antithesis.random import get_random, random_choice
|
||||
name = os.path.basename(sys.argv[0])
|
||||
values = [get_random() for _ in range(3)] + [random_choice(["a", "b", "c", "d"])]
|
||||
with open("trace.txt", "a") as f:
|
||||
f.write(f"{name} {values}\\n")
|
||||
"""
|
||||
|
||||
|
||||
def write(dir: Path, name: str, body: str, executable: bool = True) -> Path:
|
||||
path = dir / name
|
||||
path.write_text(SHEBANG + body)
|
||||
if executable:
|
||||
path.chmod(0o755)
|
||||
return path
|
||||
|
||||
|
||||
def template(tmp_path: Path, **commands: str) -> Path:
|
||||
t = tmp_path / "template"
|
||||
t.mkdir()
|
||||
for name, body in commands.items():
|
||||
write(t, name, body)
|
||||
return t
|
||||
|
||||
|
||||
def run(t: Path, workdir: Path, *args: str) -> int:
|
||||
return main(["run", str(t), "--workdir", str(workdir), "--keep-workdir", "-q", *args])
|
||||
|
||||
|
||||
def trace(workdir: Path) -> str:
|
||||
return (workdir / "trace.txt").read_text()
|
||||
|
||||
|
||||
def basic(tmp_path: Path) -> Path:
|
||||
return template(
|
||||
tmp_path,
|
||||
first_setup=RECORD,
|
||||
parallel_driver_a=RECORD,
|
||||
parallel_driver_b=RECORD,
|
||||
serial_driver_c=RECORD,
|
||||
finally_check=RECORD,
|
||||
)
|
||||
|
||||
|
||||
def test_same_seed_same_run(tmp_path):
|
||||
t = basic(tmp_path)
|
||||
assert run(t, tmp_path / "w1", "--seed", "42", "--steps", "30") == 0
|
||||
assert run(t, tmp_path / "w2", "--seed", "42", "--steps", "30") == 0
|
||||
assert trace(tmp_path / "w1") == trace(tmp_path / "w2")
|
||||
lines = trace(tmp_path / "w1").splitlines()
|
||||
assert len(lines) == 32
|
||||
assert lines[0].startswith("first_setup ")
|
||||
assert lines[-1].startswith("finally_check ")
|
||||
|
||||
|
||||
def test_different_seed_different_run(tmp_path):
|
||||
t = basic(tmp_path)
|
||||
assert run(t, tmp_path / "w1", "--seed", "1", "--steps", "10") == 0
|
||||
assert run(t, tmp_path / "w2", "--seed", "2", "--steps", "10") == 0
|
||||
assert trace(tmp_path / "w1") != trace(tmp_path / "w2")
|
||||
|
||||
|
||||
def test_prefix_is_stable(tmp_path):
|
||||
# A shorter run with the same seed is a prefix of a longer one, which is
|
||||
# what makes --steps K a replay of the first K steps.
|
||||
t = template(tmp_path, parallel_driver_a=RECORD, parallel_driver_b=RECORD)
|
||||
run(t, tmp_path / "short", "--seed", "7", "--steps", "5")
|
||||
run(t, tmp_path / "long", "--seed", "7", "--steps", "20")
|
||||
assert trace(tmp_path / "long").startswith(trace(tmp_path / "short"))
|
||||
|
||||
|
||||
def test_steps_do_not_repeat_randomness(tmp_path):
|
||||
t = template(tmp_path, parallel_driver_a=RECORD)
|
||||
run(t, tmp_path / "w", "--seed", "3", "--steps", "5")
|
||||
lines = trace(tmp_path / "w").splitlines()
|
||||
assert len(set(lines)) == len(lines)
|
||||
|
||||
|
||||
FAIL_SOMETIMES = """
|
||||
from antithesis.assertions import always
|
||||
from antithesis.random import get_random
|
||||
v = get_random() % 8
|
||||
always(v != 0, "value is never zero", {"v": v})
|
||||
"""
|
||||
|
||||
|
||||
def test_always_violation_fails_and_reproduces(tmp_path, capsys):
|
||||
t = template(tmp_path, parallel_driver_a=FAIL_SOMETIMES)
|
||||
assert run(t, tmp_path / "w1", "--seed", "5", "--steps", "1000") == 1
|
||||
err = capsys.readouterr().err
|
||||
assert 'Always "value is never zero" violated' in err
|
||||
repro = next(line for line in err.splitlines() if "reproduce with:" in line)
|
||||
steps = repro.split("--steps ")[1].split()[0]
|
||||
|
||||
timeline = [json.loads(line) for line in (tmp_path / "w1/.thesis/timeline.jsonl").read_text().splitlines()]
|
||||
assert len(timeline) == int(steps)
|
||||
assert timeline[-1]["violations"] == ["value is never zero"]
|
||||
assert all(not e["violations"] for e in timeline[:-1])
|
||||
|
||||
# Replaying exactly that many steps hits the same failure on the last step.
|
||||
assert run(t, tmp_path / "w2", "--seed", "5", "--steps", steps) == 1
|
||||
replay = [json.loads(line) for line in (tmp_path / "w2/.thesis/timeline.jsonl").read_text().splitlines()]
|
||||
assert replay == [{**e, "elapsed": replay[i]["elapsed"]} for i, e in enumerate(timeline)]
|
||||
|
||||
|
||||
def test_keep_going(tmp_path):
|
||||
t = template(tmp_path, parallel_driver_a=FAIL_SOMETIMES)
|
||||
assert run(t, tmp_path / "w", "--seed", "5", "--steps", "200", "--keep-going") == 1
|
||||
lines = (tmp_path / "w/.thesis/timeline.jsonl").read_text().splitlines()
|
||||
assert len(lines) == 200
|
||||
|
||||
|
||||
def test_nonzero_exit_fails(tmp_path, capsys):
|
||||
t = template(tmp_path, parallel_driver_a="import sys; print('boom'); sys.exit(3)\n")
|
||||
assert run(t, tmp_path / "w", "--seed", "1") == 1
|
||||
err = capsys.readouterr().err
|
||||
assert "exited with status 3" in err
|
||||
assert "boom" in err
|
||||
|
||||
|
||||
def test_timeout(tmp_path, capsys):
|
||||
t = template(tmp_path, parallel_driver_a="import time; time.sleep(30)\n")
|
||||
assert run(t, tmp_path / "w", "--seed", "1", "--timeout", "0.5") == 1
|
||||
assert "timed out" in capsys.readouterr().err
|
||||
|
||||
|
||||
def test_unreachable(tmp_path, capsys):
|
||||
t = template(
|
||||
tmp_path,
|
||||
parallel_driver_a='from antithesis.assertions import unreachable\nunreachable("never here", {})\n',
|
||||
)
|
||||
assert run(t, tmp_path / "w", "--seed", "1") == 1
|
||||
assert 'Unreachable "never here"' in capsys.readouterr().err
|
||||
|
||||
|
||||
SOMETIMES = """
|
||||
from antithesis.assertions import sometimes, reachable
|
||||
sometimes(False, "rare event", {})
|
||||
reachable("driver ran", {})
|
||||
"""
|
||||
|
||||
|
||||
def test_unsatisfied_sometimes(tmp_path, capsys):
|
||||
t = template(tmp_path, parallel_driver_a=SOMETIMES)
|
||||
assert run(t, tmp_path / "w1", "--seed", "1", "--steps", "3") == 0
|
||||
err = capsys.readouterr().err
|
||||
assert "1 passed, 0 failed, 1 unsatisfied" in err
|
||||
assert 'unsatisfied: Sometimes "rare event"' in err
|
||||
assert run(t, tmp_path / "w2", "--seed", "1", "--steps", "3", "--strict") == 1
|
||||
|
||||
|
||||
def test_singleton_timeline(tmp_path):
|
||||
t = template(tmp_path, singleton_driver_only=RECORD)
|
||||
assert run(t, tmp_path / "w", "--seed", "1", "--steps", "50") == 0
|
||||
assert len(trace(tmp_path / "w").splitlines()) == 1
|
||||
|
||||
|
||||
def test_workdir_must_be_empty(tmp_path):
|
||||
t = basic(tmp_path)
|
||||
w = tmp_path / "w"
|
||||
w.mkdir()
|
||||
(w / "stale.db").write_text("")
|
||||
assert run(t, w, "--seed", "1") == 2
|
||||
|
||||
|
||||
def test_workdir_removed_on_success(tmp_path):
|
||||
t = basic(tmp_path)
|
||||
w = tmp_path / "w"
|
||||
assert main(["run", str(t), "--workdir", str(w), "-q", "--seed", "1", "--steps", "2"]) == 0
|
||||
assert not w.exists()
|
||||
|
||||
|
||||
def test_discovery(tmp_path):
|
||||
t = tmp_path / "t"
|
||||
t.mkdir()
|
||||
write(t, "parallel_driver_x.py", "")
|
||||
write(t, "anytime_check.sh", "")
|
||||
write(t, "helper_utils.py", "")
|
||||
write(t, "serial_driver_not_executable.py", "", executable=False)
|
||||
kinds = {c.name: c.kind for c in load_template(t).commands}
|
||||
assert kinds == {"anytime_check.sh": Kind.ANYTIME, "parallel_driver_x.py": Kind.PARALLEL_DRIVER}
|
||||
|
||||
|
||||
def test_existing_sitecustomize_still_runs(tmp_path):
|
||||
site = tmp_path / "site"
|
||||
site.mkdir()
|
||||
(site / "sitecustomize.py").write_text("import os\nos.environ['CHAINED'] = '1'\n")
|
||||
t = template(
|
||||
tmp_path,
|
||||
parallel_driver_a="import os\nopen('trace.txt', 'w').write(os.environ.get('CHAINED', '0'))\n",
|
||||
)
|
||||
old = os.environ.get("PYTHONPATH")
|
||||
os.environ["PYTHONPATH"] = str(site)
|
||||
try:
|
||||
assert run(t, tmp_path / "w", "--seed", "1", "--steps", "1") == 0
|
||||
finally:
|
||||
if old is None:
|
||||
del os.environ["PYTHONPATH"]
|
||||
else:
|
||||
os.environ["PYTHONPATH"] = old
|
||||
assert trace(tmp_path / "w") == "1"
|
||||
46
uv.lock
generated
46
uv.lock
generated
@@ -7,6 +7,7 @@ members = [
|
||||
"limbo",
|
||||
"pyturso",
|
||||
"scripts",
|
||||
"thesis",
|
||||
"turso-test",
|
||||
]
|
||||
|
||||
@@ -19,6 +20,15 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/78/b6/6307fbef88d9b5ee7421e68d78a9f162e0da4900bc5f5793f6d3d0e34fb8/annotated_types-0.7.0-py3-none-any.whl", hash = "sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53", size = 13643, upload-time = "2024-05-20T21:33:24.1Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "antithesis"
|
||||
version = "0.3.1"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/c0/55/66b63df7f5135506df6f51013b09b81880257024505db7010bcfe8129f07/antithesis-0.3.1.tar.gz", hash = "sha256:767778b72bb7cd02bc669107c5c6fc926988bd0dfac2fa0d6556db12dff4fee6", size = 32981, upload-time = "2026-09-03T15:30:13.556Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/a2/3a/07d951fd4e96fa494011dae1a616c1190eef6c6bea134b59d533aa5df7a4/antithesis-0.3.1-py3-none-any.whl", hash = "sha256:4f6f2abca3abbde2e27a8d4333ea5c128d3998a3040899c24de1e7c13c3f7fd7", size = 25674, upload-time = "2026-09-03T15:30:12.472Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "certifi"
|
||||
version = "2025.11.12"
|
||||
@@ -127,6 +137,7 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/02/2f/28592176381b9ab2cafa12829ba7b472d177f3acc35d8fbcf3673d966fff/greenlet-3.3.0-cp313-cp313-macosx_11_0_universal2.whl", hash = "sha256:a1e41a81c7e2825822f4e068c48cb2196002362619e2d70b148f20a831c00739", size = 275140, upload-time = "2025-12-04T14:23:01.282Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/2c/80/fbe937bf81e9fca98c981fe499e59a3f45df2a04da0baa5c2be0dca0d329/greenlet-3.3.0-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:9f515a47d02da4d30caaa85b69474cec77b7929b2e936ff7fb853d42f4bf8808", size = 599219, upload-time = "2025-12-04T14:50:08.309Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/c2/ff/7c985128f0514271b8268476af89aee6866df5eec04ac17dcfbc676213df/greenlet-3.3.0-cp313-cp313-manylinux_2_24_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:7d2d9fd66bfadf230b385fdc90426fcd6eb64db54b40c495b72ac0feb5766c54", size = 610211, upload-time = "2025-12-04T14:57:43.968Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/79/07/c47a82d881319ec18a4510bb30463ed6891f2ad2c1901ed5ec23d3de351f/greenlet-3.3.0-cp313-cp313-manylinux_2_24_s390x.manylinux_2_28_s390x.whl", hash = "sha256:30a6e28487a790417d036088b3bcb3f3ac7d8babaa7d0139edbaddebf3af9492", size = 624311, upload-time = "2025-12-04T15:07:14.697Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/fd/8e/424b8c6e78bd9837d14ff7df01a9829fc883ba2ab4ea787d4f848435f23f/greenlet-3.3.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:087ea5e004437321508a8d6f20efc4cfec5e3c30118e1417ea96ed1d93950527", size = 612833, upload-time = "2025-12-04T14:26:03.669Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b5/ba/56699ff9b7c76ca12f1cdc27a886d0f81f2189c3455ff9f65246780f713d/greenlet-3.3.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:ab97cf74045343f6c60a39913fa59710e4bd26a536ce7ab2397adf8b27e67c39", size = 1567256, upload-time = "2025-12-04T15:04:25.276Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/1e/37/f31136132967982d698c71a281a8901daf1a8fbab935dce7c0cf15f942cc/greenlet-3.3.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:5375d2e23184629112ca1ea89a53389dddbffcf417dad40125713d88eb5f96e8", size = 1636483, upload-time = "2025-12-04T14:27:30.804Z" },
|
||||
@@ -134,6 +145,7 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/d7/7c/f0a6d0ede2c7bf092d00bc83ad5bafb7e6ec9b4aab2fbdfa6f134dc73327/greenlet-3.3.0-cp314-cp314-macosx_11_0_universal2.whl", hash = "sha256:60c2ef0f578afb3c8d92ea07ad327f9a062547137afe91f38408f08aacab667f", size = 275671, upload-time = "2025-12-04T14:23:05.267Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/44/06/dac639ae1a50f5969d82d2e3dd9767d30d6dbdbab0e1a54010c8fe90263c/greenlet-3.3.0-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:0a5d554d0712ba1de0a6c94c640f7aeba3f85b3a6e1f2899c11c2c0428da9365", size = 646360, upload-time = "2025-12-04T14:50:10.026Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e0/94/0fb76fe6c5369fba9bf98529ada6f4c3a1adf19e406a47332245ef0eb357/greenlet-3.3.0-cp314-cp314-manylinux_2_24_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:3a898b1e9c5f7307ebbde4102908e6cbfcb9ea16284a3abe15cab996bee8b9b3", size = 658160, upload-time = "2025-12-04T14:57:45.41Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/93/79/d2c70cae6e823fac36c3bbc9077962105052b7ef81db2f01ec3b9bf17e2b/greenlet-3.3.0-cp314-cp314-manylinux_2_24_s390x.manylinux_2_28_s390x.whl", hash = "sha256:dcd2bdbd444ff340e8d6bdf54d2f206ccddbb3ccfdcd3c25bf4afaa7b8f0cf45", size = 671388, upload-time = "2025-12-04T15:07:15.789Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/b8/14/bab308fc2c1b5228c3224ec2bf928ce2e4d21d8046c161e44a2012b5203e/greenlet-3.3.0-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5773edda4dc00e173820722711d043799d3adb4f01731f40619e07ea2750b955", size = 660166, upload-time = "2025-12-04T14:26:05.099Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/4b/d2/91465d39164eaa0085177f61983d80ffe746c5a1860f009811d498e7259c/greenlet-3.3.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:ac0549373982b36d5fd5d30beb8a7a33ee541ff98d2b502714a09f1169f31b55", size = 1615193, upload-time = "2025-12-04T15:04:27.041Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/42/1b/83d110a37044b92423084d52d5d5a3b3a73cafb51b547e6d7366ff62eff1/greenlet-3.3.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:d198d2d977460358c3b3a4dc844f875d1adb33817f0613f663a656f463764ccc", size = 1683653, upload-time = "2025-12-04T14:27:32.366Z" },
|
||||
@@ -141,6 +153,7 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/a0/66/bd6317bc5932accf351fc19f177ffba53712a202f9df10587da8df257c7e/greenlet-3.3.0-cp314-cp314t-macosx_11_0_universal2.whl", hash = "sha256:d6ed6f85fae6cdfdb9ce04c9bf7a08d666cfcfb914e7d006f44f840b46741931", size = 282638, upload-time = "2025-12-04T14:25:20.941Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/30/cf/cc81cb030b40e738d6e69502ccbd0dd1bced0588e958f9e757945de24404/greenlet-3.3.0-cp314-cp314t-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:d9125050fcf24554e69c4cacb086b87b3b55dc395a8b3ebe6487b045b2614388", size = 651145, upload-time = "2025-12-04T14:50:11.039Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/9c/ea/1020037b5ecfe95ca7df8d8549959baceb8186031da83d5ecceff8b08cd2/greenlet-3.3.0-cp314-cp314t-manylinux_2_24_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:87e63ccfa13c0a0f6234ed0add552af24cc67dd886731f2261e46e241608bee3", size = 654236, upload-time = "2025-12-04T14:57:47.007Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/69/cc/1e4bae2e45ca2fa55299f4e85854606a78ecc37fead20d69322f96000504/greenlet-3.3.0-cp314-cp314t-manylinux_2_24_s390x.manylinux_2_28_s390x.whl", hash = "sha256:2662433acbca297c9153a4023fe2161c8dcfdcc91f10433171cf7e7d94ba2221", size = 662506, upload-time = "2025-12-04T15:07:16.906Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/57/b9/f8025d71a6085c441a7eaff0fd928bbb275a6633773667023d19179fe815/greenlet-3.3.0-cp314-cp314t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:3c6e9b9c1527a78520357de498b0e709fb9e2f49c3a513afd5a249007261911b", size = 653783, upload-time = "2025-12-04T14:26:06.225Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/f6/c7/876a8c7a7485d5d6b5c6821201d542ef28be645aa024cfe1145b35c120c1/greenlet-3.3.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:286d093f95ec98fdd92fcb955003b8a3d054b4e2cab3e2707a5039e7b50520fd", size = 1614857, upload-time = "2025-12-04T15:04:28.484Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/4f/dc/041be1dff9f23dac5f48a43323cd0789cb798342011c19a248d9c9335536/greenlet-3.3.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:6c10513330af5b8ae16f023e8ddbfb486ab355d04467c4679c5cfe4659975dd9", size = 1676034, upload-time = "2025-12-04T14:27:33.531Z" },
|
||||
@@ -172,9 +185,23 @@ dependencies = [
|
||||
{ name = "rich" },
|
||||
]
|
||||
|
||||
[package.dev-dependencies]
|
||||
antithesis = [
|
||||
{ name = "antithesis" },
|
||||
{ name = "pyturso" },
|
||||
{ name = "thesis" },
|
||||
]
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [{ name = "rich", specifier = ">=15.0.0" }]
|
||||
|
||||
[package.metadata.requires-dev]
|
||||
antithesis = [
|
||||
{ name = "antithesis", specifier = ">=0.1.17" },
|
||||
{ name = "pyturso", editable = "bindings/python" },
|
||||
{ name = "thesis", editable = "tools/thesis" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "markdown-it-py"
|
||||
version = "3.0.0"
|
||||
@@ -502,6 +529,25 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/bf/e1/3ccb13c643399d22289c6a9786c1a91e3dcbb68bce4beb44926ac2c557bf/sqlalchemy-2.0.45-py3-none-any.whl", hash = "sha256:5225a288e4c8cc2308dbdd874edad6e7d0fd38eac1e9e5f23503425c8eee20d0", size = 1936672, upload-time = "2025-12-09T21:54:52.608Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thesis"
|
||||
version = "0.1.0"
|
||||
source = { editable = "tools/thesis" }
|
||||
|
||||
[package.dev-dependencies]
|
||||
dev = [
|
||||
{ name = "antithesis" },
|
||||
{ name = "pytest" },
|
||||
]
|
||||
|
||||
[package.metadata]
|
||||
|
||||
[package.metadata.requires-dev]
|
||||
dev = [
|
||||
{ name = "antithesis", specifier = ">=0.1.17" },
|
||||
{ name = "pytest", specifier = ">=8" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "turso-test"
|
||||
version = "0.1.0"
|
||||
|
||||
Reference in New Issue
Block a user