Repository navigation
Preserve authoritative preset keys without listing first #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2fdb2c4
4311f6a
26af4c2
85774ac
053da6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4187,37 +4187,60 @@ def save_current_preset( | |||||||||||||||||||||||||||||||||
| return e.name | ||||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def delete_preset(self, setlist_path: str, name: str): | ||||||||||||||||||||||||||||||||||
| """Delete the preset named ``name`` from the setlist at ``setlist_path``. | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Confirmed by capture: deleting "Test save to user | ||||||||||||||||||||||||||||||||||
| sl" from slot 28E sent ``File{action: DELETE, type: 0, folder{key: | ||||||||||||||||||||||||||||||||||
| <setlist path>, is_factory: false, files{key: "<setlist | ||||||||||||||||||||||||||||||||||
| path>/<name>.pb"}}}`` - the preset is addressed by its device FILE | ||||||||||||||||||||||||||||||||||
| PATH (name-based, ``.pb`` extension), NOT by slot index. | ||||||||||||||||||||||||||||||||||
| def _stored_preset_key(self, setlist_path: str, preset) -> str: | ||||||||||||||||||||||||||||||||||
| """Resolve a display name or validate a listed ProductData key.""" | ||||||||||||||||||||||||||||||||||
| if not isinstance(preset, pa.ProductData): | ||||||||||||||||||||||||||||||||||
| # Backward-compatible and deliberately listing-free: hardware | ||||||||||||||||||||||||||||||||||
| # teardown depends on a best-effort delete even when listing reads | ||||||||||||||||||||||||||||||||||
| # are silent. On measured 4.0.1 listings this reconstructed path is | ||||||||||||||||||||||||||||||||||
| # byte-for-byte the same value as the device-supplied key. | ||||||||||||||||||||||||||||||||||
| return f"{setlist_path.rstrip('/')}/{preset}.pb" | ||||||||||||||||||||||||||||||||||
| if not (field_present(preset, "key") and preset.key): | ||||||||||||||||||||||||||||||||||
| raise ControlNotDrivable( | ||||||||||||||||||||||||||||||||||
| "stored preset product key", | ||||||||||||||||||||||||||||||||||
| "the supplied ProductData carries no key, so the device did " | ||||||||||||||||||||||||||||||||||
| "not provide an address", | ||||||||||||||||||||||||||||||||||
| "pass a populated ProductData from list_presets(), or pass " | ||||||||||||||||||||||||||||||||||
| "the exact display name to use the measured 4.0.1 path shape", | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| prefix = setlist_path.rstrip("/") + "/" | ||||||||||||||||||||||||||||||||||
| if not preset.key.startswith(prefix): | ||||||||||||||||||||||||||||||||||
| raise ValueError( | ||||||||||||||||||||||||||||||||||
| f"preset key {preset.key!r} does not belong to " | ||||||||||||||||||||||||||||||||||
| f"setlist {setlist_path!r}") | ||||||||||||||||||||||||||||||||||
| return preset.key | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def delete_preset(self, setlist_path: str, preset): | ||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the one I would most like changed. Dropping Repo mypy is deliberately not strict, so CI stays green either way - this is about what downstream gets. The union is one line:
Suggested change
|
||||||||||||||||||||||||||||||||||
| """Delete a stored preset from ``setlist_path``. | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| ``preset`` is either its exact display name or the ``ProductData`` | ||||||||||||||||||||||||||||||||||
| returned by :meth:`list_presets`. On three CorOS 4.0.1 captures every | ||||||||||||||||||||||||||||||||||
| occupied entry's key was exactly ``<setlist>/<name>.pb``; passing a | ||||||||||||||||||||||||||||||||||
| listing entry avoids reconstructing it, while the name form remains a | ||||||||||||||||||||||||||||||||||
| listing-free compatibility path for best-effort cleanup. | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+4216
to
+4220
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The captured record that was here is gone rather than kept. Thread 3992216374 asked for the 4.0.1 captured shape to stay, with any 4.1.0 reading recorded beside it and labelled as read from the binary; the thread is resolved but the shape is not back. CLAUDE.md's rule is that a docstring states its evidence, and "on three CorOS 4.0.1 captures" names a firmware but no capture and no date. I re-decoded the three sessions to check your claim, and it holds: one DELETE exists across all three (windows-session-02, frame 19033, t=54.6s) and it sent exactly this shape. So the old record and your new sentence are both true and can sit together.
Suggested change
|
||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||
| msg = pa.FileMessage(action=pa.MessageAction.DELETE, type=0) | ||||||||||||||||||||||||||||||||||
| msg.folder.key = setlist_path | ||||||||||||||||||||||||||||||||||
| msg.folder.is_factory = False | ||||||||||||||||||||||||||||||||||
| msg.folder.files.add().key = f"{setlist_path}/{name}.pb" | ||||||||||||||||||||||||||||||||||
| msg.folder.files.add().key = self._stored_preset_key( | ||||||||||||||||||||||||||||||||||
| setlist_path, preset) | ||||||||||||||||||||||||||||||||||
| return self._file_operation(msg) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def move_preset(self, setlist_path: str, name: str, to_position): | ||||||||||||||||||||||||||||||||||
| """Move the preset named ``name`` to slot ``to_position`` (same setlist). | ||||||||||||||||||||||||||||||||||
| def move_preset(self, setlist_path: str, preset, to_position): | ||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
| """Move a stored preset into ``to_position`` in the same setlist. | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| ``to_position`` is either the linear slot index or the slot name shown on | ||||||||||||||||||||||||||||||||||
| the unit (``"28D"``). | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Confirmed by capture: dragging "Darkglass AO900 | ||||||||||||||||||||||||||||||||||
| 2_1" onto slot 28D sent ``File{action: MOVE, type: 0, folder{key: | ||||||||||||||||||||||||||||||||||
| <setlist path>, files{key: "<setlist path>/<name>.pb"}}, | ||||||||||||||||||||||||||||||||||
| to_folder{key: <setlist path>, files{index: 219}}}`` - source by FILE | ||||||||||||||||||||||||||||||||||
| PATH, destination by LINEAR slot index. | ||||||||||||||||||||||||||||||||||
| the unit (``"28D"``). ``preset`` may be its exact display name or the | ||||||||||||||||||||||||||||||||||
| ``ProductData`` returned by :meth:`list_presets`; the latter supplies | ||||||||||||||||||||||||||||||||||
| the device's own key. Cortex Control 4.0.1 was captured adding | ||||||||||||||||||||||||||||||||||
| ``is_downloads: false`` to this MOVE shape. | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+4233
to
+4236
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as on Your
Suggested change
|
||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||
| msg = pa.FileMessage(action=pa.MessageAction.MOVE, type=0) | ||||||||||||||||||||||||||||||||||
| msg.folder.key = setlist_path | ||||||||||||||||||||||||||||||||||
| msg.folder.is_factory = False | ||||||||||||||||||||||||||||||||||
| msg.folder.files.add().key = f"{setlist_path}/{name}.pb" | ||||||||||||||||||||||||||||||||||
| msg.folder.is_downloads = False | ||||||||||||||||||||||||||||||||||
| msg.folder.files.add().key = self._stored_preset_key( | ||||||||||||||||||||||||||||||||||
| setlist_path, preset) | ||||||||||||||||||||||||||||||||||
| msg.to_folder.key = setlist_path | ||||||||||||||||||||||||||||||||||
| msg.to_folder.files.add().index = _as_position(to_position) | ||||||||||||||||||||||||||||||||||
| return self._file_operation(msg) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -586,37 +586,105 @@ def test_save_current_preset_sends_file_create_by_reference(): | |||||
| ) | ||||||
|
|
||||||
|
|
||||||
| def test_delete_preset_sends_file_delete_by_path(): | ||||||
| # CONFIRMED wire shape (Windows capture 2): delete addresses the preset by | ||||||
| # its device file path "<setlist>/<name>.pb", not by slot index. | ||||||
| qc = client.QuadCortex(FakeTransport()) | ||||||
| qc.delete_preset("/media/p4/Presets/My Presets", "Test save to user sl") | ||||||
| def _preset_listing(setlist, *entries): | ||||||
| listing = pa.FileMessage() | ||||||
| listing.folder.key = setlist | ||||||
| for values in entries: | ||||||
| entry = listing.folder.files.add() | ||||||
| for field, value in values.items(): | ||||||
| setattr(entry, field, value) | ||||||
| return listing | ||||||
|
|
||||||
|
|
||||||
| def test_delete_preset_uses_the_authoritative_catalog_key(): | ||||||
| setlist = "/media/p4/Presets/My Presets" | ||||||
| listing = _preset_listing(setlist, { | ||||||
| "index": 220, | ||||||
| "name": "Test save to user sl", | ||||||
| "key": f"{setlist}/opaque-device-key-220", | ||||||
| }) | ||||||
| fake = FakeTransport() | ||||||
| qc = client.QuadCortex(fake) | ||||||
| qc.delete_preset(setlist, listing.folder.files[0]) | ||||||
| sent = qc._t.sent[-1] | ||||||
| assert isinstance(sent, pa.FileMessage) | ||||||
| assert sent.action == pa.MessageAction.DELETE | ||||||
| assert sent.type == 0 | ||||||
| assert sent.folder.key == "/media/p4/Presets/My Presets" | ||||||
| assert sent.folder.is_factory is False | ||||||
| assert ( | ||||||
| sent.folder.files[0].key | ||||||
| == "/media/p4/Presets/My Presets/Test save to user sl.pb" | ||||||
| ) | ||||||
| assert sent.folder.files[0].key == f"{setlist}/opaque-device-key-220" | ||||||
| assert not sent.folder.files[0].HasField("name") | ||||||
| assert not sent.folder.files[0].HasField("index") | ||||||
| assert not sent.HasField("to_folder") | ||||||
|
|
||||||
|
|
||||||
| def test_move_preset_sends_file_move(): | ||||||
| # CONFIRMED wire shape (Windows capture 2): source by file path, | ||||||
| # destination by linear slot index in to_folder. | ||||||
| def test_delete_preset_by_name_stays_listing_free_for_hardware_cleanup(): | ||||||
| setlist = "/media/p4/Presets/My Presets" | ||||||
| qc = client.QuadCortex(FakeTransport()) | ||||||
| qc.move_preset("/media/p4/Presets/My Presets", "Darkglass AO900 2_1", 219) | ||||||
| qc.delete_preset(setlist, "Test save to user sl") | ||||||
| assert qc._t.sent[-1].folder.files[0].key == \ | ||||||
| f"{setlist}/Test save to user sl.pb" | ||||||
|
|
||||||
|
|
||||||
| def test_a_product_key_must_belong_to_the_named_setlist(): | ||||||
| qc = client.QuadCortex(FakeTransport()) | ||||||
| wrong = pa.ProductData( | ||||||
| key="/media/p4/Presets/Factory Presets/Cali Basswalk.pb") | ||||||
| with pytest.raises(ValueError, match="does not belong"): | ||||||
| qc.delete_preset("/media/p4/Presets/My Presets", wrong) | ||||||
| assert qc._t.sent == [] | ||||||
|
|
||||||
|
|
||||||
| def test_a_product_without_a_key_refuses_with_auditable_evidence(): | ||||||
| qc = client.QuadCortex(FakeTransport()) | ||||||
| with pytest.raises(ControlNotDrivable) as caught: | ||||||
| qc.delete_preset("/media/p4/Presets/My Presets", | ||||||
| pa.ProductData(name="Unnamed")) | ||||||
| assert caught.value.control == "stored preset product key" | ||||||
| assert "no key" in caught.value.evidence | ||||||
| assert "list_presets" in caught.value.workaround | ||||||
|
|
||||||
|
|
||||||
| def test_move_preset_uses_an_authoritative_key_and_the_captured_flag(): | ||||||
| setlist = "/media/p4/Presets/My Presets" | ||||||
| listing = _preset_listing( | ||||||
| setlist, | ||||||
| {"index": 218, "name": "Darkglass AO900 2_1", | ||||||
| "key": f"{setlist}/opaque-source"}, | ||||||
| {"index": 219, "name": "Unsaved"}, | ||||||
| ) | ||||||
| fake = FakeTransport() | ||||||
| qc = client.QuadCortex(fake) | ||||||
| qc.move_preset(setlist, listing.folder.files[0], 219) | ||||||
| sent = qc._t.sent[-1] | ||||||
| assert isinstance(sent, pa.FileMessage) | ||||||
| assert sent.action == pa.MessageAction.MOVE | ||||||
| assert ( | ||||||
| sent.folder.files[0].key | ||||||
| == "/media/p4/Presets/My Presets/Darkglass AO900 2_1.pb" | ||||||
| ) | ||||||
| assert sent.folder.is_downloads is False | ||||||
| assert sent.folder.files[0].key == f"{setlist}/opaque-source" | ||||||
| assert sent.to_folder.key == "/media/p4/Presets/My Presets" | ||||||
| assert sent.to_folder.files[0].index == 219 | ||||||
| assert not sent.to_folder.HasField("is_factory") | ||||||
|
|
||||||
|
|
||||||
| def test_move_preset_matches_the_captured_cortex_builder_bytes(): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Threads 3992216440 and 3992216451 both land here and neither is closed. I decoded the hex independently: it is byte-for-byte what the four lines above it build, and the key it pins is The test is still worth keeping - it would catch
Suggested change
If you want it to pin the device rather than the field order, build it from the recorded MOVE: |
||||||
| setlist = "/media/p4/Presets/My Presets" | ||||||
| product_key = f"{setlist}/Numb.pb" | ||||||
|
tony-xmelon marked this conversation as resolved.
Resolved
|
||||||
| listing = _preset_listing( | ||||||
| setlist, | ||||||
| {"index": 55, "name": "Numb", "key": product_key}, | ||||||
| {"index": 54, "name": "Unsaved"}, | ||||||
| ) | ||||||
| fake = FakeTransport() | ||||||
| qc = client.QuadCortex(fake) | ||||||
| qc.move_preset(setlist, listing.folder.files[0], 54) | ||||||
| assert fake.sent[-1].SerializeToString() == bytes.fromhex( | ||||||
| "08 04 18 00 22 4a 0a 1c 2f 6d 65 64 69 61 2f 70 34 2f 50 72 65 73 " | ||||||
| "65 74 73 2f 4d 79 20 50 72 65 73 65 74 73 20 00 28 00 3a 26 0a 24 " | ||||||
| "2f 6d 65 64 69 61 2f 70 34 2f 50 72 65 73 65 74 73 2f 4d 79 20 50 " | ||||||
| "72 65 73 65 74 73 2f 4e 75 6d 62 2e 70 62 2a 22 0a 1c 2f 6d 65 64 " | ||||||
| "69 61 2f 70 34 2f 50 72 65 73 65 74 73 2f 4d 79 20 50 72 65 73 65 " | ||||||
| "74 73 3a 02 10 36" | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| # -- session hello ------------------------------------------------------------- | ||||||
|
|
@@ -744,6 +812,12 @@ def test_find_preset_looks_a_preset_up_by_name(): | |||||
|
|
||||||
| def test_save_and_move_accept_slot_names(): | ||||||
| fake = FakeTransport() | ||||||
| fake.broadcast = _preset_listing( | ||||||
| str(Setlist.USER), | ||||||
| {"index": 1, "name": "Some Preset", | ||||||
| "key": f"{Setlist.USER}/opaque-source"}, | ||||||
| {"index": 219, "name": "Unsaved"}, | ||||||
| ) | ||||||
| qc = client.QuadCortex(fake) | ||||||
|
|
||||||
| qc.save_current_preset(Setlist.USER, "30A", "Some Preset") | ||||||
|
|
@@ -973,9 +1047,17 @@ def test_file_operations_do_not_raise_when_the_device_stays_silent(): | |||||
| # File ops are asynchronous and every host write is STALLed, so a missing reply | ||||||
| # says nothing about success. Raising made callers wrap each one in | ||||||
| # try/except and verify by re-reading anyway. | ||||||
| qc = client.QuadCortex(TimingOutTransport()) | ||||||
| assert qc.delete_preset(Setlist.USER, "Some Preset") is None | ||||||
| assert qc.move_preset(Setlist.USER, "Some Preset", "28D") is None | ||||||
| transport = TimingOutTransport() | ||||||
| transport.broadcast = _preset_listing( | ||||||
| str(Setlist.USER), | ||||||
| {"index": 1, "name": "Some Preset", | ||||||
| "key": f"{Setlist.USER}/opaque-source"}, | ||||||
| {"index": 219, "name": "Unsaved"}, | ||||||
| ) | ||||||
| qc = client.QuadCortex(transport) | ||||||
| source = transport.broadcast.folder.files[0] | ||||||
| assert qc.delete_preset(Setlist.USER, source) is None | ||||||
|
tony-xmelon marked this conversation as resolved.
Resolved
|
||||||
| assert qc.move_preset(Setlist.USER, source, "28D") is None | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test exists for the case where the device never answers, and it no longer covers the form that case actually arises in. The new Keeping both forms under |
||||||
| assert qc.save_current_preset(Setlist.USER, "30A", "Some Preset") == "Some Preset" | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This row says the explicit false flag is present on the captured MOVE shape, and section 10.2 above still prints that shape without it:
One document, two shapes. A correction replaces the wrong sentence rather than sitting beside it, so section 10.2's block wants
is_downloads: falseadded tofolder(it is outside this diff, so I cannot suggest it inline).Also, the "Verified by" column has a controlled vocabulary defined in the paragraph above the table - read-back, on-unit, captured only - and these two rows introduce "three Cortex Control 4.0.1 captures + read-back" and "Cortex Control 4.0.1 capture + read-back".