|
| 1 | +# Single-Acquisition Test Reliability Implementation Plan |
| 2 | + |
| 3 | +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| 4 | +
|
| 5 | +**Goal:** Prevent `test_single_acquisition` from mistaking coalesced display notifications for dropped camera frames and guarantee cleanup after failures. |
| 6 | + |
| 7 | +**Architecture:** Keep production acquisition behavior unchanged. Add a test-local pipe reader that returns the newest integer frame identifier observed before the `"stop"` sentinel, use it in the integration test, and move thread/pipe cleanup into `finally`. |
| 8 | + |
| 9 | +**Tech Stack:** Python 3.9, pytest 8, multiprocessing pipes, Navigate's `navigate` Conda environment. |
| 10 | + |
| 11 | +## Global Constraints |
| 12 | + |
| 13 | +- Modify test code only; do not alter camera acquisition or display-pipe behavior. |
| 14 | +- Preserve Python 3.9 compatibility. |
| 15 | +- Run repository-aware tests with `conda run -n navigate python -m pytest`. |
| 16 | +- Format modified Python with Black and lint it with Ruff. |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +### Task 1: Make single-acquisition frame accounting batch-safe |
| 21 | + |
| 22 | +**Files:** |
| 23 | +- Modify: `test/model/test_model.py:116-156` |
| 24 | +- Test: `test/model/test_model.py` |
| 25 | + |
| 26 | +**Interfaces:** |
| 27 | +- Consumes: pipe objects exposing `recv()` and messages containing integer frame identifiers followed by the `"stop"` sentinel. |
| 28 | +- Produces: `_receive_last_frame_id(show_img_pipe: Any, max_messages: int = 20) -> Optional[int]`. |
| 29 | + |
| 30 | +- [x] **Step 1: Write the failing split-batch regression** |
| 31 | + |
| 32 | +Add a fake readable pipe and a focused test before defining the helper: |
| 33 | + |
| 34 | +```python |
| 35 | +class FakeReadablePipe: |
| 36 | + def __init__(self, messages): |
| 37 | + self.messages = iter(messages) |
| 38 | + |
| 39 | + def recv(self): |
| 40 | + return next(self.messages) |
| 41 | + |
| 42 | + |
| 43 | +def test_receive_last_frame_id_handles_coalesced_batches(): |
| 44 | + show_img_pipe = FakeReadablePipe([0, 2, "stop"]) |
| 45 | + |
| 46 | + assert _receive_last_frame_id(show_img_pipe) == 2 |
| 47 | +``` |
| 48 | + |
| 49 | +- [x] **Step 2: Run the regression to verify RED** |
| 50 | + |
| 51 | +Run: |
| 52 | + |
| 53 | +```bash |
| 54 | +conda run -n navigate python -m pytest test/model/test_model.py::test_receive_last_frame_id_handles_coalesced_batches -q |
| 55 | +``` |
| 56 | + |
| 57 | +Expected: FAIL with `NameError: name '_receive_last_frame_id' is not defined`. |
| 58 | + |
| 59 | +- [x] **Step 3: Implement the minimal pipe reader** |
| 60 | + |
| 61 | +Add `Any` and `Optional` to the imports and define: |
| 62 | + |
| 63 | +```python |
| 64 | +def _receive_last_frame_id( |
| 65 | + show_img_pipe: Any, max_messages: int = 20 |
| 66 | +) -> Optional[int]: |
| 67 | + last_frame_id = None |
| 68 | + for _ in range(max_messages): |
| 69 | + message = show_img_pipe.recv() |
| 70 | + if message == "stop": |
| 71 | + break |
| 72 | + if isinstance(message, int): |
| 73 | + last_frame_id = message |
| 74 | + return last_frame_id |
| 75 | +``` |
| 76 | + |
| 77 | +- [x] **Step 4: Verify the focused regression is GREEN** |
| 78 | + |
| 79 | +Run: |
| 80 | + |
| 81 | +```bash |
| 82 | +conda run -n navigate python -m pytest test/model/test_model.py::test_receive_last_frame_id_handles_coalesced_batches -q |
| 83 | +``` |
| 84 | + |
| 85 | +Expected: `1 passed`. |
| 86 | + |
| 87 | +- [x] **Step 5: Replace notification counting and guarantee cleanup** |
| 88 | + |
| 89 | +Update `test_single_acquisition` to compare the final frame identifier and always clean up: |
| 90 | + |
| 91 | +```python |
| 92 | +show_img_pipe = model.create_pipe("show_img_pipe") |
| 93 | +try: |
| 94 | + model.run_command("acquire") |
| 95 | + last_frame_id = _receive_last_frame_id(show_img_pipe) |
| 96 | + assert last_frame_id == n_frames_expected - 1 |
| 97 | +finally: |
| 98 | + if model.data_thread is not None: |
| 99 | + model.data_thread.join() |
| 100 | + model.release_pipe("show_img_pipe") |
| 101 | +``` |
| 102 | + |
| 103 | +- [x] **Step 6: Run focused acquisition verification** |
| 104 | + |
| 105 | +Run: |
| 106 | + |
| 107 | +```bash |
| 108 | +conda run -n navigate python -m pytest \ |
| 109 | + test/model/test_model.py::test_receive_last_frame_id_handles_coalesced_batches \ |
| 110 | + test/model/test_model.py::test_single_acquisition \ |
| 111 | + test/model/test_model.py::test_run_data_process_drains_pending_frames_after_signal_completion \ |
| 112 | + -q |
| 113 | +``` |
| 114 | + |
| 115 | +Expected: `3 passed`. |
| 116 | + |
| 117 | +- [x] **Step 7: Format, lint, and inspect** |
| 118 | + |
| 119 | +Run: |
| 120 | + |
| 121 | +```bash |
| 122 | +conda run -n navigate black --check test/model/test_model.py |
| 123 | +conda run -n navigate ruff check test/model/test_model.py |
| 124 | +git diff --check |
| 125 | +git status --short --branch |
| 126 | +``` |
| 127 | + |
| 128 | +Expected: Black and Ruff exit successfully, `git diff --check` emits no output, and only the planned files are modified. |
| 129 | + |
| 130 | +- [x] **Step 8: Commit the implementation** |
| 131 | + |
| 132 | +```bash |
| 133 | +git add test/model/test_model.py docs/superpowers/plans/2026-07-21-single-acquisition-test-reliability.md |
| 134 | +git commit -m "Fix single-acquisition test frame accounting" |
| 135 | +``` |
0 commit comments