File size: 1,433 Bytes
f3b0a91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""Shared fixtures: locate promtool/amtool (AF_PROMTOOL/AF_AMTOOL, PATH, or ../../vendor/bin) and build tasks."""

from __future__ import annotations

import os
import shutil

import pytest

HERE = os.path.dirname(os.path.abspath(__file__))
VENDOR_BIN = os.path.abspath(os.path.join(HERE, "..", "..", "..", "vendor", "bin"))

for _tool in ("promtool", "amtool"):
    key = f"AF_{_tool.upper()}"
    if not os.environ.get(key):
        cand = os.path.join(VENDOR_BIN, _tool)
        if os.path.exists(cand):
            os.environ[key] = cand

HAVE_TOOLS = all(shutil.which(os.environ.get(f"AF_{t.upper()}", t)) for t in ("promtool", "amtool"))
needs_tools = pytest.mark.skipif(not HAVE_TOOLS, reason="promtool/amtool not available")


@pytest.fixture(scope="session")
def easy_task(tmp_path_factory):
    """slo-onboarding easy seed 1, built once per session."""
    if not HAVE_TOOLS:
        pytest.skip("promtool/amtool not available")
    from alertforge import render
    out = tmp_path_factory.mktemp("tasks")
    return render.build_task("slo-onboarding", "easy", 1, str(out), "af-test-easy", 20260928)


@pytest.fixture(scope="session")
def hard_task(tmp_path_factory):
    if not HAVE_TOOLS:
        pytest.skip("promtool/amtool not available")
    from alertforge import render
    out = tmp_path_factory.mktemp("tasks")
    return render.build_task("missed-page-postmortem", "hard", 1, str(out), "af-test-hard", 20260928)