Skip to content

Commit e8509a7

Browse files
author
Krish Patel
committed
chore: add release validation tests and PyPI publish workflow
- tests/test_release.py: 16 tests covering imports, core functionality, CLI entry points, version consistency - .github/workflows/release.yml: tag-triggered build + PyPI publish via trusted publisher
1 parent c0749a8 commit e8509a7

2 files changed

Lines changed: 227 additions & 0 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-python@v5
14+
with:
15+
python-version: "3.12"
16+
- name: Install package
17+
working-directory: aecp-python
18+
run: pip install -e ".[dev]"
19+
- name: Run release tests
20+
working-directory: aecp-python
21+
run: python -m pytest tests/test_release.py -v --tb=short
22+
- name: Run full test suite
23+
working-directory: aecp-python
24+
run: python -m pytest tests/ -q --tb=short
25+
26+
publish:
27+
needs: test
28+
runs-on: ubuntu-latest
29+
permissions:
30+
id-token: write
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: actions/setup-python@v5
34+
with:
35+
python-version: "3.12"
36+
- name: Install build tools
37+
run: pip install build twine
38+
- name: Build package
39+
working-directory: aecp-python
40+
run: python -m build
41+
- name: Publish to PyPI
42+
uses: pypa/gh-action-pypi-publish@release/v1
43+
with:
44+
packages-dir: aecp-python/dist/

‎aecp-python/tests/test_release.py‎

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
"""Release validation tests — run before PyPI publish.
2+
3+
These tests verify the package is importable, the CLI works,
4+
core functionality is intact, and the version is consistent.
5+
They should pass on a clean install without optional deps.
6+
"""
7+
8+
from __future__ import annotations
9+
10+
import shutil
11+
import subprocess
12+
import sys
13+
from pathlib import Path
14+
15+
import numpy as np
16+
import pytest
17+
18+
19+
class TestPackageImport:
20+
"""Verify the package imports cleanly."""
21+
22+
def test_import_aecp(self):
23+
import aecp
24+
25+
assert aecp.__version__ == "0.2.0"
26+
27+
def test_import_mapping(self):
28+
from aecp.mapping.linear import RidgeMapping
29+
30+
assert RidgeMapping.mapping_type == "ridge"
31+
32+
def test_import_gate(self):
33+
from aecp.quality.gate import GateVerdict
34+
35+
assert GateVerdict.PASS.value == "PASS"
36+
37+
def test_import_serve(self):
38+
from aecp.serve import QueryAdapter
39+
40+
assert QueryAdapter is not None
41+
42+
def test_import_migrate(self):
43+
from aecp.migrate import migrate_store
44+
45+
assert callable(migrate_store)
46+
47+
def test_import_stores(self):
48+
from aecp.stores.numpy_files import NumpyFileStore
49+
50+
assert NumpyFileStore is not None
51+
52+
53+
class TestCoreFunctionality:
54+
"""Verify core features work end-to-end."""
55+
56+
def test_ridge_fit_transform(self):
57+
from aecp.mapping.linear import RidgeMapping
58+
59+
rng = np.random.default_rng(42)
60+
X = rng.normal(size=(200, 8))
61+
W = rng.normal(size=(8, 12))
62+
Y = X @ W
63+
m = RidgeMapping(alpha="auto", seed=0)
64+
m.fit(X, Y)
65+
Z = m.transform(X[:10])
66+
assert Z.shape == (10, 12)
67+
assert np.isfinite(Z).all()
68+
69+
def test_save_load_roundtrip(self, tmp_path):
70+
from aecp.mapping.linear import RidgeMapping
71+
72+
rng = np.random.default_rng(42)
73+
X = rng.normal(size=(200, 8))
74+
W = rng.normal(size=(8, 12))
75+
Y = X @ W
76+
m = RidgeMapping(alpha="auto", seed=0)
77+
m.fit(X, Y)
78+
path = tmp_path / "test.aecp"
79+
m.save(path)
80+
loaded = RidgeMapping.load(path)
81+
Z1 = m.transform(X[:5])
82+
Z2 = loaded.transform(X[:5])
83+
np.testing.assert_allclose(Z1, Z2, atol=1e-6)
84+
85+
def test_quality_gate(self):
86+
from aecp.mapping.linear import RidgeMapping
87+
from aecp.quality.gate import QualityGate
88+
89+
rng = np.random.default_rng(42)
90+
X = rng.normal(size=(200, 8))
91+
W = rng.normal(size=(8, 12))
92+
Y = X @ W
93+
m = RidgeMapping(alpha="auto", seed=0)
94+
m.fit(X, Y)
95+
gate = QualityGate()
96+
report = gate.evaluate(m, X[:50], Y[:50])
97+
assert report.verdict.value in ("PASS", "WARN", "FAIL")
98+
assert 0.0 <= report.predicted_retention <= 1.0
99+
100+
def test_numpy_store_roundtrip(self, tmp_path):
101+
from aecp.stores.numpy_files import NumpyFileStore
102+
103+
vecs = np.random.randn(10, 8)
104+
texts = [f"doc {i}" for i in range(10)]
105+
store = NumpyFileStore.from_arrays(tmp_path / "store", vecs, texts=texts)
106+
assert store.count() == 10
107+
loaded = list(store.iter_vectors(batch_size=5))
108+
assert len(loaded) == 2
109+
110+
def test_migration_manifest(self, tmp_path):
111+
from aecp.mapping.linear import RidgeMapping
112+
from aecp.migrate import migrate_store
113+
from aecp.stores.numpy_files import NumpyFileStore
114+
115+
rng = np.random.default_rng(42)
116+
X = rng.normal(size=(200, 8))
117+
W = rng.normal(size=(8, 12))
118+
Y = X @ W
119+
m = RidgeMapping(alpha="auto", seed=0).fit(X, Y)
120+
121+
source = NumpyFileStore.from_arrays(
122+
tmp_path / "src", X[:50], texts=[f"doc {i}" for i in range(50)]
123+
)
124+
target = NumpyFileStore(tmp_path / "tgt", create=True)
125+
126+
manifest = migrate_store(source, target, m, batch_size=20)
127+
assert manifest.migrated_vectors == 50
128+
129+
130+
def _aecp_bin() -> str | None:
131+
"""Find the aecp CLI script next to the current Python interpreter."""
132+
aecp = Path(sys.executable).parent / "aecp"
133+
if aecp.exists():
134+
return str(aecp)
135+
return shutil.which("aecp")
136+
137+
138+
def _run_aecp(*args: str) -> subprocess.CompletedProcess[str]:
139+
bin_path = _aecp_bin()
140+
if bin_path is None:
141+
pytest.skip("aecp CLI not installed")
142+
return subprocess.run([bin_path, *args], capture_output=True, text=True, timeout=10)
143+
144+
145+
class TestCLI:
146+
"""Verify CLI entry points work."""
147+
148+
def test_cli_version(self):
149+
result = _run_aecp("version")
150+
assert result.returncode == 0
151+
assert "0.2.0" in result.stdout
152+
153+
def test_cli_help(self):
154+
result = _run_aecp("--help")
155+
assert result.returncode == 0
156+
assert "aecp" in result.stdout.lower()
157+
158+
def test_cli_plan(self):
159+
result = _run_aecp(
160+
"plan",
161+
"--source-model",
162+
"all-MiniLM-L6-v2",
163+
"--target-model",
164+
"bge-large",
165+
"--corpus-size",
166+
"10000",
167+
)
168+
assert result.returncode == 0
169+
assert "10,000" in result.stdout
170+
171+
172+
class TestVersionConsistency:
173+
"""Verify version is consistent across the package."""
174+
175+
def test_version_in_pyproject(self):
176+
pyproject = Path(__file__).parent.parent / "pyproject.toml"
177+
content = pyproject.read_text()
178+
assert 'version = "0.2.0"' in content
179+
180+
def test_version_in_init(self):
181+
init = Path(__file__).parent.parent / "src" / "aecp" / "__init__.py"
182+
content = init.read_text()
183+
assert "0.2.0" in content

0 commit comments

Comments
 (0)