From 8d6df2a4b538fa691e8c2fca96336e1a17df2daa Mon Sep 17 00:00:00 2001 From: Antoni Ivanov <262547018+tony-xmelon@users.noreply.github.com> Date: Fri, 11 Sep 2026 13:19:58 +0300 Subject: [PATCH 1/7] Use firmware setlist duplication --- docs/api.md | 2 +- docs/manual-coverage.md | 2 +- docs/protocol.md | 24 +++---- pyquadcortex/protocol/client.py | 119 ++++++++++++++++++++++++-------- tests/test_client.py | 75 ++++++++++++++++++++ tests/test_hardware_markers.py | 2 +- 6 files changed, 181 insertions(+), 43 deletions(-) diff --git a/docs/api.md b/docs/api.md index c34a0ce4..d46765a4 100644 --- a/docs/api.md +++ b/docs/api.md @@ -70,7 +70,7 @@ already read and need no connection; calling them as methods raises | **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`) | | **List parameters** | `set_param_option(cell, param, option, source)`, `protocol.param_options(preset, ...)` - includes a block's side-chain SOURCE | -| **Setlists** | `create_setlist(name)`, `delete_setlist(name)`, `duplicate_setlist(src, dest)`, `list_folders()` | +| **Setlists** | `create_setlist(name)`, `delete_setlist(name)`, `duplicate_setlist(source)`, `list_folders()`; duplication is one firmware-side COPY and the device chooses the destination name | | **Copying** | `copy_preset(from_setlist, position, to_setlist)` - recall + save, so it loads each source | | **Device list** | `pin_model()`, `unpin_model()`, `pinned_models()`, `master_volume()` | | **Neural Captures** | `captures()`, `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 | diff --git a/docs/manual-coverage.md b/docs/manual-coverage.md index 97d4fc80..3ca6e3ba 100644 --- a/docs/manual-coverage.md +++ b/docs/manual-coverage.md @@ -133,7 +133,7 @@ which this document had over-read as unreachable, and it answers a READ perfectl | User folders / additional setlists | yes | `create_setlist()` makes them and `list_folders()` finds them; `list_presets()` accepts any key. CC#32's 'User folders' 2-12 are created, not built in | | Create a folder, nested navigation | yes | `create_setlist(name)`. The earlier failure was the path: setlists are siblings under `/media/p4/Presets`, not children of My Presets | | Favorites and Recents | yes | `recents()` and `favorites()` read the two lists - the request's `is_favorites` flag selects which, though the REPLY never sets it, so correlate on `request_id`. `add_favorite()`/`remove_favorite()` write, one entry at a time, confirmed by the device's echo of the changed entry. Entries feed straight into `find_preset()`/`recall_preset()`. Only presets can be favourited | -| Bulk actions | partly | there is no host-drivable bulk copy - `BulkOperation` only narrates progress - but `copy_preset()` and `duplicate_setlist()` achieve it by recall + save, at a few seconds per preset | +| Bulk actions | yes | `duplicate_setlist()` sends Cortex Control's single firmware-side folder COPY, then verifies the asynchronously created destination without replaying the write; `BulkOperation` only narrates progress | | Search | no | candidate `RecentSearches` | | Sort | n/a | client-side once a listing is in hand | | Neural Captures: list | yes | `captures()` browses the library - over 2000 entries, shown on the unit as Factory Captures V1/V2 and My Captures. NOT the catalog, which does not grow when a capture is saved | diff --git a/docs/protocol.md b/docs/protocol.md index cbe3b806..54f29241 100644 --- a/docs/protocol.md +++ b/docs/protocol.md @@ -2435,19 +2435,17 @@ not fixed setlists. setlist's own key - the folder leaves the listing, subject to the usual eventual consistency. -**There is no host-drivable copy, and none is needed.** The unit's duplicate action -sends a `File` CREATE for the destination and then narrates itself through -`BulkOperation` - `"Duplicating, please wait."`, a progress fraction, then `finished` - -and doing the same from the host creates an EMPTY destination. Everything in that window -is the device REPORTING, not a command. - -The unit's per-preset copy/paste gives the way in: pasting broadcasts -`File{CREATE, folder{key, files{key, index, name, ...}}}`, which is the same shape as a -Save As pointed at a different folder. And a save DOES accept any folder key (confirmed: -recalling a factory preset and saving it into `/media/p4/Presets/probe` put it there). So -copying a preset is recall-then-save, and duplicating a setlist is that per preset - -which is what `copy_preset()` and `duplicate_setlist()` do. The cost is inherent: each -one recalls the source on the unit. +**Setlist duplication is one host-drivable folder COPY.** Cortex Control sends +`File{COPY, type: 0, folder{key: , is_factory: false}}` with no destination +folder, name, index, or per-preset entries. Firmware chooses the collision-safe +destination identity and performs the copy asynchronously. `BulkOperation` only +narrates progress; it is not the command. + +The destination can remain visibly empty for more than 45 seconds and later publish +the complete source inventory without a second write. `duplicate_setlist()` therefore +takes a fresh catalog baseline, sends COPY exactly once, and uses read-only polling to +verify that exactly one new folder eventually matches every occupied source position, +name, and instrument. A timeout never replays COPY or falls back to recall-and-save. ### 7.7b3 Looper X, master volume, pinning, and the Global EQ diff --git a/pyquadcortex/protocol/client.py b/pyquadcortex/protocol/client.py index 4e9e102d..996d997f 100644 --- a/pyquadcortex/protocol/client.py +++ b/pyquadcortex/protocol/client.py @@ -3448,36 +3448,82 @@ def copy_preset(self, from_setlist: str, position, to_setlist: str, name or source_name or "copy", instrument=instrument, confirm=True) - def duplicate_setlist(self, source_name: str, dest_name: str, - limit: int | None = None): - """Copy a whole setlist into a new one, preset by preset. - - Also a composition rather than a device operation. The unit's own - duplicate action broadcasts a ``BulkOperation`` narrating its progress - - ``"Duplicating, please wait."``, then a progress fraction, then - ``finished`` - but that is the device REPORTING: replaying it copies - nothing, and no host-drivable duplicate exists. So this creates the - destination and copies each preset with :meth:`copy_preset`. - - Which means it is SLOW - a recall and a save per preset, several seconds - each - and it recalls every one of them on the unit as it goes. ``limit`` - caps how many are copied, for trying it out on a large setlist. - - Returns the list of names stored in the destination. + def duplicate_setlist(self, source_name: str, *, confirm: bool = True, + timeout: float | None = None, + interval: float = 2.0): + """Ask firmware to duplicate a complete user setlist exactly once. + + Cortex Control sends one sparse ``File{COPY}`` containing only the + source folder key and explicit ``is_factory: false``. Firmware chooses + the collision-safe destination name and key and copies the inventory + asynchronously; no destination identity or per-preset writes belong on + the wire. + + With ``confirm=True`` (the default), this takes a fresh folder and source + inventory baseline before the write, then performs read-only polling + until exactly one new folder has the source's complete + position/name/instrument inventory. The COPY is never replayed. Firmware + has taken more than 80 seconds for 74 presets, so the default deadline is + ``90 + 2 * occupied_presets`` seconds, capped at ten minutes. + + Returns the device-created :class:`Folder` when confirmed. With + ``confirm=False``, returns the immediate File reply if one arrives, + otherwise ``None``; that mode does not prove completion. """ - dest_key = self.create_setlist(dest_name) - time.sleep(3.0) source_key = (source_name if source_name.startswith("/") else f"{USER_SETLIST_ROOT}/{source_name}") - entries = self.list_presets(source_key) - if limit is not None: - entries = entries[:limit] - stored = [] - for i, entry in enumerate(entries): - stored.append(self.copy_preset(source_key, entry.index, dest_key, - to_position=i, name=entry.name, - instrument=entry.instrument)) - return stored + if confirm: + before = self.list_folders() + source = self.list_presets(source_key) + before_keys = {folder.key for folder in before} + if source_key not in before_keys: + raise ValueError(f"source setlist {source_key!r} is not in the fresh catalog") + custom_setlists = [ + folder for folder in before + if _is_user_setlist_key(folder.key) + and folder.key != str(Setlist.USER) + ] + if len(custom_setlists) >= 12: + raise ValueError("the device already has the maximum 12 user setlists") + expected = _preset_inventory(source) + if timeout is None: + timeout = min(600.0, 90.0 + 2.0 * len(expected)) + + msg = pa.FileMessage(action=pa.MessageAction.COPY, type=0) + msg.folder.key = source_key + msg.folder.is_factory = False + reply = self._file_operation(msg) + if not confirm: + return reply + + deadline = time.monotonic() + timeout + while True: + remaining = max(0.1, deadline - time.monotonic()) + folders = self.list_folders(seconds=min(20.0, remaining)) + created = [ + folder for folder in folders + if folder.key not in before_keys + and _is_user_setlist_key(folder.key) + ] + if len(created) > 1: + raise RuntimeError( + "more than one folder appeared during duplicate verification; " + "the device-created destination is ambiguous" + ) + if created: + destination = created[0] + try: + actual = _preset_inventory(self.list_presets(destination.key)) + except TimeoutError: + actual = None + if actual == expected: + return destination + if time.monotonic() >= deadline: + raise TimeoutError( + f"setlist COPY was sent once but did not publish a complete " + f"matching destination within {timeout}s; it was not replayed" + ) + time.sleep(interval) #: How many parameters each Global EQ band occupies, and the offset of each #: control within a band. See :meth:`set_global_eq`. @@ -4024,6 +4070,25 @@ def field_present(message, field: str) -> bool: return False +def _preset_inventory(entries) -> tuple: + """Stable occupied-inventory identity used for setlist COPY verification.""" + return tuple(sorted( + ( + entry.index, + entry.name, + entry.instrument if field_present(entry, "instrument") else 0, + ) + for entry in entries + if field_present(entry, "key") and entry.key + )) + + +def _is_user_setlist_key(key: str) -> bool: + """Whether ``key`` is a direct setlist child of the user preset root.""" + prefix = f"{USER_SETLIST_ROOT}/" + return key.startswith(prefix) and "/" not in key[len(prefix):] + + def blocks(p: preset.BinaryPreset) -> list: """The OCCUPIED grid cells of ``p``, as :class:`Block` entries. diff --git a/tests/test_client.py b/tests/test_client.py index daa43778..d723a442 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -2987,6 +2987,81 @@ def test_copy_preset_does_recall_the_source_which_changes_the_grid(): assert any(isinstance(m, pa.SetlistPositionMessage) for m in qc._t.sent) +def test_duplicate_setlist_sends_the_exact_cortex_folder_copy(): + qc = client.QuadCortex(FakeTransport()) + qc.duplicate_setlist("Live", confirm=False) + sent = qc._t.sent[-1] + assert sent.SerializeToString() == bytes.fromhex( + "08 05 18 00 22 1a 0a 16 2f 6d 65 64 69 61 2f 70 34 2f 50 72 65 73 " + "65 74 73 2f 4c 69 76 65 20 00" + ) + assert not sent.HasField("request_id") # Transport.request assigns it later. + assert not sent.HasField("to_folder") + assert len(sent.folder.files) == 0 + + +def test_duplicate_setlist_sends_once_and_waits_for_matching_inventory(monkeypatch): + root = "/media/p4/Presets" + source_key = f"{root}/Live" + destination_key = f"{root}/Live 2" + before = [client.Folder(source_key, "Live", 256, 2, False)] + after = before + [client.Folder(destination_key, "Live 2", 256, 2, False)] + + source = [] + destination_incomplete = [] + destination_complete = [] + for collection in (source, destination_complete): + first = pa.ProductData(index=1, name="One", key="key-one", instrument=1) + second = pa.ProductData(index=7, name="Two", key="key-two", instrument=2) + collection.extend((first, second)) + destination_incomplete.append(source[0]) + + fake = FakeTransport() + qc = client.QuadCortex(fake) + folder_generations = iter((before, after, after)) + destination_generations = iter((destination_incomplete, destination_complete)) + qc.list_folders = lambda seconds=20.0: next(folder_generations) + + def list_presets(key, *args, **kwargs): + if key == source_key: + return source + assert key == destination_key + return next(destination_generations) + + qc.list_presets = list_presets + monkeypatch.setattr(client.time, "sleep", lambda seconds: None) + + created = qc.duplicate_setlist("Live", timeout=5.0, interval=0.0) + + assert created.key == destination_key + copies = [ + message for message in fake.sent + if isinstance(message, pa.FileMessage) + and message.action == pa.MessageAction.COPY + ] + assert len(copies) == 1, "polling must never replay a persistent COPY" + + +def test_duplicate_setlist_refuses_at_the_cortex_twelve_setlist_guard(): + root = "/media/p4/Presets" + source_key = f"{root}/Live" + folders = [client.Folder(source_key, "Live", 256, 1, False)] + folders.extend( + client.Folder(f"{root}/Setlist {index}", f"Setlist {index}", 256, 0, False) + for index in range(1, 12) + ) + fake = FakeTransport() + qc = client.QuadCortex(fake) + qc.list_folders = lambda seconds=20.0: folders + qc.list_presets = lambda key: [ + pa.ProductData(index=0, name="One", key="key-one", instrument=1) + ] + + with pytest.raises(ValueError, match="maximum 12"): + qc.duplicate_setlist("Live") + assert fake.sent == [] + + # -- Global EQ by band, not by wire index -------------------------------------- # 5 parameters per band at offsets GAIN 0, FREQUENCY 1, Q 2, TYPE 3. Established by # changing each of band 1's controls and seeing which index moved, then checked diff --git a/tests/test_hardware_markers.py b/tests/test_hardware_markers.py index cfbc5a6f..cbc471e8 100644 --- a/tests/test_hardware_markers.py +++ b/tests/test_hardware_markers.py @@ -37,7 +37,7 @@ "wait_for_listing": "no hardware test yet; it is the polling wrapper round list_presets and says nothing until a write changes a listing", "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", + "duplicate_setlist": "no Python same-commit hardware test yet; firmware creates a new folder asynchronously, so a disposable source and separately authorized cleanup are required", # -- library listings whose CONTENT belongs to the owner ------------------- # Each returns whatever this unit happens to hold, so a test can assert the From 2d70432a45d8ce651d3f3d9a644d8955cd2d272a Mon Sep 17 00:00:00 2001 From: Antoni Ivanov <262547018+tony-xmelon@users.noreply.github.com> Date: Fri, 11 Sep 2026 14:26:26 +0300 Subject: [PATCH 2/7] Harden duplicate setlist listing verification --- docs/protocol.md | 8 ++++ pyquadcortex/protocol/client.py | 82 ++++++++++++++++++++++++++++----- tests/test_client.py | 64 +++++++++++++++++++------ tests/test_hardware_markers.py | 2 +- 4 files changed, 130 insertions(+), 26 deletions(-) diff --git a/docs/protocol.md b/docs/protocol.md index 54f29241..a22a43fb 100644 --- a/docs/protocol.md +++ b/docs/protocol.md @@ -2447,6 +2447,14 @@ takes a fresh catalog baseline, sends COPY exactly once, and uses read-only poll verify that exactly one new folder eventually matches every occupied source position, name, and instrument. A timeout never replays COPY or falls back to recall-and-save. +On 2026-09-11 a contributed CorOS 4.1.0 run sent that sparse COPY once against a +disposable two-preset setlist. Firmware created its collision-named destination and +published the matching position/name/instrument inventory 49.878 seconds later. The +same mutation campaign also observed one-slot and transient blank `File` broadcasts +before later 256-slot user-setlist listings. A matching short generation is therefore +not completion evidence: duplication stabilizes two identical generations, each with +every slot index 0 through 255, for both its source baseline and destination proof. + ### 7.7b3 Looper X, master volume, pinning, and the Global EQ **Looper X state.** `LooperStatus.state` was mapped by watching each transport diff --git a/pyquadcortex/protocol/client.py b/pyquadcortex/protocol/client.py index 996d997f..7bddbf9c 100644 --- a/pyquadcortex/protocol/client.py +++ b/pyquadcortex/protocol/client.py @@ -735,12 +735,15 @@ def list_presets(self, setlist: str = Setlist.USER, timeout: float = 25.0, device push a folder listing per setlist, so this sends that READ and waits for the listing whose key matches ``setlist``. - A listing that arrives is COMPLETE - five READs against an 18-preset setlist - each produced a full listing, and no short one has been observed. But a READ - does not reliably produce one promptly: two of those five saw nothing for - that setlist within 8 s, delivery being lazy. So treat a timeout as "ask - again", which is what :meth:`wait_for_listing` does, rather than as an - answer about the setlist's contents. + A READ does not reliably produce one promptly: two of five early checks saw + nothing for the requested setlist within 8 s, delivery being lazy. Later + CorOS 4.1.0 mutation testing also observed one-slot partial broadcasts before + the eventual 256-slot user-setlist listing. This method returns the first + matching non-empty broadcast, so a workflow that needs an authoritative + user-setlist inventory must require and stabilize all 256 slot indices, as + :meth:`duplicate_setlist` does. Treat a timeout as "ask again", which is + what :meth:`wait_for_listing` does, rather than as an answer about the + setlist's contents. Note the trailing-slash asymmetry the match has to absorb: recalls need the factory path WITH its trailing slash (Cortex Control sends it that @@ -3464,7 +3467,11 @@ def duplicate_setlist(self, source_name: str, *, confirm: bool = True, until exactly one new folder has the source's complete position/name/instrument inventory. The COPY is never replayed. Firmware has taken more than 80 seconds for 74 presets, so the default deadline is - ``90 + 2 * occupied_presets`` seconds, capped at ten minutes. + ``90 + 2 * occupied_presets`` seconds, capped at ten minutes. A 2026-09-11 + CorOS 4.1.0 run confirmed a disposable two-preset copy in 49.878 seconds. + That run also received partial ``File`` broadcasts before complete ones, + so both inventories require two identical generations containing every + user-setlist slot index before they are trusted. Returns the device-created :class:`Folder` when confirmed. With ``confirm=False``, returns the immediate File reply if one arrives, @@ -3474,7 +3481,6 @@ def duplicate_setlist(self, source_name: str, *, confirm: bool = True, else f"{USER_SETLIST_ROOT}/{source_name}") if confirm: before = self.list_folders() - source = self.list_presets(source_key) before_keys = {folder.key for folder in before} if source_key not in before_keys: raise ValueError(f"source setlist {source_key!r} is not in the fresh catalog") @@ -3485,7 +3491,9 @@ def duplicate_setlist(self, source_name: str, *, confirm: bool = True, ] if len(custom_setlists) >= 12: raise ValueError("the device already has the maximum 12 user setlists") - expected = _preset_inventory(source) + expected = self._stable_complete_user_setlist( + source_key, timeout=120.0, interval=interval + ) if timeout is None: timeout = min(600.0, 90.0 + 2.0 * len(expected)) @@ -3496,7 +3504,9 @@ def duplicate_setlist(self, source_name: str, *, confirm: bool = True, if not confirm: return reply + assert timeout is not None deadline = time.monotonic() + timeout + previous_destination = None while True: remaining = max(0.1, deadline - time.monotonic()) folders = self.list_folders(seconds=min(20.0, remaining)) @@ -3513,11 +3523,20 @@ def duplicate_setlist(self, source_name: str, *, confirm: bool = True, if created: destination = created[0] try: - actual = _preset_inventory(self.list_presets(destination.key)) + listing = self.list_presets( + destination.key, + timeout=min(25.0, remaining), + include_empty=True, + ) except TimeoutError: - actual = None + listing = [] + actual = _complete_user_setlist_inventory(listing) if actual == expected: - return destination + if previous_destination == actual: + return destination + previous_destination = actual + else: + previous_destination = None if time.monotonic() >= deadline: raise TimeoutError( f"setlist COPY was sent once but did not publish a complete " @@ -3525,6 +3544,37 @@ def duplicate_setlist(self, source_name: str, *, confirm: bool = True, ) time.sleep(interval) + def _stable_complete_user_setlist(self, key: str, *, timeout: float, + interval: float) -> tuple: + """Return two identical complete 256-slot generations for ``key``.""" + deadline = time.monotonic() + timeout + previous = None + listings_seen = 0 + while True: + remaining = max(0.1, deadline - time.monotonic()) + try: + listing = self.list_presets( + key, + timeout=min(25.0, remaining), + include_empty=True, + ) + except TimeoutError: + listing = [] + actual = _complete_user_setlist_inventory(listing) + if actual is not None: + listings_seen += 1 + if previous == actual: + return actual + previous = actual + else: + previous = None + if time.monotonic() >= deadline: + raise TimeoutError( + f"no stable complete 256-slot listing arrived for {key!r} " + f"within {timeout}s ({listings_seen} complete generation(s) seen)" + ) + time.sleep(interval) + #: How many parameters each Global EQ band occupies, and the offset of each #: control within a band. See :meth:`set_global_eq`. GLOBAL_EQ_BAND_STRIDE = 5 @@ -4083,6 +4133,14 @@ def _preset_inventory(entries) -> tuple: )) +def _complete_user_setlist_inventory(entries) -> tuple | None: + """Occupied identity only when a user-setlist generation has all 256 slots.""" + positions = [entry.index for entry in entries if field_present(entry, "index")] + if len(entries) != 256 or set(positions) != set(range(256)): + return None + return _preset_inventory(entries) + + def _is_user_setlist_key(key: str) -> bool: """Whether ``key`` is a direct setlist child of the user preset root.""" prefix = f"{USER_SETLIST_ROOT}/" diff --git a/tests/test_client.py b/tests/test_client.py index d723a442..f60758ce 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -3007,24 +3007,36 @@ def test_duplicate_setlist_sends_once_and_waits_for_matching_inventory(monkeypat before = [client.Folder(source_key, "Live", 256, 2, False)] after = before + [client.Folder(destination_key, "Live 2", 256, 2, False)] - source = [] - destination_incomplete = [] - destination_complete = [] - for collection in (source, destination_complete): - first = pa.ProductData(index=1, name="One", key="key-one", instrument=1) - second = pa.ProductData(index=7, name="Two", key="key-two", instrument=2) - collection.extend((first, second)) - destination_incomplete.append(source[0]) + def complete(first_name="One", second_name="Two"): + entries = [pa.ProductData(index=index) for index in range(256)] + entries[1].name = first_name + entries[1].key = "key-one" + entries[1].instrument = 1 + entries[7].name = second_name + entries[7].key = "key-two" + entries[7].instrument = 2 + return entries + + source = complete() + destination_partial = [source[1]] + destination_wrong = complete(second_name="Still copying") + destination_complete = complete() fake = FakeTransport() qc = client.QuadCortex(fake) - folder_generations = iter((before, after, after)) - destination_generations = iter((destination_incomplete, destination_complete)) + folder_generations = iter((before, after, after, after, after)) + source_generations = iter((source, source)) + destination_generations = iter(( + destination_partial, + destination_wrong, + destination_complete, + destination_complete, + )) qc.list_folders = lambda seconds=20.0: next(folder_generations) def list_presets(key, *args, **kwargs): if key == source_key: - return source + return next(source_generations) assert key == destination_key return next(destination_generations) @@ -3042,6 +3054,32 @@ def list_presets(key, *args, **kwargs): assert len(copies) == 1, "polling must never replay a persistent COPY" +def test_duplicate_setlist_never_baselines_a_partial_source_listing(monkeypatch): + root = "/media/p4/Presets" + source_key = f"{root}/Live" + folders = [client.Folder(source_key, "Live", 256, 1, False)] + partial = [pa.ProductData(index=0, name="Only", key="one", instrument=1)] + complete = [pa.ProductData(index=index) for index in range(256)] + complete[0].name = "Only" + complete[0].key = "one" + complete[0].instrument = 1 + + fake = FakeTransport() + qc = client.QuadCortex(fake) + qc.list_folders = lambda seconds=20.0: folders + generations = iter((partial, complete, complete)) + qc.list_presets = lambda *args, **kwargs: next(generations) + monkeypatch.setattr(client.time, "sleep", lambda seconds: None) + + # Exercise the authoritative preflight directly so the test cannot create a + # persistent COPY merely to prove that a partial generation was rejected. + inventory = qc._stable_complete_user_setlist( + source_key, timeout=5.0, interval=0.0 + ) + assert inventory == ((0, "Only", 1),) + assert fake.sent == [] + + def test_duplicate_setlist_refuses_at_the_cortex_twelve_setlist_guard(): root = "/media/p4/Presets" source_key = f"{root}/Live" @@ -3053,8 +3091,8 @@ def test_duplicate_setlist_refuses_at_the_cortex_twelve_setlist_guard(): fake = FakeTransport() qc = client.QuadCortex(fake) qc.list_folders = lambda seconds=20.0: folders - qc.list_presets = lambda key: [ - pa.ProductData(index=0, name="One", key="key-one", instrument=1) + qc.list_presets = lambda key, **kwargs: [ + pa.ProductData(index=index) for index in range(256) ] with pytest.raises(ValueError, match="maximum 12"): diff --git a/tests/test_hardware_markers.py b/tests/test_hardware_markers.py index cbc471e8..a4f8fd0b 100644 --- a/tests/test_hardware_markers.py +++ b/tests/test_hardware_markers.py @@ -37,7 +37,7 @@ "wait_for_listing": "no hardware test yet; it is the polling wrapper round list_presets and says nothing until a write changes a listing", "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 Python same-commit hardware test yet; firmware creates a new folder asynchronously, so a disposable source and separately authorized cleanup are required", + "duplicate_setlist": "same-commit CorOS 4.1.0 corroboration exists outside the pytest hardware suite; add a state-neutral suite test before removing this marker", # -- library listings whose CONTENT belongs to the owner ------------------- # Each returns whatever this unit happens to hold, so a test can assert the From ed52166354e04bd9b9fd8fc3a0b31d4aa7b6603f Mon Sep 17 00:00:00 2001 From: Antoni Ivanov <262547018+tony-xmelon@users.noreply.github.com> Date: Fri, 11 Sep 2026 22:14:34 +0300 Subject: [PATCH 3/7] Scope native setlist copy to CorOS 4.1 --- changelog.md | 9 +++ docs/api.md | 2 +- docs/manual-coverage.md | 15 ++-- docs/protocol.md | 9 ++- pyquadcortex/protocol/client.py | 78 ++++++++++++++++---- pyquadcortex/protocol/profiles.py | 9 ++- tests/test_client.py | 119 +++++++++++++++++++++++++----- tests/test_hardware_markers.py | 2 +- tests/test_profiles.py | 6 +- 9 files changed, 202 insertions(+), 47 deletions(-) diff --git a/changelog.md b/changelog.md index d8b2b27f..57af12a3 100644 --- a/changelog.md +++ b/changelog.md @@ -20,6 +20,15 @@ correction. ## Unreleased +### CorOS 4.1 can duplicate a setlist with one firmware-side copy + +`QuadCortex41.duplicate_setlist()` sends the sparse folder COPY extracted from +Cortex Control 4.1 exactly once, then confirms the firmware-created destination +with stable folder generations and two identical complete 256-slot inventories. +A contributed CorOS 4.1.0 hardware run on 2026-09-11 confirmed a two-preset copy +in 49.878 seconds. The CorOS 4.0.1 base refuses this unmeasured command and points +callers to the older, measured `copy_preset()` recall-and-save composition. + ### The first hardware run of the profile seam, and what it corrected Run 2026-09-07 on Quad Cortex, CorOS 4.0.1 / d14e, straight after the seam diff --git a/docs/api.md b/docs/api.md index d46765a4..bc71fd57 100644 --- a/docs/api.md +++ b/docs/api.md @@ -70,7 +70,7 @@ already read and need no connection; calling them as methods raises | **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`) | | **List parameters** | `set_param_option(cell, param, option, source)`, `protocol.param_options(preset, ...)` - includes a block's side-chain SOURCE | -| **Setlists** | `create_setlist(name)`, `delete_setlist(name)`, `duplicate_setlist(source)`, `list_folders()`; duplication is one firmware-side COPY and the device chooses the destination name | +| **Setlists** | `create_setlist(name)`, `delete_setlist(name)`, `duplicate_setlist(source)`, `list_folders()`; on CorOS 4.1 duplication is one firmware-side COPY and the device chooses the destination name. The CorOS 4.0.1 profile refuses that unmeasured command and points to `copy_preset()` | | **Copying** | `copy_preset(from_setlist, position, to_setlist)` - recall + save, so it loads each source | | **Device list** | `pin_model()`, `unpin_model()`, `pinned_models()`, `master_volume()` | | **Neural Captures** | `captures()`, `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 | diff --git a/docs/manual-coverage.md b/docs/manual-coverage.md index 3ca6e3ba..3d803f22 100644 --- a/docs/manual-coverage.md +++ b/docs/manual-coverage.md @@ -20,10 +20,10 @@ or a field in `BinaryPreset`. A named candidate is a lead, not a claim that it w ## Summary -Of 105 features audited: **65 yes**, **8 partly**, **21 no**, **11 n/a**. +Of 105 features audited: **66 yes**, **7 partly**, **21 no**, **11 n/a**. Of the 93 features a host could plausibly drive - everything above except the 11 marked -n/a - **65 are fully covered** and 8 more are partly covered, which here means the state +n/a - **66 are fully covered** and 7 more are partly covered, which here means the state is readable and at least one field of it is confirmed writable, with the neighbours the same shape but not individually exercised. Only 20 remain untouched. @@ -39,10 +39,11 @@ reference pitch, creating a setlist, the expression-bypass numbering, the Looper the master volume scale, how pinning is written, the Global EQ's whole 28-index layout, every option of the metronome's four lists, and the per-beat accent cells. -What is left is of two kinds. A few writes are **confirmed no-ops** with no route found: -preset tags, and duplicating a setlist as a device operation (the library does it by -recall-and-save instead). And two whole features remain unexplored because they need the -physical world: Neural Capture, and loading from the factory Captures Library. +What is left is of two kinds. Preset tags are a **confirmed no-op** with no route +found. Two whole features remain unexplored because they need the physical world: +Neural Capture, and loading from the factory Captures Library. Firmware-native +setlist duplication is measured only on CorOS 4.1; 4.0.1 retains the explicit +recall-and-save composition instead of inheriting that wire command. The Tempo menu's MODE was the last feature with no wire path found. It closed on 2026-08-12: the device never broadcasts it, which three tests established correctly and @@ -133,7 +134,7 @@ which this document had over-read as unreachable, and it answers a READ perfectl | User folders / additional setlists | yes | `create_setlist()` makes them and `list_folders()` finds them; `list_presets()` accepts any key. CC#32's 'User folders' 2-12 are created, not built in | | Create a folder, nested navigation | yes | `create_setlist(name)`. The earlier failure was the path: setlists are siblings under `/media/p4/Presets`, not children of My Presets | | Favorites and Recents | yes | `recents()` and `favorites()` read the two lists - the request's `is_favorites` flag selects which, though the REPLY never sets it, so correlate on `request_id`. `add_favorite()`/`remove_favorite()` write, one entry at a time, confirmed by the device's echo of the changed entry. Entries feed straight into `find_preset()`/`recall_preset()`. Only presets can be favourited | -| Bulk actions | yes | `duplicate_setlist()` sends Cortex Control's single firmware-side folder COPY, then verifies the asynchronously created destination without replaying the write; `BulkOperation` only narrates progress | +| Bulk actions | yes | On the measured CorOS 4.1 profile, `duplicate_setlist()` sends Cortex Control's single firmware-side folder COPY, then verifies the asynchronously created destination without replaying the write; the CorOS 4.0.1 profile refuses and points to `copy_preset()`. `BulkOperation` only narrates progress | | Search | no | candidate `RecentSearches` | | Sort | n/a | client-side once a listing is in hand | | Neural Captures: list | yes | `captures()` browses the library - over 2000 entries, shown on the unit as Factory Captures V1/V2 and My Captures. NOT the catalog, which does not grow when a capture is saved | diff --git a/docs/protocol.md b/docs/protocol.md index a22a43fb..1ea66e3c 100644 --- a/docs/protocol.md +++ b/docs/protocol.md @@ -2435,7 +2435,13 @@ not fixed setlists. setlist's own key - the folder leaves the listing, subject to the usual eventual consistency. -**Setlist duplication is one host-drivable folder COPY.** Cortex Control sends +On CorOS 4.0.1, the unit's own duplicate action was captured sending a `File` +CREATE and narrating progress through `BulkOperation`; replaying that CREATE +from the host produced an empty destination. Separately, a save was confirmed +to accept any folder key, which is the measured basis of `copy_preset()`'s +recall-and-save fallback. No firmware-native COPY has been measured on 4.0.1. + +**On CorOS 4.1, setlist duplication is one host-drivable folder COPY.** Cortex Control sends `File{COPY, type: 0, folder{key: , is_factory: false}}` with no destination folder, name, index, or per-preset entries. Firmware chooses the collision-safe destination identity and performs the copy asynchronously. `BulkOperation` only @@ -2835,6 +2841,7 @@ screen; **captured only** = seen on the wire, with no independent read-back. | `pin_model` / `unpin_model` / `pinned_models` | `PinnedModels{models}` with NO action / `{DELETE, models}` | read-back + on-unit | pinning APPENDS and can duplicate; DELETE removes every entry for an id | | `delete_setlist` | `File{DELETE, folder{key, name}}` | read-back | removes the setlist and its contents | | `create_setlist` | `File{CREATE, folder{key: "/media/p4/Presets/", name}}` | read-back + on-unit | setlists are siblings under the presets root, not children of My Presets | +| `duplicate_setlist` (CorOS 4.1) | `File{COPY, folder{key: , is_factory: false}}` | Cortex Control 4.1 binary + contributed hardware read-back | sends once, then stabilizes folder and complete 256-slot preset listings; CorOS 4.0.1 refuses because this shape has not been measured there | | `set_split_mute` | `Grid{UPDATE, preset{chains{row, splitBypass{bypass}}}}` | read-back | the single splitter/mixer MUTE; reported back in `mixBypass`, and one write sets all eight scenes | | `set_stomp_assignment` | `Grid{DELETE, stomp_mode_assignments{row, column}}` then `Grid{UPDATE, ...{stomp_index}}` | read-back + on-unit | the unit's own two-message sequence; an UPDATE alone leaves the old assignment | | `set_stomp_momentary` | `Grid{UPDATE, preset{stomp_is_momentary{key, value}}}` | read-back + on-unit | keyed by footswitch, not column. **Only lands on a switch driving exactly one block** - the device refuses multi-block switches silently, as its own toggle does | diff --git a/pyquadcortex/protocol/client.py b/pyquadcortex/protocol/client.py index 7bddbf9c..9d6011fb 100644 --- a/pyquadcortex/protocol/client.py +++ b/pyquadcortex/protocol/client.py @@ -735,10 +735,10 @@ def list_presets(self, setlist: str = Setlist.USER, timeout: float = 25.0, device push a folder listing per setlist, so this sends that READ and waits for the listing whose key matches ``setlist``. - A READ does not reliably produce one promptly: two of five early checks saw - nothing for the requested setlist within 8 s, delivery being lazy. Later - CorOS 4.1.0 mutation testing also observed one-slot partial broadcasts before - the eventual 256-slot user-setlist listing. This method returns the first + On CorOS 4.0.1, five READs against an 18-preset setlist each produced a + complete listing, although two produced nothing within 8 s. A contributed + CorOS 4.1.0 run on 2026-09-11 also observed transient one-slot and blank + generations before the eventual 256-slot user-setlist listing. This returns the first matching non-empty broadcast, so a workflow that needs an authoritative user-setlist inventory must require and stabilize all 256 slot indices, as :meth:`duplicate_setlist` does. Treat a timeout as "ask again", which is @@ -3454,6 +3454,18 @@ def copy_preset(self, from_setlist: str, position, to_setlist: str, def duplicate_setlist(self, source_name: str, *, confirm: bool = True, timeout: float | None = None, interval: float = 2.0): + """Refuse firmware-native duplication on the CorOS 4.0.1 profile.""" + raise ControlNotDrivable( + "duplicate_setlist", + "firmware-native File COPY was measured on CorOS 4.1.0, not on " + "the CorOS 4.0.1 base profile", + "copy presets individually with copy_preset(), or use a measured " + "CorOS 4.1 profile", + ) + + def _duplicate_setlist_41(self, source_name: str, *, confirm: bool = True, + timeout: float | None = None, + interval: float = 2.0): """Ask firmware to duplicate a complete user setlist exactly once. Cortex Control sends one sparse ``File{COPY}`` containing only the @@ -3479,23 +3491,20 @@ def duplicate_setlist(self, source_name: str, *, confirm: bool = True, """ source_key = (source_name if source_name.startswith("/") else f"{USER_SETLIST_ROOT}/{source_name}") + if not _is_user_setlist_key(source_key): + raise ValueError( + f"source {source_key!r} is not a direct user setlist") if confirm: - before = self.list_folders() + before = self._stable_folder_listing(timeout=120.0, + interval=interval) before_keys = {folder.key for folder in before} if source_key not in before_keys: raise ValueError(f"source setlist {source_key!r} is not in the fresh catalog") - custom_setlists = [ - folder for folder in before - if _is_user_setlist_key(folder.key) - and folder.key != str(Setlist.USER) - ] - if len(custom_setlists) >= 12: - raise ValueError("the device already has the maximum 12 user setlists") expected = self._stable_complete_user_setlist( source_key, timeout=120.0, interval=interval ) if timeout is None: - timeout = min(600.0, 90.0 + 2.0 * len(expected)) + timeout = _setlist_copy_timeout(len(expected)) msg = pa.FileMessage(action=pa.MessageAction.COPY, type=0) msg.folder.key = source_key @@ -3507,9 +3516,21 @@ def duplicate_setlist(self, source_name: str, *, confirm: bool = True, assert timeout is not None deadline = time.monotonic() + timeout previous_destination = None + previous_folders = None while True: remaining = max(0.1, deadline - time.monotonic()) folders = self.list_folders(seconds=min(20.0, remaining)) + folder_generation = tuple( + (f.key, f.name, f.slots, f.occupied, f.is_factory) + for f in folders) + if folder_generation != previous_folders: + previous_folders = folder_generation + if time.monotonic() >= deadline: + raise TimeoutError( + f"setlist COPY was sent once but did not publish a complete " + f"matching destination within {timeout}s; it was not replayed") + time.sleep(interval) + continue created = [ folder for folder in folders if folder.key not in before_keys @@ -3522,6 +3543,11 @@ def duplicate_setlist(self, source_name: str, *, confirm: bool = True, ) if created: destination = created[0] + remaining = deadline - time.monotonic() + if remaining <= 0: + raise TimeoutError( + f"setlist COPY was sent once but did not publish a complete " + f"matching destination within {timeout}s; it was not replayed") try: listing = self.list_presets( destination.key, @@ -3544,6 +3570,25 @@ def duplicate_setlist(self, source_name: str, *, confirm: bool = True, ) time.sleep(interval) + def _stable_folder_listing(self, *, timeout: float, + interval: float) -> list: + """Return two identical folder generations inside one deadline.""" + deadline = time.monotonic() + timeout + previous_identity = None + while True: + remaining = deadline - time.monotonic() + if remaining <= 0: + raise TimeoutError( + f"no stable folder listing arrived within {timeout}s") + folders = self.list_folders(seconds=min(20.0, remaining)) + identity = tuple( + (f.key, f.name, f.slots, f.occupied, f.is_factory) + for f in folders) + if identity == previous_identity: + return folders + previous_identity = identity + time.sleep(interval) + def _stable_complete_user_setlist(self, key: str, *, timeout: float, interval: float) -> tuple: """Return two identical complete 256-slot generations for ``key``.""" @@ -4129,7 +4174,7 @@ def _preset_inventory(entries) -> tuple: entry.instrument if field_present(entry, "instrument") else 0, ) for entry in entries - if field_present(entry, "key") and entry.key + if field_present(entry, "name") and entry.name )) @@ -4147,6 +4192,11 @@ def _is_user_setlist_key(key: str) -> bool: return key.startswith(prefix) and "/" not in key[len(prefix):] +def _setlist_copy_timeout(occupied_presets: int) -> float: + """Measured 4.1 COPY allowance, capped at ten minutes.""" + return min(600.0, 90.0 + 2.0 * occupied_presets) + + def blocks(p: preset.BinaryPreset) -> list: """The OCCUPIED grid cells of ``p``, as :class:`Block` entries. diff --git a/pyquadcortex/protocol/profiles.py b/pyquadcortex/protocol/profiles.py index 18cd41e0..85548083 100644 --- a/pyquadcortex/protocol/profiles.py +++ b/pyquadcortex/protocol/profiles.py @@ -43,11 +43,18 @@ class QuadCortex41(QuadCortex): MEASURED_ON = ("4.1.0",) EVIDENCE = Evidence.CONTRIBUTED - VERIFIED = frozenset() + VERIFIED = frozenset({"duplicate_setlist"}) models = NoSnapshot("coros_4_1_0") params = NoSnapshot("coros_4_1_0") options = NoSnapshot("coros_4_1_0") + def duplicate_setlist(self, source_name: str, *, confirm: bool = True, + timeout: float | None = None, + interval: float = 2.0): + """Duplicate a setlist with the CorOS 4.1 firmware-side COPY.""" + return self._duplicate_setlist_41( + source_name, confirm=confirm, timeout=timeout, interval=interval) + class QuadCortexMini(QuadCortex): """Quad Cortex Mini - recognised, not supported, and here to be finished. diff --git a/tests/test_client.py b/tests/test_client.py index f60758ce..f5d1691b 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -10,7 +10,7 @@ import pytest -from pyquadcortex.protocol import catalog, client +from pyquadcortex.protocol import catalog, client, profiles from pyquadcortex.protocol.enums import (Footswitch, Input, Instrument, MidiSource, Output, SceneBypassBehavior, Setlist, TempoMode) from pyquadcortex.protocol.proto import ProductionAutomation_pb2 as pa @@ -29,6 +29,7 @@ def __init__(self, canned=None): self.canned = canned or {} self.broadcast = None self.last_match = None # the predicate the last type-matched read passed (read_preset, version) + self.last_timeout = None self.listeners = [] self._ids = itertools.count(1) @@ -44,6 +45,7 @@ def next_request_id(self): def await_broadcast(self, expected_class, trigger, timeout=40.0, match=None): self.last_match = match + self.last_timeout = timeout trigger() return self.broadcast @@ -144,6 +146,23 @@ def test_list_presets_omits_empty_slots_by_default(): assert [pd.index for pd in full] == [0, 1, 2, 3] +def test_list_presets_exposes_the_complete_256_slot_generation_on_request(): + listing = pa.FileMessage() + listing.folder.key = str(Setlist.USER) + for index in range(256): + listing.folder.files.add().index = index + listing.folder.files[17].name = "Occupied without relying on key" + fake = FakeTransport() + fake.broadcast = listing + + entries = client.QuadCortex(fake).list_presets( + Setlist.USER, timeout=3.0, include_empty=True) + + assert len(entries) == 256 + assert [entry.index for entry in entries] == list(range(256)) + assert fake.last_timeout == 3.0 + + def test_list_presets_matches_the_factory_listing_despite_the_trailing_slash(): # Setlist.FACTORY carries a trailing slash because RECALLS require it, but the # device reports that same folder's LISTING key without one. A naive @@ -2988,7 +3007,7 @@ def test_copy_preset_does_recall_the_source_which_changes_the_grid(): def test_duplicate_setlist_sends_the_exact_cortex_folder_copy(): - qc = client.QuadCortex(FakeTransport()) + qc = profiles.QuadCortex41(FakeTransport()) qc.duplicate_setlist("Live", confirm=False) sent = qc._t.sent[-1] assert sent.SerializeToString() == bytes.fromhex( @@ -3023,8 +3042,8 @@ def complete(first_name="One", second_name="Two"): destination_complete = complete() fake = FakeTransport() - qc = client.QuadCortex(fake) - folder_generations = iter((before, after, after, after, after)) + qc = profiles.QuadCortex41(fake) + folder_generations = iter((before, before, after, after, after, after, after)) source_generations = iter((source, source)) destination_generations = iter(( destination_partial, @@ -3065,7 +3084,7 @@ def test_duplicate_setlist_never_baselines_a_partial_source_listing(monkeypatch) complete[0].instrument = 1 fake = FakeTransport() - qc = client.QuadCortex(fake) + qc = profiles.QuadCortex41(fake) qc.list_folders = lambda seconds=20.0: folders generations = iter((partial, complete, complete)) qc.list_presets = lambda *args, **kwargs: next(generations) @@ -3080,26 +3099,88 @@ def test_duplicate_setlist_never_baselines_a_partial_source_listing(monkeypatch) assert fake.sent == [] -def test_duplicate_setlist_refuses_at_the_cortex_twelve_setlist_guard(): - root = "/media/p4/Presets" - source_key = f"{root}/Live" - folders = [client.Folder(source_key, "Live", 256, 1, False)] - folders.extend( - client.Folder(f"{root}/Setlist {index}", f"Setlist {index}", 256, 0, False) - for index in range(1, 12) - ) +def test_coros_4_0_1_refuses_unmeasured_native_setlist_copy(): fake = FakeTransport() qc = client.QuadCortex(fake) - qc.list_folders = lambda seconds=20.0: folders - qc.list_presets = lambda key, **kwargs: [ - pa.ProductData(index=index) for index in range(256) - ] + with pytest.raises(ControlNotDrivable) as caught: + qc.duplicate_setlist("Live", confirm=False) + assert caught.value.control == "duplicate_setlist" + assert "4.1.0" in caught.value.evidence + assert "copy_preset" in caught.value.workaround + assert fake.sent == [] + - with pytest.raises(ValueError, match="maximum 12"): - qc.duplicate_setlist("Live") +def test_duplicate_setlist_rejects_a_factory_source_before_sending(): + fake = FakeTransport() + qc = profiles.QuadCortex41(fake) + with pytest.raises(ValueError, match="direct user setlist"): + qc.duplicate_setlist(str(Setlist.FACTORY), confirm=False) assert fake.sent == [] +def test_duplicate_setlist_confirm_false_returns_the_immediate_reply(): + reply = pa.FileMessage(action=pa.MessageAction.UPDATE) + fake = FakeTransport({"FileMessage": reply}) + qc = profiles.QuadCortex41(fake) + assert qc.duplicate_setlist("Live", confirm=False) is reply + + +def test_duplicate_setlist_preflight_rejects_a_missing_source_before_copy( + monkeypatch): + folders = [client.Folder("/media/p4/Presets/Other", "Other", 256, 0, False)] + fake = FakeTransport() + qc = profiles.QuadCortex41(fake) + qc.list_folders = lambda **kwargs: folders + monkeypatch.setattr(client.time, "sleep", lambda seconds: None) + with pytest.raises(ValueError, match="not in the fresh catalog"): + qc.duplicate_setlist("Missing") + assert fake.sent == [] + + +def test_duplicate_setlist_rejects_an_ambiguous_new_folder(monkeypatch): + root = "/media/p4/Presets" + source_key = f"{root}/Live" + before = [client.Folder(source_key, "Live", 256, 1, False)] + after = before + [ + client.Folder(f"{root}/Live 2", "Live 2", 256, 1, False), + client.Folder(f"{root}/Other", "Other", 256, 0, False), + ] + full = [pa.ProductData(index=index) for index in range(256)] + full[0].name = "One" + fake = FakeTransport() + qc = profiles.QuadCortex41(fake) + folders = iter((before, before, after, after)) + qc.list_folders = lambda **kwargs: next(folders) + qc.list_presets = lambda *args, **kwargs: full + monkeypatch.setattr(client.time, "sleep", lambda seconds: None) + with pytest.raises(RuntimeError, match="more than one folder"): + qc.duplicate_setlist("Live", timeout=5.0, interval=0.0) + assert sum(isinstance(m, pa.FileMessage) and + m.action == pa.MessageAction.COPY for m in fake.sent) == 1 + + +def test_duplicate_setlist_timeout_never_replays_copy(monkeypatch): + root = "/media/p4/Presets" + source_key = f"{root}/Live" + before = [client.Folder(source_key, "Live", 256, 1, False)] + full = [pa.ProductData(index=index) for index in range(256)] + full[0].name = "One" + fake = FakeTransport() + qc = profiles.QuadCortex41(fake) + qc.list_folders = lambda **kwargs: before + qc.list_presets = lambda *args, **kwargs: full + monkeypatch.setattr(client.time, "sleep", lambda seconds: None) + with pytest.raises(TimeoutError, match="was not replayed"): + qc.duplicate_setlist("Live", timeout=0.0, interval=0.0) + assert sum(isinstance(m, pa.FileMessage) and + m.action == pa.MessageAction.COPY for m in fake.sent) == 1 + + +def test_duplicate_setlist_default_deadline_scales_and_caps(): + assert client._setlist_copy_timeout(2) == 94.0 + assert client._setlist_copy_timeout(256) == 600.0 + + # -- Global EQ by band, not by wire index -------------------------------------- # 5 parameters per band at offsets GAIN 0, FREQUENCY 1, Q 2, TYPE 3. Established by # changing each of band 1's controls and seeing which index moved, then checked diff --git a/tests/test_hardware_markers.py b/tests/test_hardware_markers.py index a4f8fd0b..4efce4c6 100644 --- a/tests/test_hardware_markers.py +++ b/tests/test_hardware_markers.py @@ -37,7 +37,7 @@ "wait_for_listing": "no hardware test yet; it is the polling wrapper round list_presets and says nothing until a write changes a listing", "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": "same-commit CorOS 4.1.0 corroboration exists outside the pytest hardware suite; add a state-neutral suite test before removing this marker", + "duplicate_setlist": "no hardware test yet; a failed run leaves a firmware-named folder behind and cleanup requires discovering then destructively deleting it. A contributed CorOS 4.1.0 run on 2026-09-11 corroborated the operation outside pytest", # -- library listings whose CONTENT belongs to the owner ------------------- # Each returns whatever this unit happens to hold, so a test can assert the diff --git a/tests/test_profiles.py b/tests/test_profiles.py index 4fd3c8f0..28c18d0d 100644 --- a/tests/test_profiles.py +++ b/tests/test_profiles.py @@ -248,17 +248,17 @@ def test_support_defaults_to_verified_and_is_readable(): assert qc.support is support.Support.EXPERIMENTAL -def test_the_4_1_stub_connects_but_verifies_nothing_and_has_no_snapshot(): +def test_the_4_1_profile_verifies_native_duplication_and_has_no_snapshot_yet(): cls = profiles.QuadCortex41 assert issubclass(cls, client.QuadCortex) assert cls.MEASURED_ON == ("4.1.0",) assert cls.EVIDENCE is support.Evidence.CONTRIBUTED - assert cls.VERIFIED == frozenset() + assert cls.VERIFIED == frozenset({"duplicate_setlist"}) 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 len(cls(FakeTransport()).unverified_operations) == len(client.QuadCortex.operations()) + assert "duplicate_setlist" not in cls(FakeTransport()).unverified_operations def test_the_mini_stub_is_recognised_but_cannot_connect(): From f9cb4f9ce5561da22001ffc7328d5d6edc4e789b Mon Sep 17 00:00:00 2001 From: Antoni Ivanov <262547018+tony-xmelon@users.noreply.github.com> Date: Sat, 19 Sep 2026 22:44:08 +0300 Subject: [PATCH 4/7] Fix profile-aware session expectation --- tests/test_session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 3e74f1e3bbd6c701e5f44520a73679b0818665ec Mon Sep 17 00:00:00 2001 From: Antoni Ivanov <262547018+tony-xmelon@users.noreply.github.com> Date: Sat, 19 Sep 2026 22:54:46 +0300 Subject: [PATCH 5/7] Follow documentation typography rules --- changelog.md | 2 +- docs/protocol.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index 3002f3fc..c996c94b 100644 --- a/changelog.md +++ b/changelog.md @@ -17,7 +17,7 @@ sustained stretch without a correction. ### CorOS 4.1 can duplicate a setlist with one firmware-side copy -`QuadCortex41.duplicate_setlist()` sends the sparse folder COPY extracted from +`QuadCortex41.duplicate_setlist()` sends the sparse folder `COPY` extracted from Cortex Control 4.1 exactly once, then confirms the firmware-created destination with stable folder generations and two identical complete 256-slot inventories. A contributed CorOS 4.1.0 hardware run on 2026-09-11 confirmed a two-preset copy diff --git a/docs/protocol.md b/docs/protocol.md index aa0e2f26..81048760 100644 --- a/docs/protocol.md +++ b/docs/protocol.md @@ -1385,15 +1385,15 @@ does. So the MIDI documentation's "User folders" at bank-select LSB 2 to 12 are folders a player creates. **Deleting a setlist** is `File{DELETE, folder{key, name}}` against the setlist's own key. -On CorOS 4.0.1, the unit's duplicate action sends a `File` CREATE and narrates -progress through `BulkOperation`; replaying that CREATE from the host produced +On CorOS 4.0.1, the unit's duplicate action sends a `File` `CREATE` and narrates +progress through `BulkOperation`; replaying that `CREATE` from the host produced an empty destination. `copy_preset()` retains the measured recall-and-save fallback on that profile. On CorOS 4.1, Cortex Control sends one host-drivable sparse `File{COPY, type: 0, folder{key: , is_factory: false}}`. Firmware chooses the collision-safe destination and performs the copy asynchronously. -`duplicate_setlist()` sends COPY exactly once and uses read-only polling until +`duplicate_setlist()` sends `COPY` exactly once and uses read-only polling until two complete, identical 256-slot destination generations match the source. A contributed 4.1.0 hardware run verified a two-preset copy in 49.878 seconds. From 5eed351ee74871643f159b46d248e9db8d9cd708 Mon Sep 17 00:00:00 2001 From: Antoni Ivanov <262547018+tony-xmelon@users.noreply.github.com> Date: Sun, 27 Sep 2026 03:55:03 +0300 Subject: [PATCH 6/7] Add disposable native duplicate hardware coverage --- tests/hardware/test_duplicate_setlist.py | 123 +++++++++++++++++++++++ tests/test_hardware_markers.py | 1 - 2 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 tests/hardware/test_duplicate_setlist.py diff --git a/tests/hardware/test_duplicate_setlist.py b/tests/hardware/test_duplicate_setlist.py new file mode 100644 index 00000000..2ffb1d02 --- /dev/null +++ b/tests/hardware/test_duplicate_setlist.py @@ -0,0 +1,123 @@ +"""Read/write hardware coverage for firmware-native setlist duplication.""" + +import time +import uuid + +import pytest + + +FOLDER_LIST_TIMEOUT = 20.0 + + +def _folder(qc, key): + return next((item for item in qc.list_folders(seconds=FOLDER_LIST_TIMEOUT) + if item.key.rstrip("/") == key.rstrip("/")), None) + + +def _wait_for_folder(qc, key, *, present, timeout=90.0): + deadline = time.monotonic() + timeout + while True: + result = _folder(qc, key) + if (result is not None) is present: + return result + remaining = deadline - time.monotonic() + if remaining <= 0: + state = "appear" if present else "disappear" + raise AssertionError( + f"test-owned setlist {key!r} did not {state} within {timeout}s") + time.sleep(min(2.0, remaining)) + + +@pytest.mark.verifies("duplicate_setlist") +def test_duplicate_setlist_copies_a_disposable_empty_setlist(qc, profile): + """Exercise one native COPY without exposing any user preset to deletion. + + The source is a fresh empty setlist. Cleanup is limited to its exact key and + a returned or uniquely token-named destination, and only while each still + reads empty. The COPY is sent once by the library; this test never retries + it after an uncertain result. + """ + from pyquadcortex.protocol.client import ( + QuadCortex, USER_SETLIST_ROOT, _is_user_setlist_key, + ) + + if profile.duplicate_setlist is QuadCortex.duplicate_setlist: + pytest.skip( + f"native duplicate_setlist is unavailable on {profile.__name__}") + + token = uuid.uuid4().hex[:12] + source_name = f"QCdup-{token}" + source_key = f"{USER_SETLIST_ROOT}/{source_name}" + assert _folder(qc, source_key) is None, ( + f"random disposable source already exists; refusing to touch {source_key!r}") + + create_attempted = False + copy_attempted = False + destination = None + copy_baseline: set[str] = set() + try: + # CREATE may have committed before a reply/readback problem, so cleanup + # owns the exact generated name from immediately before the call. + create_attempted = True + assert qc.create_setlist(source_name) == source_key + source = _wait_for_folder(qc, source_key, present=True) + assert source is not None and source.name == source_name + assert source.occupied == 0, ( + f"new disposable source unexpectedly contains presets: {source!r}; " + "refusing to duplicate or delete it") + + copy_baseline = { + item.key for item in qc.list_folders(seconds=FOLDER_LIST_TIMEOUT) + } + assert source_key in copy_baseline, ( + "source disappeared before COPY preflight; refusing to send") + + copy_attempted = True + destination = qc.duplicate_setlist( + source_name, timeout=180.0, interval=1.0) + assert destination.key not in copy_baseline + assert not destination.is_factory + assert destination.occupied == 0, ( + f"duplicate of an empty source is unexpectedly occupied: {destination!r}") + finally: + if create_attempted: + folders = qc.list_folders(seconds=FOLDER_LIST_TIMEOUT) + source_key_normalized = source_key.rstrip("/") + destination_key = (destination.key.rstrip("/") + if destination is not None else None) + owned = [item for item in folders + if item.key.rstrip("/") == source_key_normalized + or (destination_key is not None + and item.key.rstrip("/") == destination_key) + or (copy_attempted and token in (item.name + item.key) + and not item.is_factory + and _is_user_setlist_key(item.key) + and item.key not in copy_baseline)] + unidentified = [item for item in folders + if copy_attempted + and item.key not in copy_baseline + and item.key.rstrip("/") != source_key_normalized + and (destination_key is None + or item.key.rstrip("/") != destination_key) + and token not in (item.name + item.key) + and _is_user_setlist_key(item.key) + and not item.is_factory] + + for item in reversed(owned): + if item.occupied != 0: + pytest.fail( + f"test-owned setlist {item.key!r} unexpectedly contains " + f"{item.occupied} presets; left untouched for manual review") + # Do not replay DELETE if read-back is uncertain; report the + # exact empty test folder still present instead. + qc.delete_setlist(item.name) + if _folder(qc, item.key) is not None: + pytest.fail( + f"DELETE was not confirmed for disposable test folder " + f"{item.key!r}; it was not sent a second time") + if unidentified: + names = ", ".join( + f"{item.name!r} ({item.key!r})" for item in unidentified) + pytest.fail( + "COPY may have created a folder without the unique source " + f"token, so it was left untouched for manual review: {names}") diff --git a/tests/test_hardware_markers.py b/tests/test_hardware_markers.py index 8b631e9a..77475d9b 100644 --- a/tests/test_hardware_markers.py +++ b/tests/test_hardware_markers.py @@ -37,7 +37,6 @@ "wait_for_listing": "no hardware test yet; it is the polling wrapper round list_presets and says nothing until a write changes a listing", "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; a failed run leaves a firmware-named folder behind and cleanup requires discovering then destructively deleting it. A contributed CorOS 4.1.0 run on 2026-09-11 corroborated the operation outside pytest", # -- library listings whose CONTENT belongs to the owner ------------------- # Each returns whatever this unit happens to hold, so a test can assert the From c7961c2e4bd1a6c5a3c0120f0ceec0db8471dd95 Mon Sep 17 00:00:00 2001 From: Antoni Ivanov <262547018+tony-xmelon@users.noreply.github.com> Date: Sun, 27 Sep 2026 03:57:42 +0300 Subject: [PATCH 7/7] Require stable setlist generations in hardware cleanup --- tests/hardware/test_duplicate_setlist.py | 34 +++++++++++++++--------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/tests/hardware/test_duplicate_setlist.py b/tests/hardware/test_duplicate_setlist.py index 2ffb1d02..b75864dc 100644 --- a/tests/hardware/test_duplicate_setlist.py +++ b/tests/hardware/test_duplicate_setlist.py @@ -6,25 +6,31 @@ import pytest -FOLDER_LIST_TIMEOUT = 20.0 +def _stable_folders(qc, *, timeout=120.0): + # The firmware can publish partial generations. Use the same convergence + # rule as duplicate_setlist before making inventory or cleanup decisions. + return qc._stable_folder_listing(timeout=timeout, interval=1.0) def _folder(qc, key): - return next((item for item in qc.list_folders(seconds=FOLDER_LIST_TIMEOUT) + return next((item for item in _stable_folders(qc) if item.key.rstrip("/") == key.rstrip("/")), None) def _wait_for_folder(qc, key, *, present, timeout=90.0): deadline = time.monotonic() + timeout while True: - result = _folder(qc, key) - if (result is not None) is present: - return result remaining = deadline - time.monotonic() if remaining <= 0: state = "appear" if present else "disappear" raise AssertionError( f"test-owned setlist {key!r} did not {state} within {timeout}s") + result = next((item for item in _stable_folders( + qc, timeout=remaining) + if item.key.rstrip("/") == key.rstrip("/")), None) + if (result is not None) is present: + return result + remaining = deadline - time.monotonic() time.sleep(min(2.0, remaining)) @@ -66,9 +72,7 @@ def test_duplicate_setlist_copies_a_disposable_empty_setlist(qc, profile): f"new disposable source unexpectedly contains presets: {source!r}; " "refusing to duplicate or delete it") - copy_baseline = { - item.key for item in qc.list_folders(seconds=FOLDER_LIST_TIMEOUT) - } + copy_baseline = {item.key for item in _stable_folders(qc)} assert source_key in copy_baseline, ( "source disappeared before COPY preflight; refusing to send") @@ -81,7 +85,7 @@ def test_duplicate_setlist_copies_a_disposable_empty_setlist(qc, profile): f"duplicate of an empty source is unexpectedly occupied: {destination!r}") finally: if create_attempted: - folders = qc.list_folders(seconds=FOLDER_LIST_TIMEOUT) + folders = _stable_folders(qc) source_key_normalized = source_key.rstrip("/") destination_key = (destination.key.rstrip("/") if destination is not None else None) @@ -103,6 +107,7 @@ def test_duplicate_setlist_copies_a_disposable_empty_setlist(qc, profile): and _is_user_setlist_key(item.key) and not item.is_factory] + deleted_keys = set() for item in reversed(owned): if item.occupied != 0: pytest.fail( @@ -111,10 +116,15 @@ def test_duplicate_setlist_copies_a_disposable_empty_setlist(qc, profile): # Do not replay DELETE if read-back is uncertain; report the # exact empty test folder still present instead. qc.delete_setlist(item.name) - if _folder(qc, item.key) is not None: + deleted_keys.add(item.key.rstrip("/")) + if deleted_keys: + remaining = {item.key.rstrip("/") + for item in _stable_folders(qc)} + leftovers = sorted(deleted_keys & remaining) + if leftovers: pytest.fail( - f"DELETE was not confirmed for disposable test folder " - f"{item.key!r}; it was not sent a second time") + "DELETE was not confirmed for disposable test folders " + f"{leftovers!r}; none was sent a second time") if unidentified: names = ", ".join( f"{item.name!r} ({item.key!r})" for item in unidentified)