Seeds
Seeds set up the fixtures your cases need, like a test project or user, and clean them up afterwards.
This one, from the Sentry triage example, releases a new version of a shop and sends it requests that fail, so the agent has real Sentry issues to investigate:
from eac import Seed
class Incident(Seed):
name = "incident"
credentials = [SentryLogin()]
def setup(self) -> dict[str, Any]:
release = f"shop@1.4.{secrets.token_hex(3)}"
dsn = cli("dsn", "list", PROJECT)["data"][0]["dsn"]
sentry_sdk.init(dsn=dsn, release=release, default_integrations=False)
for error, request in REQUESTS.items():
with sentry_sdk.new_scope() as scope:
scope.fingerprint = ["{{ default }}", release]
scope.set_tag("eac_error", error)
app.handle(*request) # fails, and reports the error to Sentry
sentry_sdk.flush()
# wait_for_issue() polls Sentry until the error's issue shows up.
return {
"release": release,
"issues": {error: self.wait_for_issue(release, error) for error in REQUESTS},
}
def cleanup(self, seed_results: dict[str, Any]) -> None:
for short_id in seed_results["issues"].values():
cli("issue", "resolve", f"{ORG}/{short_id}")setup() returns the seed's results: plain JSON, like IDs and URLs, that says what it made. Attach the seed with Case(seeds=[Incident()]), then read its results in your runner and judges as case.seed_results["incident"]. cleanup() gets the same results back.
Caching
Setting up fixtures can be slow, so eac caches them between runs:
- Seeds with the same
key()are set up once and shared. Every triage case usesIncident(), so they all share one incident. - By default, the key changes when you edit the seed's code.
eac offline prunecleans up seeds nothing uses anymore.
If instances of a seed differ by their constructor arguments, add those to the key:
def key(self) -> str:
return stable_hash([super().key(), self.slug])If a case changes its fixtures, use Case(cache=False) to get a fresh one each run. If a seed can never be reused, set cacheable = False on it.
Sharing across machines
The cache lives on your machine by default. To share fixtures across CI jobs, store them somewhere shared by implementing load_cached, save_cached and delete_cached:
class SharedSeed(Seed):
def load_cached(self, key: str) -> dict[str, Any] | None:
return bucket.get(f"seeds/{self.name}/{key}")
def save_cached(self, key: str, seed_results: dict[str, Any]) -> None:
bucket.put(f"seeds/{self.name}/{key}", seed_results)
def delete_cached(self, key: str) -> None:
bucket.delete(f"seeds/{self.name}/{key}")