Skip to content

feat: add MediaBackend-v2-aware test harness - #168

Draft
JarbasAl wants to merge 1 commit into
devfrom
feat/media-backend-v2-harness
Draft

JarbasAl wants to merge 1 commit into
devfrom
feat/media-backend-v2-harness

Conversation

@JarbasAl

@JarbasAl JarbasAl commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

🤖 Auto-generated by Claude Fable 5 (claude-fable-5) via Claude Code — NOT human-reviewed. Verify before acting.

ovos-media's feat/media-backend-v2-port branch replaces the v1 MediaBackend contract with a report()/bind_event_reporter() one: plugins report physical PlaybackEvents (TRACK_START, PAUSED, RESUMED, STOPPED, END_OF_MEDIA, ERROR) instead of emitting bus messages themselves, load_track returns a bool instead of a None, and stop() becomes a concrete template method that delegates to a plugin's _stop(). The daemon (ovos-media's BaseMediaService) is now the sole translator from those events to ovos.common_play.* wire messages, via _handle_backend_event — and it has dropped handle_media_state_change entirely. ovoscope's media harnesses predate this port and needed updating to keep exercising the real daemon shape.

This adds MediaBackendHarness (ovoscope/media_backend.py), a harness for a plugin author testing their own MediaBackend v2 class in isolation: it binds a capturing spy reporter onto a backend instance and asserts the event sequence and per-event data it reports, without any daemon involved. The v2 template it targets (ovos_plugin_manager.templates.media) only exists on the unreleased OPM branch, so both the module import and the ovoscope/__init__.py re-export are guarded: import ovoscope is always safe against a released ovos-plugin-manager, and MediaBackendHarness() raises a clear ImportError only when actually constructed without the v2 template installed. Its own test module carries the equivalent guard at collection time, since its plugin stand-in subclasses the v2 template directly.

It also adds MockOCPBackendV2 (ovoscope/media.py), the v2 counterpart to the existing MockOCPBackend (kept unmodified, still importable, for plugin repos that haven't ported yet), and makes it OCPPlayerHarness's default injected backend. OCPPlayerHarness.__enter__ now binds each injected backend's event reporter, and guards the v1-only set_track_start_callback call on whether the service it reads track_start from actually has that attribute — not on the backend, which a v1 backend always has regardless of which ovos-media build is installed; guarding on the backend alone still crashed with AttributeError against a v2 build. In the default (no backend_factory) mode, audio_service is a MagicMock with no real _handle_backend_event behind it, so the backend's reporter is bound to a small shim reproducing the daemon's END_OF_MEDIA/ERROR wire translation — the only two events that mode's own control methods can actually drive — with its docstring naming the two daemon guards (currency, staleness) it deliberately skips, so a test needing those knows to go through the real daemon (backend_factory) instead. MockOCPBackendV2.load_track now clears current_uri on a failed load, so a failed load doesn't leave a stale, previous track's uri behind for a following simulate_invalid_stream()/report_track_end() to report against.

Every v2-only test class and cell is now gated on whether the v2 template actually imported, not merely on ovos-media being installed, and the backend_factory stand-in several pre-existing cells share (_RecordingBackend) now has a v1 variant selected the same way — including fixing that variant to emit LOADED_MEDIA on the topic a real v1 BaseMediaService actually subscribes to (ovos.common_play.media.state), not the per-namespace one MockOCPBackend emits, which no real BaseMediaService instance has ever listened on. The full suite now collects and runs clean against both a released ovos-plugin-manager (v2 cells skip) and the unreleased branches (v2 cells run) — collection used to abort entirely against released deps because a test module imported the v2 template unguarded at collection time.

Fail-before (source reverted with the test kept, run foreground, then restored): the set_track_start_callback guard turned 16 of 42 test_media.py tests failing with AttributeError across every OCPPlayerHarness-based class; the default-mode event-reporter shim's two new cells failed with no wire message emitted at all when reverted to binding straight into the MagicMock's _handle_backend_event; test_failed_load_clears_current_uri failed with the current_uri clear removed.

Full suite against released PyPI deps on python 3.10, foreground: 655 passed, 55 skipped, 0 failed. The 55 skips are exactly the v2-only cells gated off without the v2 template.

No workflow installs from git. coverage-pages.yml and release-workflow.yml's build_tests job gain the media, listener and bench extras, which they lacked, and that is the whole CI change. The released ovos-plugin-manager is 2.12.1a1 (latest alpha; its templates/media.py is still the v1 one, no PlaybackEvent, no bind_event_reporter) and released ovos-media is 2.2.5a1, so neither carries the v2 backend template. The [media] floor therefore stays at ovos-media>=2.0.0a9 and the v2 cells skip on the template guard they already carry; they start running once ovos-plugin-manager publishes the v2 template and the floor can be raised to it.

That also settles the build_tests (3.10) failure on TestOCPHarnessWithoutHandlePlay::test_enter_and_play_succeed_when_handle_play_is_absent: it was specific to the git-branch ovos-media those pre_install_pip lines installed, not to dev. Against released deps that cell passes, as does the rest of the suite.

@coderabbitai

coderabbitai Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Fresh off the press! I've got some check results for you. 🗞️

I've aggregated the results of the automated checks for this PR below.

🔍 Lint

A detailed summary of the latest automation run. 📝

❌ ruff: issues found in 76 file(s) — see job log
✅ actionlint: 12 workflow file(s), no finding

📊 Coverage

How much of the logic is under the microscope? 🔬

⚠️ 63.8% total coverage

Files below 80% coverage (17 files)
File Coverage Missing lines
ovoscope/golden_worker.py 0.0% 30
ovoscope/media_backend.py 0.0% 56
ovoscope/simple_listener.py 0.0% 63
ovoscope/version.py 0.0% 5
ovoscope/classic_listener.py 18.2% 117
ovoscope/intent_cases.py 22.3% 153
ovoscope/pytest_plugin.py 47.0% 210
ovoscope/ocp.py 47.9% 61
ovoscope/media.py 47.9% 162
ovoscope/cli.py 48.3% 140
ovoscope/tts_intelligibility.py 49.0% 102
ovoscope/e2e.py 57.1% 73
ovoscope/listener.py 57.1% 127
ovoscope/voice_loop.py 59.0% 119
ovoscope/audio.py 64.4% 126
ovoscope/__init__.py 66.9% 402
ovoscope/media_provider.py 67.6% 23

Full report: download the coverage-report artifact.

⚖️ License Check

Scanning for any non-commercial-only restrictions. 💰

✅ No license violations found.

Policy: Apache 2.0 (universal donor). StrongCopyleft / NetworkCopyleft / WeakCopyleft / Other / Error categories fail. MPL allowed.

📋 Repo Health

Scanning for any signs of code rot or decay. 🍄

✅ All required files present.

Latest Version: 1.11.1a1

✅ ovoscope/version.py — Version file
✅ README.md — README
✅ LICENSE — License file
✅ pyproject.toml — pyproject.toml
⚠️ setup.py — setup.py
✅ CHANGELOG.md — Changelog
✅ ovoscope/version.py has valid version block markers

🔒 Security (pip-audit)

I've checked the security of our API endpoints. 🌐

✅ No known vulnerabilities found (133 packages scanned).

🏷️ Release Preview

Evaluating the overall quality of the next release. ✨

Current: 1.11.1a1 → Next: 1.12.0a1

Signal Value
Label feature
PR title feat: add MediaBackend-v2-aware test harness
Bump minor

✅ PR title follows conventional commit format.


🚀 Release Channel Compatibility

Predicted next version: 1.12.0a1

Channel Status Note Current Constraint
Stable ⚪ Not in channel -
Testing ❌ Too new (must be <1.0.0) ovoscope>=0.7.2,<1.0.0
Alpha ✅ Compatible ovoscope>=1.6.15a1

🔨 Build Tests

The build bots have finished their assembly. 🤖

✅ All versions pass

Python Build Install Tests pytest
3.10 ✅ ✅ ✅ 758 passed, 59 skipped, 85 warnings in 246.20s (0:04:06)
3.11 ✅ ✅ ✅ 758 passed, 59 skipped, 85 warnings in 256.68s (0:04:16)
3.12 ✅ ✅ ✅ 758 passed, 59 skipped, 85 warnings in 263.65s (0:04:23)
3.13 ✅ ✅ ✅ 758 passed, 59 skipped, 122 warnings in 265.19s (0:04:25)
3.14 ✅ ✅ ✅ 758 passed, 59 skipped, 122 warnings in 250.61s (0:04:10)

Powered by OVOS scripts and a bit of magic. ✨

@JarbasAl
JarbasAl force-pushed the feat/media-backend-v2-harness branch from cf5ef23 to 39f2275 Compare September 4, 2026 15:59
@github-actions github-actions Bot added feature and removed feature labels Sep 4, 2026
@JarbasAl
JarbasAl force-pushed the feat/media-backend-v2-harness branch from 39f2275 to eb6b48b Compare September 4, 2026 16:31
@github-actions github-actions Bot added feature and removed feature labels Sep 4, 2026
@JarbasAl
JarbasAl force-pushed the feat/media-backend-v2-harness branch from eb6b48b to 15d0dba Compare September 8, 2026 11:09
@github-actions github-actions Bot added feature and removed feature labels Sep 8, 2026
@JarbasAl
JarbasAl force-pushed the feat/media-backend-v2-harness branch from 15d0dba to bc03bcf Compare October 1, 2026 11:18
MediaBackendHarness drives one MediaBackend v2 plugin in isolation, without a
daemon: it binds a spy reporter, calls each v2 verb, and asserts the physical
playback events the plugin reported. OCPPlayerHarness gains backend injection,
so a test can drive the real ovos-media player over a backend it controls.

The v2 names (PlaybackEvent, bind_event_reporter, report) exist only on
ovos-plugin-manager's feat/media-backend-v2 branch, so the import is guarded
and every v2 cell skips with a reason against a released OPM. The cells
therefore run in CI only once ovos-plugin-manager 3.0.0a1 publishes.

Three review findings are answered.

C1, the branch did not merge into dev. Dev #188 set the release workflow's
install_extras to "test"; this branch set an explicit five-extra list. The
hunk is dropped rather than re-resolved, because dev's "test" extra is a
strict superset of it: it carries ovos-audio, ovos-media, ovos-dinkum-listener,
ovos-pydantic-models and numpy, which are exactly the five, plus more. The
coverage-pages workflow keeps its own widening, which the body now discloses
instead of calling the release workflow "the whole CI change".

C2, the v2 cells failed against the branches the PR names. Re-measured against
the CURRENT heads rather than the ones the review read: ovos-plugin-manager
0b4d806 (was dfcb7fab) and ovos-media 32c8582 (was 997fc82a). Most of the
failures were the dependencies' and are gone. What remained was ours: five
assertions read a backend attribute on the line after a bus emit, so they
raced the daemon's own thread. Each now uses this class's existing bounded
settle (assert_backend_playing, assert_backend_paused, _eventually at 2s).
The two assertions on a directly driven backend are left alone, because that
path is synchronous and has no race.

Result: 68 passed, six runs out of six, where the review measured 6 to 8
failures. The cells have teeth in both directions, proven by mutation rather
than claimed: making report() drop its event data reds 4 cells, and making
bind_event_reporter never bind reds 17. The tree restores to 68 green after
each.

C3, __exit__ deleted a reporter bound before the harness. A daemon binds its
own handler before a test ever sees the backend, and clearing it left the
daemon deaf for the rest of the process with nothing raised. __enter__ now
remembers what it displaces and __exit__ puts it back; an unbound backend
still ends unbound, which is asserted as the control.

The v2 availability probe import in test_media.py carries an explicit
noqa: F401. It exists to make the try/except detect the template, so ruff's
unused-import finding on it is intentional rather than a defect; the marker
states that instead of leaving CI to report it.

T-7216, from T-0260.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@JarbasAl
JarbasAl force-pushed the feat/media-backend-v2-harness branch from bc03bcf to b59e45e Compare October 1, 2026 12:08

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant