Skip to content

Commit 5846510

Browse files
chore(test): add live marker + CI guard for LLM/API discipline (pass 2) (#8)
Layer 1 of test-strategy pass 2. Three small changes: - pyproject.toml: register the `live` pytest marker; update addopts to deselect it by default (`-ra -m 'not live'`). attune-help makes no LLM calls today but the marker is reserved so future tests have a consistent home. - tests.yml: add a CI guard step (in both the matrix job and the test-no-authoring-extra job) that fails fast if `ANTHROPIC_API_KEY` is set in the default test environment. Regression alarm, not routine — GitHub Actions secrets aren't exposed unless explicitly named in `env:`, so this only fires if someone wires a secret into the wrong job. - tests/README.md: replace the inline LLM-mocking section with a pointer to `testing-conventions.md` in the attune workspace umbrella (added in the workspace L0 PR). Verified locally: 309 passing, branch coverage 82.31% (gate=81 holds). Spec: /Users/patrickroebuck/attune/specs/test-strategy-pass-2/ Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 26d3c00 commit 5846510

3 files changed

Lines changed: 25 additions & 13 deletions

File tree

.github/workflows/tests.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ jobs:
3636
- name: Run ruff
3737
run: python -m ruff check src/ tests/
3838

39+
- name: Guard — ANTHROPIC_API_KEY must NOT be set for default suite
40+
run: |
41+
if [ -n "${ANTHROPIC_API_KEY:-}" ]; then
42+
echo "::error::ANTHROPIC_API_KEY is set in the default test environment."
43+
echo "This can cause non-'live'-marked tests to leak real API calls."
44+
echo "Either unset the key, or mark the test with @pytest.mark.live."
45+
exit 1
46+
fi
47+
shell: bash
48+
3949
- name: Run tests (with coverage on ubuntu x py3.11)
4050
run: |
4151
if [ "${{ matrix.os }}" = "ubuntu-latest" ] && [ "${{ matrix.python-version }}" = "3.11" ]; then
@@ -67,5 +77,12 @@ jobs:
6777
run: |
6878
python -m pip install --upgrade pip
6979
python -m pip install -e ".[dev]"
80+
- name: Guard — ANTHROPIC_API_KEY must NOT be set for default suite
81+
run: |
82+
if [ -n "${ANTHROPIC_API_KEY:-}" ]; then
83+
echo "::error::ANTHROPIC_API_KEY is set in the default test environment."
84+
exit 1
85+
fi
86+
shell: bash
7087
- name: Run tests; shim tests must skip cleanly via importorskip
7188
run: python -m pytest tests/ -v --tb=short

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ attune_help = ["templates/**/*.md", "templates/**/*.json", "demos/**/*.md"]
6666

6767
[tool.pytest.ini_options]
6868
testpaths = ["tests"]
69-
addopts = "-ra"
69+
addopts = "-ra -m 'not live'"
7070
markers = [
7171
"slow: tests that create real venvs or otherwise take >1s",
72+
"live: opt-in tests that hit a real LLM API. Skipped by default; require ANTHROPIC_API_KEY and any test-specific env flags.",
7273
]
7374

7475
[tool.coverage.run]

tests/README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,14 @@ The `slow` marker covers tests that create real venvs
2020
(`test_zero_dep_install.py`). Skip with `pytest -m "not slow"` for fast
2121
iteration.
2222

23-
## LLM mocking standard
23+
## LLM mocking standard, `live` marker, CI guard, cost policy
2424

25-
attune-help itself makes no LLM calls. Cross-layer integration tests that
26-
*could* exercise an LLM follow the **attune-author reference pattern**:
25+
See **`testing-conventions.md`** in the attune workspace umbrella —
26+
the canonical reference (mocking pattern, `live` marker semantics, CI
27+
guard expectation, cost & quota policy). Applies to all four layers.
2728

28-
- Strip `ANTHROPIC_API_KEY` via an autouse fixture so a misconfigured
29-
test never reaches the network.
30-
- Patch `anthropic.Anthropic` at import time, not at call site.
31-
- Reset module-level singletons (e.g. `_RagPipeline`) between tests with
32-
an autouse fixture so a leaked patch doesn't poison later tests.
33-
34-
See `attune-author/tests/conftest.py` (`_lenient_polish_by_default`,
35-
`_reset_rag_pipeline`). Pass 2 of the test-strategy spec will formalize
36-
this into a shared `docs/testing-conventions.md` across layers.
29+
attune-help itself makes no LLM calls today; the `live` marker is
30+
registered in `pyproject.toml` so future tests have a consistent home.
3731

3832
## What's tested vs. not
3933

0 commit comments

Comments
 (0)