Files
ruvnet--RuView/python/tests/test_smoke.py
T
ruv 5d90d4fef2 feat(adr-117/p1): scaffold python/ workspace — PyO3 + maturin + smoke tests (refs #785)
ADR-117 P1 — the python/ directory is now a working maturin-buildable
crate that produces the v2.x replacement for the legacy pure-Python
wifi-densepose==1.1.0 PyPI wheel.

## What lands

- `python/Cargo.toml` — PyO3 0.22 with `extension-module` + `abi3-py310`
  (one binary covers Python 3.10–3.13 per OS/arch — keeps the
  cibuildwheel matrix to 5 wheels per release, not 20). Depends on
  `wifi-densepose-core` from the existing v2/ workspace via relative
  path.

- `python/pyproject.toml` — maturin>=1.7 build backend with
  `python-source = "python"` and `module-name = "wifi_densepose._native"`
  so the compiled module loads as an internal underscore-private
  submodule of the user-facing `wifi_densepose` package. PEP 621
  metadata + classifiers + project URLs. Optional-deps:
  `wifi-densepose[client]` for the P4 WS/MQTT pure-Python layer,
  `wifi-densepose[dev]` for the test toolchain (pytest, ruff, mypy).

- `python/src/lib.rs` — minimal `#[pymodule] wifi_densepose_native`
  exporting `__rust_version__`, `__rust_build_tag__`,
  `__build_features__`, and a `hello()` smoke function. P2 will land
  the core type bindings here.

- `python/wifi_densepose/__init__.py` — pure-Python facade re-exporting
  the compiled module's symbols under their stable user-facing names.
  Docstring teaches the v1→v2 migration story up-front.

- `python/wifi_densepose/py.typed` — PEP 561 marker so `mypy --strict`
  in user code treats the wheel as fully typed (real stubs land in P2).

- `python/tests/test_smoke.py` — 6 P1 acceptance tests:
  1. package imports without error
  2. version string is PEP 440-compliant
  3. `__rust_version__` is reachable from Python (the diagnostic
     surface ADR-117 §5.2 promised)
  4. `__build_features__` lists `p1-scaffold` marker
  5. `wifi_densepose.hello()` returns "ok" (FFI round-trip)
  6. `wifi_densepose._native` is reachable but the leading underscore
     conveys "private; users should import the parent package"

- `python/README.md` — phase ledger, local build instructions
  (`maturin develop`), layout diagram.

## What's deferred to P2+

- Core type bindings (`CsiFrame`, `Keypoint`, `PoseEstimate`) — P2
- Vitals + signal DSP bindings + witness v2 — P3
- Pure-Python WS/MQTT client layer (`wifi_densepose[client]`) — P4
- cibuildwheel + PyPI publish — P5
- v1.99.0 tombstone — concurrent with P5

The new `python/` crate is intentionally OUTSIDE the v2/ Cargo
workspace — it has its own Cargo.toml with `[package]` not
`[workspace.package]` inheritance — to keep maturin's `python-source`
+ `module-name` config self-contained and to avoid forcing every
`cargo test --workspace` invocation in v2/ to compile pyo3.

Refs ADR-117 §5 (Detailed design) and §6 (Phased migration).
Refs #785 (tracking issue).

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-05-24 10:42:35 -04:00

82 lines
2.6 KiB
Python

"""ADR-117 P1 smoke tests — assert the maturin-built wheel loads and
its compiled module is callable.
These tests are the first acceptance gate of the v2.0 PyPI publish
pipeline (ADR-117 §11.1 — ``cargo test`` equivalent at the Python
level). They run on every cibuildwheel target in P5's CI matrix.
"""
from __future__ import annotations
def test_package_imports() -> None:
"""The top-level package must import without error."""
import wifi_densepose # noqa: F401
def test_version_string_well_formed() -> None:
"""Version string follows PEP 440 + matches pyproject.toml."""
import re
import wifi_densepose
assert isinstance(wifi_densepose.__version__, str)
# Allow pre-release segments (a, b, rc, dev) for non-final wheels.
assert re.match(
r"^\d+\.\d+\.\d+(a|b|rc|\.dev)?\d*$", wifi_densepose.__version__
), f"non-PEP-440 version: {wifi_densepose.__version__}"
def test_rust_version_surfaced() -> None:
"""Bound Rust core version must be reachable from Python.
This is the diagnostic surface ADR-117 §5.2 promised — users in
bug reports can paste ``wifi_densepose.__rust_version__`` so we
correlate behaviour with the exact ``v2/crates/`` HEAD.
"""
import wifi_densepose
assert isinstance(wifi_densepose.__rust_version__, str)
assert wifi_densepose.__rust_version__ # non-empty
def test_build_features_listed() -> None:
"""The wheel's build-time features must be enumerable.
P1 ships only the ``p1-scaffold`` feature marker; later phases
add more entries. The test asserts the contract that the list
exists and contains the P1 marker.
"""
import wifi_densepose
feats = wifi_densepose.__build_features__
assert isinstance(feats, list)
assert all(isinstance(f, str) for f in feats)
assert "p1-scaffold" in feats, f"P1 marker missing: {feats}"
def test_hello_returns_ok() -> None:
"""The compiled ``hello`` function round-trips through PyO3.
This is the actual smoke test — proves the FFI works end-to-end.
If this passes on every cibuildwheel target, the PyO3 build matrix
is healthy.
"""
import wifi_densepose
assert wifi_densepose.hello() == "ok"
def test_native_module_private() -> None:
"""The compiled module is reachable but marked private.
Users should ``import wifi_densepose``, not ``import
wifi_densepose._native``. The underscore prefix communicates that.
"""
import wifi_densepose
from wifi_densepose import _native
assert hasattr(_native, "hello"), "compiled module missing hello()"
# Both paths must return the same value.
assert wifi_densepose.hello() == _native.hello()