diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..eca11902 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +tests/fixtures/surface/pre_flip_init.py.txt text eol=lf diff --git a/changelog.md b/changelog.md index 779df922..96a5af23 100644 --- a/changelog.md +++ b/changelog.md @@ -15,6 +15,13 @@ sustained stretch without a correction. ## Unreleased +### Rename the unit, drive undo/redo, and read inhibited modules + +`set_device_name()` sends a sparse Version update. `undo()` and `redo()` drive +the unit's native editable-preset history, and `inhibited_modules()` reads the +explicit Global EQ/Input Gate load-inhibition flags. All three wire shapes are +pinned offline and were exercised on CorOS 4.0.1 and 4.1.0 hardware. + ### Preserve device-provided preset keys without adding a listing dependency `delete_preset()` and `move_preset()` now also accept the `ProductData` returned diff --git a/docs/api.md b/docs/api.md index 50508cd0..6752c662 100644 --- a/docs/api.md +++ b/docs/api.md @@ -46,7 +46,7 @@ already read and need no connection; calling them as methods raises | | | |---|---| | **Connect** | `protocol.connect(profile=, support=)` resolves the unit's device profile before the handshake (ADR-0020) and returns a connected client. An unknown `(device_type, zenos_git_hash)` raises `UnsupportedDevice`. `Support.VERIFIED` (default) refuses an operation the profile has not verified; `Support.EXPERIMENTAL` runs it with one warning. `qc.models`, `qc.params` and `qc.options` are that connection's own constants | -| **Inspect** | `version()`, `list_presets(setlist)`, `find_preset(name, setlist)`, `read_preset(setlist, slot)` | +| **Inspect / device identity** | `version()`, `set_device_name(name)`, `list_presets(setlist)`, `find_preset(name, setlist)`, `read_preset(setlist, slot)` | | **Navigate** | `recall_preset(setlist, slot)`, `switch_scene(scene)` | | **Edit the grid** | `set_chain_input(row, input)`, `reroute_grid_input(preset, input)`, `set_param(target, param, value)`, `set_bypass(Block(row, column), bypassed)` | | **Add and remove blocks** | `set_block(Block(row, column, model_id))`, `remove_block(cell)`, `move_block(source, destination)`, `catalog` | @@ -68,6 +68,7 @@ already read and need no connection; calling them as methods raises | **Watch what the unit pushes** | `add_listener(fn)`, `remove_listener(fn)`. Your `fn` is called with every message the unit sends. It runs on the transport's read thread, so it must not block and may not read from the unit. To catch the connect handshake's own burst, register before it with `protocol.connect(before_handshake=...)` | | **Scenes** | `copy_scene(from_scene, to_scene, swap=False)`, `set_scene_label(scene, label)`, `set_scene_color(scene, argb)` | | **Global settings** | `settings()`, `update_settings(**fields)`, `set_scene_bypass_behavior()`, `set_global_bypass()`, `set_master_volume_assignment()`, `mode()`, `set_mode()`, `set_mode_cycle()`, `set_gig_view()` | +| **Inhibited global modules** | `inhibited_modules()` | | **Global EQ** | `global_eq()`, `set_global_eq(band, gain=, frequency=, q=, filter_type=, enabled=)`, `set_global_eq_output(level=, out12=, out34=)`, `set_global_eq_bypassed()` | | **I/O ports** | `io_settings()`, `set_input_port()`, `set_output_port()`, `set_usb_port()`, `set_midi_thru()`, `set_output_pairing()` | | **Tuner and Looper** | `tuner()`, `show_tuner()`, `set_tuner_input()`, `set_tuner_reference()`, `set_tuner_mute()`, `looper()` (states named by `LooperState`) | @@ -76,6 +77,7 @@ already read and need no connection; calling them as methods raises | **Copying** | `copy_preset(from_setlist, position, to_setlist)`: recall plus save, so it loads each source | | **Device list** | `pin_model()`, `unpin_model()`, `pinned_models()`, `master_volume()` | | **Neural Captures** | `captures()` and `list_irs()` to browse the library, `set_capture(cell, entry)` to place one. Creating a capture is the unit's own wizard; disconnect first, since a connected client suppresses it | +| **Edit history** | `undo()`, `redo()` | | **Discovery** | `list_folders()`: every folder the unit knows, including the factory Captures Library and plugin artist presets; `recents()`, `favorites()`, `add_favorite()`, `remove_favorite()` | | **Manage presets** | `save_current_preset(setlist, slot, name)`, `delete_preset(setlist, preset)`, `move_preset(setlist, preset, to_slot)`; `preset` may be the exact name or a `ProductData` returned by `list_presets()` | | **Local backups** | `create_local_backup()` returns the unit's validated portable backup document; serialize it to JSON wherever you keep backups | diff --git a/docs/domain-model.md b/docs/domain-model.md index 0bbdc9a1..75172b68 100644 --- a/docs/domain-model.md +++ b/docs/domain-model.md @@ -1095,7 +1095,7 @@ hardware, host concerns or reference text with nothing for a host API to model. | Looper X: parameters | `LooperBlock.params` | yes | | | Looper X: transport actions | **omitted**; `LooperBlock.state` is readable | partly | transport is not drivable over USB; MIDI CC#48-61 is the documented route | | Assign Looper X Actions (footswitch layout) | `device.settings.looper_actions` | yes | `GeneralSettings.looper_stomp_assignments`, global. The MIDI CC follows the action, not the switch | -| Undo / redo | **omitted** | no | `UndoRedo` arrives as an acceptance signal; drivable, and not modelled | +| Undo / redo | **omitted from the model** | yes | protocol `undo()` / `redo()` reversed and reapplied a bypass edit on CorOS 4.0.1 and 4.1.0 | ## Chapter 5 - The Directory @@ -1170,7 +1170,7 @@ hardware, host concerns or reference text with nothing for a host API to model. | GIG VIEW ACCESS | `settings.gig_view_access` | yes | | | LATENCY COMPENSATION | `settings.latency_compensation` | yes | | | MIDI submenu | `settings.midi` | partly | see ch. 8 row | -| Device name | **omitted** | no | candidates `Serialization`, `GeneralSettings`, unexplored | +| Device name | **omitted from the model** | yes | protocol `set_device_name()` is confirmed on CorOS 4.0.1 and 4.1.0 | | Firmware and serial (Device Information) | `device.firmware`, `device.serial` | yes | | | Diagnostics / Send Report | **omitted** | no | decoded but never driven | | 3rd-party licenses | - | n/a | reference text | diff --git a/docs/manual-coverage.md b/docs/manual-coverage.md index b97c2f6c..d9b17a48 100644 --- a/docs/manual-coverage.md +++ b/docs/manual-coverage.md @@ -18,10 +18,10 @@ A "candidate" names a message type from the unit's own schema or a field in ## Summary -Of 105 features audited: **65 yes**, **9 partly**, **20 no**, **11 n/a**. +Of 105 features audited: **68 yes**, **8 partly**, **18 no**, **11 n/a**. -Of the 94 features a host could plausibly drive, 65 are fully covered and 9 are -partly covered. Twenty remain untouched. Of those, a few are writes confirmed to +Of the 94 features a host could plausibly drive, 68 are fully covered and 8 are +partly covered. Eighteen remain untouched. Of those, a few are writes confirmed to do nothing with no route found (preset tags, duplicating a setlist as one operation), and two whole features need the physical world: creating a Neural Capture, and loading from the factory Captures Library. How an unknown gets @@ -70,7 +70,7 @@ settled is in [capture.md](capture.md). | Remove a block | yes | `remove_block()` (the `DELETE` action; an `UPDATE` with `hash: 0` is ignored) | | Move a block | yes | `move_block(source, destination)`; a cross-row move makes the unit create a branch | | DSP capacity refusal | partly | detected, not predicted: a refused placement raises `BlockRefused`. Headroom cannot be read; `CPULoad` never arrives | -| Global EQ / Input Gate auto-disable under load | partly | `CompilerInhibitedModules{global_gate, global_eq}` is decoded and arrives on grid edits. Not surfaced in the API | +| Global EQ / Input Gate auto-disable under load | yes | `inhibited_modules()` reads `CompilerInhibitedModules{global_gate, global_eq}`; the same state also arrives on grid edits | | Input blocks: assign a physical input | yes | `set_chain_input()` | | Output blocks: assign a destination | yes | `set_chain_output()`. 16 to 18 are internal row-to-row; 19 (`MULTIPLE`) is the Multi-Out | | Input Gate Control | yes | `set_param(LaneInput(row), ...)`: `NOISE REDUCTION`, `BYPASS`, `INPUT GAIN`, per scene. `GAIN REDUCTION` is a meter | @@ -93,7 +93,7 @@ settled is in [capture.md](capture.md). | Set Parameters as Defaults | no | `DefaultParameters` is decoded and subscribed; never written | | Looper X: place the block | yes | an ordinary catalog model | | Looper X: transport actions and parameters | partly | `looper()` reads the full status and `LooperState` names five states. The transport is not driven from here; MIDI CC#48 to 61 is the documented route | -| Undo / redo | no | `UndoRedo` is decoded and subscribed. It arrives after accepted grid edits, so it is useful as an acceptance signal | +| Undo / redo | yes | `undo()` and `redo()` send sparse `UndoRedo{UPDATE}` commands; a bypass edit was reversed and reapplied on disposable preset copies | ## 05 The Directory @@ -159,7 +159,7 @@ the menu; fifteen of its fields are confirmed writable one at a time. | STOMP MODE BYPASS (auto-assign on load) | yes | `update_settings(stomp_mode_auto_assign=...)` | | HOLD TIMING, SWAP TEMPO AND TUNER, GIG VIEW ACCESS | yes | all three via `update_settings()`. `set_hold_timing()` takes `Milliseconds` and writes the index the unit stores (500 to 1000 ms in 100 ms steps); `hold_timing_ms()` reads it back | | LATENCY COMPENSATION | yes | `update_settings(enable_dynamic_delay_compensation=...)` | -| Device name | no | candidates `Serialization`, `GeneralSettings` | +| Device name | yes | `set_device_name()` sends sparse `Version{UPDATE, custom_name}`; read-back and restoration matched on CorOS 4.0.1 and 4.1.0 | | Firmware and serial | yes | `version()` | | Diagnostics (DSP, footswitches, USB) | no | `ModuleStats` is decoded and subscribed; `Diagnostics` and `DSPCommsDiagnostics` are not | | CorOS updates | no | `Updater` is decoded and subscribed; never driven, and out of scope for good | diff --git a/docs/protocol.md b/docs/protocol.md index 133c034d..c3bd071b 100644 --- a/docs/protocol.md +++ b/docs/protocol.md @@ -2103,6 +2103,9 @@ wire, with no independent read-back. |---|---|---|---| | connect handshake | `ResetCommsBuffers` + `Version` UPDATE + `ModelRepo` READ + `Connection` + subscribe READs | read-back | the connect gate; state pushes flow only after it | | version read | `Version{action: READ}` | read-back | two messages come back; `version()` accepts only one carrying `device_serial_number` or `app_fw_version` (section 4.4) | +| `set_device_name` | `Version{UPDATE, custom_name}` | read-back + on-unit | sparse echo, read-back, and restoration confirmed on CorOS 4.0.1 and 4.1.0 | +| `undo` / `redo` | `UndoRedo{UPDATE, undo}` / `{UPDATE, redo}` | read-back + on-unit | a bypass edit was reversed and reapplied on disposable preset copies; empty-history behaviour is unknown | +| `inhibited_modules` | `CompilerInhibitedModules{READ}` | read-back | explicit false/false reply on CorOS 4.0.1 and 4.1.0; true semantics are schema-derived, not yet observed | | `create_local_backup` | `LocalBackup{CREATE}` then `LocalBackup{UPDATE, backup_json}` pushes, the last with `is_last_chunk` | captured only | section 10.5. `can_apply_backup` never appeared, so the refusal path is unverified | | `recall_preset` / `read_preset` | `SetlistPosition{UPDATE, folder_key, position, is_factory, request_id}` then a `RecallPreset` push | read-back | the push echoes the recall's `request_id` | | `read_current_preset` / `read_current_preset_push` | `RecallPreset{READ, request_id}` | read-back | the live grid, no side effects. The push variant hands back the whole reply with `reason` | diff --git a/pyquadcortex/protocol/client.py b/pyquadcortex/protocol/client.py index 70a9b1b8..39f72982 100644 --- a/pyquadcortex/protocol/client.py +++ b/pyquadcortex/protocol/client.py @@ -660,6 +660,41 @@ def version(self, timeout: float = 10.0): or m.HasField("app_fw_version")), ) + def set_device_name(self, name: str): + """Set the user-visible device name. + + The update is deliberately sparse: only ``custom_name`` is sent, so + none of the other version/identity fields can be overwritten. + Confirmed on CorOS 4.0.1 and 4.1.0, firmware d14e: the unit echoed a + sparse Version UPDATE, and read-back and restoration matched. + """ + if not isinstance(name, str): + raise TypeError("name must be a string") + self._t.send(pa.VersionMessage( + action=pa.MessageAction.UPDATE, custom_name=name + )) + + def undo(self): + """Undo the most recent editable-preset operation. + + Confirmed on CorOS 4.0.1 and 4.1.0, firmware d14e: a bypass edit was + reversed. Behaviour when the edit history is empty is not established. + """ + self._t.send(pa.UndoRedoMessage( + action=pa.MessageAction.UPDATE, undo=True + )) + + def redo(self): + """Redo the most recently undone editable-preset operation. + + Confirmed on CorOS 4.0.1 and 4.1.0, firmware d14e: the bypass edit + reversed by :meth:`undo` was reapplied. Behaviour when the edit history + is empty is not established. + """ + self._t.send(pa.UndoRedoMessage( + action=pa.MessageAction.UPDATE, redo=True + )) + def create_local_backup(self, timeout: float = 60.0) -> dict[str, typing.Any]: """Create and return the device's portable local-backup document. @@ -2923,6 +2958,25 @@ def global_eq(self, timeout: float = 10.0): return self._read_state(pa.GlobalEQMessage, lambda m: m.HasField("bypassed"), timeout) + def inhibited_modules(self, timeout: float = 10.0): + """Whether DSP load has automatically disabled the Input Gate or Global EQ. + + Returns the raw ``CompilerInhibitedModules`` message. The schema names + ``global_gate`` and ``global_eq`` as the corresponding inhibited states; + only the explicit false/false reply has been observed. Both fields are + required so an absent optional field is never mistaken for false. + + Confirmed read-only on hardware: a ``CompilerInhibitedModules{READ}`` + returned ``08 01 18 00 20 00`` with both fields explicit on Quad Cortex, + CorOS 4.0.1 and 4.1.0 / firmware d14e. The same message type was already + observed after grid edits when DSP load changes the inhibited state. + """ + return self._read_state( + pa.CompilerInhibitedModulesMessage, + lambda m: m.HasField("global_gate") and m.HasField("global_eq"), + timeout, + ) + def set_global_eq_bypassed(self, bypassed: bool = True): """Turn the Global EQ off or on. Confirmed writable on hardware. diff --git a/pyquadcortex/protocol/profiles.py b/pyquadcortex/protocol/profiles.py index 7e78d135..ea700aa0 100644 --- a/pyquadcortex/protocol/profiles.py +++ b/pyquadcortex/protocol/profiles.py @@ -23,7 +23,8 @@ class QuadCortex41(QuadCortex): passed, 8 skipped, on a Quad Cortex running CorOS 4.1.0 / app firmware d14e, by tony-xmelon. That is a contributor's report and the maintainer has not reproduced it, which is what ``Evidence.CONTRIBUTED`` says here. - ``create_local_backup`` has its own dated 4.1.0 capture and is VERIFIED; + ``create_local_backup`` has its own dated 4.1.0 capture. The contributed + device-name round trip also verified ``set_device_name``; both are VERIFIED. other inherited operations refuse under ``Support.VERIFIED`` and run with a warning under ``Support.EXPERIMENTAL``. The snapshot is deliberately absent: binding the 4.0.1 constants would hand a 4.1 user names their unit does not @@ -42,7 +43,7 @@ class QuadCortex41(QuadCortex): MEASURED_ON = ("4.1.0",) EVIDENCE = Evidence.CONTRIBUTED - VERIFIED = frozenset({"create_local_backup"}) + VERIFIED = frozenset({"create_local_backup", "set_device_name"}) models = NoSnapshot("coros_4_1_0") params = NoSnapshot("coros_4_1_0") options = NoSnapshot("coros_4_1_0") diff --git a/tests/hardware/conftest.py b/tests/hardware/conftest.py index d4e7d7db..dd939913 100644 --- a/tests/hardware/conftest.py +++ b/tests/hardware/conftest.py @@ -180,7 +180,7 @@ def pytest_collection_modifyitems(session, config, items): lambda dropped: config.hook.pytest_deselected(items=dropped))) return gated = sorted({ - str(path.relative_to(ROOT)) + path.relative_to(ROOT).as_posix() for path in map(_resolved, items) if path is not None and path.is_relative_to(SUITE) }) diff --git a/tests/hardware/readme.md b/tests/hardware/readme.md index fc3133a3..161c66fa 100644 --- a/tests/hardware/readme.md +++ b/tests/hardware/readme.md @@ -9,6 +9,11 @@ successful run leaves the unit exactly as it found it. pytest tests/hardware --hardware ``` +The undo/redo test makes a disposable copy of the loaded preset, edits that +copy, then independently restores the original and deletes the copy. Saving the +copy clears its instrument tag and makes the scene active at save time its +default scene; those metadata changes affect only the disposable copy. + `pytest --hardware` from the repo root also works, and runs both suites, the offline one and this one. Name the directory unless you want that. @@ -76,9 +81,10 @@ offline modules do `from waiting import ...`, which works only while pytest puts callables put the grid right and leave the flag set. A session teardown clears it with a recall, and only when the preset was clean before the first test: unsaved edits that were already there are the owner's. -- **It edits a scratch copy.** `scratch_preset` hands a test a disposable copy of - the loaded preset. Nothing here saves a preset, so if a run dies badly, - recalling any preset discards whatever it left on the grid. +- **It edits a scratch copy.** `scratch_preset` saves a disposable copy of the + loaded preset and hands that copy to the test. It never saves over one of the + owner's presets; if a run dies badly, the fixed scratch name identifies the + copy that may need removing. ## Before you run it diff --git a/tests/hardware/test_identity_and_history.py b/tests/hardware/test_identity_and_history.py new file mode 100644 index 00000000..3a899731 --- /dev/null +++ b/tests/hardware/test_identity_and_history.py @@ -0,0 +1,67 @@ +"""Reversible device-name and edit-history checks against a real unit.""" + +import time + +import pytest + +from pyquadcortex import protocol +SETTLE = 1.0 + + +@pytest.mark.verifies("set_device_name") +def test_device_name_round_trips_and_is_restored(qc): + identity = qc.version() + if not identity.HasField("custom_name"): + pytest.skip("the unit has no device name to restore without inventing one") + before = identity.custom_name + probe = "pyquadcortex probe" + if before == probe: + probe = "pyquadcortex probe 2" + + def read_name(): + reply = qc.version() + assert reply.HasField("custom_name"), ( + "the Version reply omitted custom_name, so the name cannot be " + "confirmed or restored") + return reply.custom_name + + try: + qc.set_device_name(probe) + time.sleep(SETTLE) + assert read_name() == probe + finally: + qc.set_device_name(before) + time.sleep(SETTLE) + + assert read_name() == before + + +@pytest.mark.verifies("undo", "redo") +def test_undo_and_redo_reverse_and_reapply_a_scratch_edit(qc, scratch_preset): + """Create, edit, and remove a test-owned copy of the loaded preset.""" + setlist, position, _name = scratch_preset + before_preset = qc.read_preset(setlist, position, timeout=30.0) + occupied = protocol.blocks(before_preset) + if not occupied: + pytest.skip("the loaded preset has no block whose bypass can be edited") + target = occupied[0] + before_scene = int(qc.active_scene()) + before = protocol.bypass_state(before_preset, target).scenes[before_scene] + + qc.set_bypass(target, not before) + time.sleep(SETTLE) + assert protocol.bypass_state( + qc.read_current_preset(), target + ).scenes[before_scene] is not before + + qc.undo() + time.sleep(SETTLE) + assert protocol.bypass_state( + qc.read_current_preset(), target + ).scenes[before_scene] is before + + qc.redo() + time.sleep(SETTLE) + assert protocol.bypass_state( + qc.read_current_preset(), target + ).scenes[before_scene] is not before diff --git a/tests/hardware/test_settings_values.py b/tests/hardware/test_settings_values.py index 7b07e24e..ea6c381b 100644 --- a/tests/hardware/test_settings_values.py +++ b/tests/hardware/test_settings_values.py @@ -30,6 +30,7 @@ from pyquadcortex.protocol import client, units, values from pyquadcortex.protocol.enums import Input +from pyquadcortex.protocol.proto import ProductionAutomation_pb2 as pa SETTLE = 2.0 @@ -38,6 +39,22 @@ PORT = Input.INPUT_1 +@pytest.mark.verifies("inhibited_modules") +def test_inhibited_modules_is_a_complete_read_only_snapshot(qc): + """Both false fields were explicitly present on CorOS 4.1.0 / d14e. + + Presence matters here: protobuf also returns false when an optional field was + never sent, and reporting that default as device state would be a guess. + """ + # Read twice because a first state READ can be dropped; both successful + # replies must carry explicit fields rather than protobuf defaults. + for _ in range(2): + state = qc.inhibited_modules() + assert state.action == pa.MessageAction.UPDATE + assert state.HasField("global_gate") + assert state.HasField("global_eq") + + def _input_level(qc, port_id): for port in qc.io_settings().settings.in_port: if port.input_port_id == int(port_id): diff --git a/tests/test_client.py b/tests/test_client.py index 3ac42661..7beb8337 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -38,8 +38,9 @@ def __init__(self, canned=None): def send(self, msg): self.sent.append(msg) - def request(self, msg, timeout=5.0): + def request(self, msg, timeout=5.0, match=None): self.sent.append(msg) + self.last_match = match return self.canned.get(type(msg).__name__) def next_request_id(self): @@ -695,6 +696,38 @@ def test_move_preset_serializes_the_captured_field_order_and_flags(): # -- session hello ------------------------------------------------------------- +def test_set_device_name_sends_a_sparse_version_update(): + qc = client.QuadCortex(FakeTransport()) + + qc.set_device_name("Stage QC") + + sent = qc._t.sent[-1] + assert isinstance(sent, pa.VersionMessage) + assert sent.SerializeToString() == b"\x08\x01\x7a\x08Stage QC" + + with pytest.raises(TypeError): + qc.set_device_name(None) + assert qc._t.sent[-1] is sent + + +def test_undo_and_redo_send_the_confirmed_sparse_updates(): + qc = client.QuadCortex(FakeTransport()) + + qc.undo() + undo = qc._t.sent[-1] + assert isinstance(undo, pa.UndoRedoMessage) + assert undo.SerializeToString() == b"\x08\x01\x28\x01" + assert undo.HasField("undo") + assert not undo.HasField("redo") + + qc.redo() + redo = qc._t.sent[-1] + assert isinstance(redo, pa.UndoRedoMessage) + assert redo.SerializeToString() == b"\x08\x01\x30\x01" + assert redo.HasField("redo") + assert not redo.HasField("undo") + + def test_hello_performs_full_connect_handshake(): canned = {"ResetCommsBuffersMessage": pa.ResetCommsBuffersMessage(session_id="ab")} qc = client.QuadCortex(FakeTransport(canned)) @@ -2319,6 +2352,23 @@ def test_settings_reads_general_settings_and_requires_a_full_push(): assert match(pa.GeneralSettingsMessage(screen_brightness=1)) is False +def test_inhibited_modules_reads_both_explicit_states(): + full = pa.CompilerInhibitedModulesMessage(action=pa.MessageAction.UPDATE, + global_gate=False, + global_eq=False) + qc = client.QuadCortex(StateTransport(full)) + got = qc.inhibited_modules() + assert got is full + sent = qc._t.sent[-1] + assert isinstance(sent, pa.CompilerInhibitedModulesMessage) + assert sent.action == pa.MessageAction.READ + assert sent.SerializeToString() == b"\x08\x03" + match = qc._t.matches[-1] + assert match(full) is True + assert match(pa.CompilerInhibitedModulesMessage(global_gate=False)) is False + assert match(pa.CompilerInhibitedModulesMessage(global_eq=False)) is False + + def test_update_settings_sends_only_the_named_fields(): qc = client.QuadCortex(FakeTransport()) qc.update_settings(screen_brightness=60, swap_tempo_tuner_access=True) diff --git a/tests/test_device.py b/tests/test_device.py index 922453a6..acae557d 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -82,12 +82,14 @@ def __init__(self, canned, trailing=()): def send(self, msg): self.sent.append(msg) - def request(self, msg, timeout=5.0): + def request(self, msg, timeout=5.0, match=None): self.sent.append(msg) reply = self.canned[type(msg).__name__] for message in [reply] + self.trailing: for listener in list(self.listeners): listener(message) # listeners see a reply first (ADR-0009) + if match is not None and not match(reply): + raise TimeoutError(f"canned {type(reply).__name__} did not match") return reply def await_broadcast(self, expected_class, trigger, timeout=5.0, match=None): diff --git a/tests/test_docs.py b/tests/test_docs.py index e63f9229..3478c7bb 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -23,7 +23,7 @@ def test_code_fences_are_balanced(doc): """An odd fence count means a section is rendering inside a code block.""" if not doc.exists(): pytest.skip(f"{doc.name} not present") - opens = sum(1 for line in doc.read_text().splitlines() + opens = sum(1 for line in doc.read_text(encoding="utf-8").splitlines() if line.startswith("```")) assert opens % 2 == 0, ( f"{doc.name} has {opens} fence lines - one is unclosed, and everything " @@ -32,7 +32,7 @@ def test_code_fences_are_balanced(doc): def _api_table_rows() -> str: - text = (ROOT / "docs" / "api.md").read_text() + text = (ROOT / "docs" / "api.md").read_text(encoding="utf-8") section = text[text.index("## Method groups"):text.index("**Rows and columns")] return "\n".join(line for line in section.splitlines() if line.startswith("|")) # table rows only, not prose @@ -119,7 +119,7 @@ def _drop_before_blocks(snippet): def _python_snippets(path): """Every ```python fence in a .md, or every ``::`` block in a .py docstring.""" - text = path.read_text() + text = path.read_text(encoding="utf-8") if path.suffix == ".md": return [_drop_before_blocks(f) for f in re.findall(r"```python\n(.*?)```", text, re.DOTALL)] diff --git a/tests/test_hardware_gate.py b/tests/test_hardware_gate.py index 5469a0d1..32280b20 100644 --- a/tests/test_hardware_gate.py +++ b/tests/test_hardware_gate.py @@ -39,7 +39,7 @@ #: way. Recursive on purpose: the conftest hook filters on #: ``path.is_relative_to(SUITE)``, so it gates a module in a subdirectory too, and #: a flat glob here would quietly stop covering what the hook covers. -MODULES = sorted(str(path.relative_to(ROOT)) +MODULES = sorted(path.relative_to(ROOT).as_posix() for path in SUITE.rglob("test_*.py")) diff --git a/tests/test_hardware_markers.py b/tests/test_hardware_markers.py index cfbc5a6f..2792fbbd 100644 --- a/tests/test_hardware_markers.py +++ b/tests/test_hardware_markers.py @@ -22,19 +22,19 @@ "io_settings": "the input gain tests read it back as their instrument; nothing asserts the port listing against what the unit shows", "preset_dirty": "test_model_state.py calls it only to decide which branch to expect; nothing asserts the flag across a known-clean and known-dirty preset", "settings": "the global-settings echo test reads it only to find the value to flip; nothing asserts a settings() field against the unit's screen", - "list_presets": "read by the scratch_preset fixture, which no test uses yet; no test asserts on the listing itself", + "list_presets": "the undo/redo test's scratch_preset fixture uses it to find a free slot; no test asserts the listing itself against the unit's Directory", # -- the preset library: writes that would touch the owner's own presets --- # The scratch_preset fixture is what these would be built on - it saves a # copy into a free User slot and deletes it again - but no test uses it yet. - "save_current_preset": "no hardware test yet; scratch_preset is the fixture for one, and it must save into a free User slot rather than over the owner's work", + "save_current_preset": "the undo/redo test's scratch_preset fixture confirms a save into a free User slot, but the test verifies undo/redo rather than the save wire shape", "recall_preset": "no hardware test yet; a recall discards the loaded preset's unsaved edits, so it needs scratch_preset around it", - "delete_preset": "no hardware test yet; only scratch_preset's teardown deletes anything, and a teardown asserts nothing", + "delete_preset": "the undo/redo test's scratch_preset teardown deletes its copy and confirms absence; no test isolates the delete wire shape itself", "copy_preset": "no hardware test yet; it writes into a second setlist, so a failed run leaves a stray preset in the owner's Directory", "move_preset": "no hardware test yet; it rearranges the slots a player has laid out for a gig, which a restore cannot make invisible mid-run", - "read_preset": "no hardware test yet; it RECALLS the preset it reads, so it is a write in disguise and needs scratch_preset", + "read_preset": "the undo/redo test reads its scratch copy to choose an edit, but verifies the history result rather than the read operation itself", "find_preset": "no hardware test yet; it needs a name that exists on the unit, which the loaded preset supplies - just not written", - "wait_for_listing": "no hardware test yet; it is the polling wrapper round list_presets and says nothing until a write changes a listing", + "wait_for_listing": "scratch_preset teardown uses it to confirm deletion; no test independently verifies its polling and stability contract", "create_setlist": "no hardware test yet; it adds a folder to the owner's Directory that a failed run would leave behind", "delete_setlist": "no hardware test yet; it deletes a folder and everything in it, which is the one preset-library mistake nothing can undo", "duplicate_setlist": "no hardware test yet; it copies a whole setlist preset by preset, so a failed run leaves a partial folder behind", @@ -48,7 +48,7 @@ "favorites": "no hardware test yet; the FAVORITES list is the owner's and may be empty, so a test can only assert the shape", "recents": "no hardware test yet; RECENTS changes with every recall, so a test can only assert the shape", "pinned_models": "no hardware test yet; which models are pinned is the owner's choice, so a test can only assert the shape", - "loaded_position": "no hardware test yet; scratch_preset reads it, and asserting it needs a recall to a slot the test chose", + "loaded_position": "scratch_preset records it so teardown can return to the starting slot; no test independently verifies all fields against the unit", "read_current_preset_push": "no hardware test yet; it returns the RecallPreset wrapper round the same payload read_current_preset returns", "mode": "no hardware test yet; which footswitch mode slots exist is the owner's configuration", "mode_cycle": "no hardware test yet; the cycle order is the owner's configuration, so a test can only assert the shape", diff --git a/tests/test_namespace.py b/tests/test_namespace.py index 543521a0..23abde02 100644 --- a/tests/test_namespace.py +++ b/tests/test_namespace.py @@ -81,7 +81,11 @@ def test_the_pre_flip_snapshot_is_byte_for_byte_what_0_40_0_shipped(): drops a name is to delete that name from here. Pinning the hash means the fixture and the export list can only be changed together and on purpose. """ - digest = hashlib.sha256(PRE_FLIP_INIT.read_bytes()).hexdigest() + # .gitattributes pins fresh checkouts to LF. Normalize defensively for a + # worktree created before that rule existed, then keep every content byte + # under the hash. + content = PRE_FLIP_INIT.read_bytes().replace(b"\r\n", b"\n") + digest = hashlib.sha256(content).hexdigest() assert digest == PRE_FLIP_INIT_SHA256, ( f"{PRE_FLIP_INIT.name} no longer matches " f"`git show 94e5053:pyquadcortex/__init__.py`. If the snapshot really " diff --git a/tests/test_profiles.py b/tests/test_profiles.py index f5895c90..98ef98d5 100644 --- a/tests/test_profiles.py +++ b/tests/test_profiles.py @@ -253,13 +253,13 @@ def test_the_4_1_profile_exposes_only_operations_with_contributed_evidence(): assert issubclass(cls, client.QuadCortex) assert cls.MEASURED_ON == ("4.1.0",) assert cls.EVIDENCE is support.Evidence.CONTRIBUTED - assert cls.VERIFIED == frozenset({"create_local_backup"}) + assert cls.VERIFIED == frozenset({"create_local_backup", "set_device_name"}) assert cls.CC_VERSION == "4.0.1", "inherited: the contributor's runs announced 4.0.1" assert isinstance(cls.models, support.NoSnapshot) with pytest.raises(AttributeError, match="coros_4_1_0"): cls.models.Delay assert cls(FakeTransport()).unverified_operations == ( - client.QuadCortex.operations() - {"create_local_backup"} + client.QuadCortex.operations() - {"create_local_backup", "set_device_name"} ) diff --git a/tests/test_session.py b/tests/test_session.py index 9c4bee4a..7f947652 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -506,7 +506,7 @@ def test_connect_hands_back_the_4_1_class_for_a_4_1_unit(fake_stack): qc = session.connect() assert type(qc) is profiles.QuadCortex41 assert qc.unverified_operations == ( - client.QuadCortex.operations() - {"create_local_backup"} + client.QuadCortex.operations() - profiles.QuadCortex41.VERIFIED ) with pytest.raises(errors.ControlNotDrivable): qc.switch_scene(1) diff --git a/tests/test_state.py b/tests/test_state.py index bd6a201d..12e3526c 100644 --- a/tests/test_state.py +++ b/tests/test_state.py @@ -114,7 +114,7 @@ def await_broadcast(self, message_class, trigger, timeout=5.0, match=None): self.push(reply) return reply - def request(self, message, timeout=5.0): + def request(self, message, timeout=5.0, match=None): name = type(message).__name__ self.sent.append(message) self.reads[name] += 1 @@ -126,6 +126,8 @@ def request(self, message, timeout=5.0): if callable(reply): reply = reply() self.push(reply) # every listener sees it first... + if match is not None and not match(reply): + raise TimeoutError(f"the canned {name} did not satisfy the waiter") return reply # ...and only then does the caller wake # -- the unit's side ------------------------------------------------------ @@ -1245,15 +1247,18 @@ def test_a_write_through_a_closed_cache_is_refused(link): def test_the_watchdog_does_not_outlive_the_connection(link): transport, cache = link + # The full offline + hardware run can have another live cache watchdog. + existing = set(_watchdog_threads()) cache.write_through("dirty", {"is_dirty": True}, send=lambda: None, patience=30.0) - assert _watchdog_threads(), "no watchdog was started, so this proves nothing" + started = set(_watchdog_threads()) - existing + assert started, "no watchdog was started, so this proves nothing" cache.close() deadline = time.monotonic() + 5.0 while time.monotonic() < deadline: - if not _watchdog_threads(): + if not (set(_watchdog_threads()) - existing): return time.sleep(0.02) pytest.fail("the write watchdog is still running after close()") @@ -1286,11 +1291,14 @@ def test_a_write_that_races_the_close_leaves_no_thread_behind(link): watchdog starting its thread. A thread started there waits forever on a connection nobody can reach.""" transport, cache = link + existing = set(_watchdog_threads()) cache.close() cache._watchdog.add(_a_watch_for_the_race()) - assert not _watchdog_threads() + # A watchdog from another test may finish during a combined offline + + # hardware run; the invariant is that this operation starts no NEW thread. + assert set(_watchdog_threads()) <= existing def _a_watch_for_the_race(): @@ -1311,9 +1319,12 @@ def test_the_watchdog_firing_as_the_connection_closes_does_not_raise(link): def test_no_watchdog_runs_until_something_is_written(link): transport, cache = link + # Baseline other live caches in a combined offline + hardware run. Some may + # finish during this test; only a newly-created watchdog would be a failure. + existing = set(_watchdog_threads()) cache.value("identity", "app_fw_version") transport.push(dirty_push(True)) - assert not _watchdog_threads() + assert set(_watchdog_threads()) <= existing def _watchdog_threads(): diff --git a/tests/test_values.py b/tests/test_values.py index 378476c9..633563d1 100644 --- a/tests/test_values.py +++ b/tests/test_values.py @@ -223,7 +223,8 @@ def test_a_floor_is_typed_whether_it_was_measured_or_derived(): def _generated_constants(): return [m for m in (CONSTANT.match(line) - for line in PARAMS_PY.read_text().splitlines()) if m] + for line in PARAMS_PY.read_text( + encoding="utf-8").splitlines()) if m] def _spellings_the_device_publishes(): diff --git a/tests/test_writing.py b/tests/test_writing.py index ace0a876..87a3563f 100644 --- a/tests/test_writing.py +++ b/tests/test_writing.py @@ -41,7 +41,7 @@ def governed_documents(): def _ids(path): - return str(path.relative_to(ROOT)) + return path.relative_to(ROOT).as_posix() def _governed_text(path):