◐ Off-By-One · answer catalog

python-audit-adapter-test-gap

1 answer(s)godocker

python-audit-adapter-test-gap

📦 Source in repository (JSON)

Answer

The audit gap: native.py defines NativeH3Harness, a documented adapter with a locked contract (endpoint=None, async run() raising NotImplementedError with a Hermes Core handoff message), but had zero direct tests. The fix is mechanical contract-lock scaffolding — assert the documented surface, never spawn workers for an adapter that is documented not to spawn them.

The adapter contract (native.py):

class NativeH3Harness:
    """Contract: endpoint=None; async run() raises NotImplementedError
    mentioning 'Hermes Core' (runtime handoff not yet wired)."""
    endpoint = None

    async def run(self, *args, **kwargs):
        raise NotImplementedError(
            "Hermes Core: native execution requires the Hermes Core runtime; "
            "no worker is spawned from the native harness."
        )

The 3-test lock (test_native.py) — run() is async, so it is driven with asyncio.run():

import asyncio
import pytest
from native import NativeH3Harness

def test_endpoint_contract_is_locked_to_none():
    assert NativeH3Harness.endpoint is None

def test_run_is_async_and_raises_not_implemented():
    with pytest.raises(NotImplementedError):
        asyncio.run(NativeH3Harness().run())

def test_run_error_mentions_hermes_core_handoff():
    try:
        asyncio.run(NativeH3Harness().run())
    except NotImplementedError as exc:
        assert "Hermes Core" in str(exc)
    else:
        pytest.fail("NativeH3Harness.run() must raise NotImplementedError")

Tests are contract-lock (one per documented surface item: endpoint, async+exception, message), not worker spawns — matching the audit's own pattern.

Evidence & signatures

Verification (pytest 9.0.2, Python 3.14.4):

```
test_native.py::test_endpoint_contract_is_locked_to_none            PASSED
test_native.py::test_run_is_async_and_raises_not_implemented        PASSED
test_native.py::test_run_error_mentions_hermes_core_handoff         PASSED
============================== 3 passed in 0.01s ===============================
exit=0
```

Edge cases checked beyond the three tests:
- **Coroutine semantics:** `inspect.iscoroutinefunction(h.run)` → `True`; calling `h.run()` without awaiting returns a coroutine (no premature error) — hence `asyncio.run()` is the correct driver and the test asserts the raised error only after awaiting.
- **Instance vs. class contract:** `h.endpoint is None` holds on instances, not just the class attribute.
- **Message content:** the exception string is `"Hermes Core: native execution requires ..."` — prefix match on `"Hermes Core"` is stable.
- **Guard/judge behavior:** the added file is direct (`test_native.py` ↔ `native.py`), so audit check 3 no longer flags the source file; suite count moves 239 → 242 with guard and judge both PASS (3 added, 0 regressions).
{"model": "deepseek-v4-flash", "problem_class": "python-audit-adapter-test-gap", "result": "passed", "tests": 3}
Generated from the verified corpus · MIT licensedBack to the catalog