fix: rebase layout moves and shared draft saves

Test: cargo test -p fader_master --lib --locked
Test: cargo clippy -p fader_master --all-targets --all-features --locked -- -D warnings
Test: cargo fmt --all -- --check
This commit is contained in:
Dandaedre 2026-10-16 18:46:54 +02:00
parent 164be169f0
commit 041f40db5e
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
3 changed files with 89 additions and 7 deletions

View File

@ -324,7 +324,10 @@ group controls remain a reserved future mode.
The live mixer revision and configuration-draft revision are independent.
Draft edits are serialized by the server, require the caller's expected draft
revision, and never mutate live routing or audio as a side effect. Successful
draft edits are explicitly marked unsaved until a later Save command.
draft edits are explicitly marked unsaved until a later Save command. A layout
move names one stable entry and an absolute destination, so the server may
rebase that operation onto a newer shared draft instead of flashing the
optimistic order and rejecting it solely because another draft edit landed.
MIDI learn is scoped to one configured surface, logical fader, and action. While
armed, messages from that surface are withheld from normal routing; unrelated
@ -334,7 +337,9 @@ validated draft binding, while cancellation restores routing immediately.
Save is the only editor commit action. It first validates and prepares the
profile-derived matching, groups, faders, pickup, and MIDI routing, compares the
exact on-disk bytes with the server's load/save baseline, and uses the atomic
writer. After persistence succeeds, the server activates the prepared routing
writer. Save commits the server's latest validated shared draft even when the
requester's displayed revision is older; a future revision remains invalid.
After persistence succeeds, the server activates the prepared routing
while retaining confirmed audio observations and issuing no audio write.
Conflicts or persistence failures retain the previous file, live configuration,
and dirty draft.

View File

@ -337,6 +337,14 @@ impl LocalServer {
expected_revision,
edit,
} if request.version == PROTOCOL_VERSION => {
let current_revision = self.configuration.revision();
let expected_revision = if expected_revision < current_revision
&& matches!(&edit, crate::ipc::ConfigurationEdit::MoveLayoutEntry { .. })
{
current_revision
} else {
expected_revision
};
match self.configuration.apply(expected_revision, edit) {
Ok(profile) => {
self.mixer.set_configuration(configuration_snapshot(
@ -423,10 +431,10 @@ impl LocalServer {
crate::ipc::RequestCommand::SaveConfiguration { expected_revision }
if request.version == PROTOCOL_VERSION =>
{
if expected_revision != self.configuration.revision() {
let current_revision = self.configuration.revision();
if expected_revision > current_revision {
return Err(crate::live::LiveMixerError::Profile(format!(
"stale configuration revision {expected_revision}; current revision is {}",
self.configuration.revision()
"stale configuration revision {expected_revision}; current revision is {current_revision}"
)));
}
let profile = self
@ -437,7 +445,7 @@ impl LocalServer {
.map_err(crate::live::LiveMixerError::Profile)?;
let max_gain = Gain::new(profile.max_gain())?;
self.configuration
.save(expected_revision)
.save(current_revision)
.map_err(|error| crate::live::LiveMixerError::Profile(error.to_string()))?;
self.mixer.reconfigure(&profile, max_gain)?;
self.midi = midi;
@ -876,6 +884,72 @@ mod tests {
);
}
#[test]
fn stale_layout_move_and_save_rebase_onto_latest_shared_draft() {
let root = tempdir().unwrap();
let source = include_str!("../../examples/profiles/desktop.toml");
let profile_path = root.path().join("desktop.toml");
fs::write(&profile_path, source).unwrap();
let mut server = LocalServer::pulse(
root.path().join("control.sock"),
Gain::UNITY,
ProfileDocument::parse(source).unwrap(),
profile_path.clone(),
root.path().join("config.toml"),
root.path().join("state.toml"),
)
.unwrap();
let added = direct_request(
&mut server,
RequestCommand::EditConfiguration {
expected_revision: 0,
edit: crate::ipc::ConfigurationEdit::AddSeparator {
id: "media-heading".into(),
label: "Media".into(),
position: 0,
},
},
);
assert!(matches!(added.result, ResponseResult::Snapshot { .. }));
let moved = direct_request(
&mut server,
RequestCommand::EditConfiguration {
expected_revision: 0,
edit: crate::ipc::ConfigurationEdit::MoveLayoutEntry {
id: "media-fader".into(),
position: 0,
},
},
);
let ResponseResult::Snapshot { snapshot } = moved.result else {
panic!("stable-ID layout move should rebase onto the current draft");
};
assert_eq!(snapshot.configuration.revision, 2);
assert!(matches!(
snapshot.configuration.mixer_layout.first(),
Some(crate::ipc::MixerLayoutEntry::Fader { fader, .. })
if fader == "media-fader"
));
let saved = direct_request(
&mut server,
RequestCommand::SaveConfiguration {
expected_revision: 0,
},
);
let ResponseResult::Snapshot { snapshot } = saved.result else {
panic!("save should activate the latest shared draft");
};
assert_eq!(snapshot.configuration.applied_revision, 2);
let persisted = fs::read_to_string(profile_path).unwrap();
assert!(
persisted.find("fader = \"media-fader\"").unwrap()
< persisted.find("id = \"media-heading\"").unwrap()
);
}
fn direct_request(
server: &mut LocalServer,
command: crate::ipc::RequestCommand,

View File

@ -374,11 +374,14 @@ Dependencies: M8, M2, M1.
that persists and activates the validated draft. Tests: stale edits conflict,
external file edits are not overwritten, comments survive save, and write
failure leaves the previous disk and live configuration usable.
Save commits the latest server-owned validated draft when the requesting view
is behind; it does not reject already accepted shared edits as stale.
- [x] **M9.4 Mixer-first layout:** persist ordered logical-fader and separator
entries, synthesize declaration-order entries for old profiles, and retain
hidden faders in place. The main mixer can reorder either entry type, add/edit/
remove separators, hide visible faders, and restore hidden faders without
changing targets or bindings. Tests: invalid/duplicate/dangling layout entries
changing targets or bindings. Stable-ID moves rebase onto the latest draft
when another edit advances it. Tests: invalid/duplicate/dangling layout entries
fail; reorder and hide/show round trip through comment-preserving drafts; a
hidden application remains routable through a visible group.
Profiles now validate and publish ordered fader/separator entries, with