fix: materialize omitted config arrays during edits
Treat omitted default-empty binding, application, group, and fader arrays consistently with profile validation. Creation edits now materialize missing arrays, unlearning from an omitted binding array is a no-op, and malformed present sections remain startup errors. Tests: cargo fmt --all -- --check; cargo test -p fader-config --test editor; cargo check --workspace --all-targets --all-features; cargo clippy --workspace --all-targets --all-features -- -D warnings; malformed-profile refusal and legacy-profile upgrade tests; cargo test --workspace --doc --all-features; cargo build --workspace --release --all-features. Full workspace tests stop at the pre-existing edited examples/profiles/arch-pipewire.toml fixture mismatch.
This commit is contained in:
parent
d12dfb8f27
commit
5983b1cfb5
|
|
@ -343,7 +343,10 @@ Editor mutations are first applied to a cloned, comment-preserving document and
|
|||
the complete candidate profile is semantically validated before the draft is
|
||||
replaced. Invalid matchers, duplicate IDs, and referenced deletes therefore
|
||||
leave the prior draft unchanged. The v1 editor creates absolute groups; relative
|
||||
group controls remain a reserved future mode.
|
||||
group controls remain a reserved future mode. Schema arrays that default empty,
|
||||
including bindings, applications, groups, and faders, may be omitted from valid
|
||||
TOML; creation edits materialize them lazily and removal from an omitted empty
|
||||
array is a no-op. A present malformed section is rejected during startup.
|
||||
|
||||
The live mixer revision and configuration-draft revision are independent.
|
||||
Draft edits are serialized by the server, require the caller's expected draft
|
||||
|
|
|
|||
|
|
@ -275,12 +275,7 @@ pickup_tolerance = 0.02
|
|||
selectors: &[SelectorDraft],
|
||||
) -> Result<(), ConfigError> {
|
||||
self.transaction(|document| {
|
||||
let applications = document
|
||||
.get_mut("applications")
|
||||
.and_then(Item::as_array_of_tables_mut)
|
||||
.ok_or_else(|| {
|
||||
ConfigError::validation("applications", "missing application array")
|
||||
})?;
|
||||
let applications = array_of_tables_mut(document, "applications")?;
|
||||
let mut table = Table::new();
|
||||
table["id"] = value(id);
|
||||
table["label"] = value(label);
|
||||
|
|
@ -363,10 +358,7 @@ pickup_tolerance = 0.02
|
|||
members: &[&str],
|
||||
) -> Result<(), ConfigError> {
|
||||
self.transaction(|document| {
|
||||
let groups = document
|
||||
.get_mut("groups")
|
||||
.and_then(Item::as_array_of_tables_mut)
|
||||
.ok_or_else(|| ConfigError::validation("groups", "missing group array"))?;
|
||||
let groups = array_of_tables_mut(document, "groups")?;
|
||||
let mut table = Table::new();
|
||||
table["id"] = value(id);
|
||||
table["label"] = value(label);
|
||||
|
|
@ -423,10 +415,7 @@ pickup_tolerance = 0.02
|
|||
pickup_tolerance: f64,
|
||||
) -> Result<(), ConfigError> {
|
||||
self.transaction(|document| {
|
||||
let faders = document
|
||||
.get_mut("faders")
|
||||
.and_then(Item::as_array_of_tables_mut)
|
||||
.ok_or_else(|| ConfigError::validation("faders", "missing fader array"))?;
|
||||
let faders = array_of_tables_mut(document, "faders")?;
|
||||
let mut table = Table::new();
|
||||
table["id"] = value(id);
|
||||
table["target"] = value(target_table(target_kind, target_id));
|
||||
|
|
@ -716,10 +705,7 @@ pickup_tolerance = 0.02
|
|||
let inferred_feedback = (action == Action::ToggleMute)
|
||||
.then(|| inferred_feedback_values(document, surface, kind))
|
||||
.flatten();
|
||||
let bindings = document
|
||||
.get_mut("bindings")
|
||||
.and_then(Item::as_array_of_tables_mut)
|
||||
.ok_or_else(|| ConfigError::validation("bindings", "missing binding array"))?;
|
||||
let bindings = array_of_tables_mut(document, "bindings")?;
|
||||
let mut table = Table::new();
|
||||
table["surface"] = value(surface);
|
||||
table["fader"] = value(fader);
|
||||
|
|
@ -757,10 +743,7 @@ pickup_tolerance = 0.02
|
|||
let inferred_feedback = (action == Action::ToggleMute)
|
||||
.then(|| inferred_feedback_values(document, surface, kind))
|
||||
.flatten();
|
||||
let bindings = document
|
||||
.get_mut("bindings")
|
||||
.and_then(Item::as_array_of_tables_mut)
|
||||
.ok_or_else(|| ConfigError::validation("bindings", "missing binding array"))?;
|
||||
let bindings = array_of_tables_mut(document, "bindings")?;
|
||||
let matching = bindings
|
||||
.iter()
|
||||
.enumerate()
|
||||
|
|
@ -792,10 +775,13 @@ pickup_tolerance = 0.02
|
|||
/// Removes only the selected fader action assignments.
|
||||
pub fn remove_bindings(&mut self, fader: &str, action: Action) -> Result<(), ConfigError> {
|
||||
self.transaction(|document| {
|
||||
if document.get("bindings").is_none() {
|
||||
return Ok(());
|
||||
}
|
||||
let bindings = document
|
||||
.get_mut("bindings")
|
||||
.and_then(Item::as_array_of_tables_mut)
|
||||
.ok_or_else(|| ConfigError::validation("bindings", "missing binding array"))?;
|
||||
.ok_or_else(|| ConfigError::validation("bindings", "must be an array of tables"))?;
|
||||
bindings.retain(|table| !binding_matches(table, fader, action));
|
||||
Ok(())
|
||||
})
|
||||
|
|
|
|||
|
|
@ -32,6 +32,67 @@ fn target_labels_can_be_renamed_without_changing_routing() {
|
|||
assert_eq!(profile.bindings().len(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn binding_edits_materialize_an_omitted_optional_binding_array() {
|
||||
let source = PROFILE.split("[[bindings]]").next().unwrap();
|
||||
assert!(ProfileDocument::parse(&format!("{source}\n[bindings]\n")).is_err());
|
||||
let mut draft = ProfileDocument::parse(source).unwrap();
|
||||
|
||||
draft
|
||||
.remove_bindings("media-fader", Action::Volume)
|
||||
.unwrap();
|
||||
draft
|
||||
.set_binding(
|
||||
"desk-left",
|
||||
"media-fader",
|
||||
Action::Volume,
|
||||
MessageKind::Cc,
|
||||
1,
|
||||
7,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let profile = draft.preview().unwrap();
|
||||
assert_eq!(profile.bindings().len(), 1);
|
||||
assert_eq!(profile.bindings()[0].fader(), "media-fader");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn object_edits_materialize_omitted_optional_arrays() {
|
||||
let mut draft = ProfileDocument::parse(
|
||||
r#"schema_version = 1
|
||||
id = "minimal"
|
||||
startup = "adopt"
|
||||
new_stream = "adopt"
|
||||
|
||||
[audio]
|
||||
adapter = "auto"
|
||||
preference = ["pulse", "pipewire"]
|
||||
max_gain = 1.0
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
draft
|
||||
.add_application(
|
||||
"music",
|
||||
"Music",
|
||||
&[SelectorDraft {
|
||||
field: SelectorField::ApplicationName,
|
||||
pattern: SelectorPattern::Exact("Music Player".into()),
|
||||
}],
|
||||
)
|
||||
.unwrap();
|
||||
draft.add_group("media", "Media", &["music"]).unwrap();
|
||||
draft
|
||||
.add_fader("media-fader", TargetKind::Group, "media", true, 0.02)
|
||||
.unwrap();
|
||||
|
||||
let profile = draft.preview().unwrap();
|
||||
assert_eq!(profile.applications()[0].id(), "music");
|
||||
assert_eq!(profile.groups()[0].id(), "media");
|
||||
assert_eq!(profile.faders()[0].id(), "media-fader");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mixer_objects_are_created_and_removed_as_atomic_valid_units() {
|
||||
let mut draft = ProfileDocument::empty("default").unwrap();
|
||||
|
|
|
|||
|
|
@ -102,6 +102,12 @@ A profile contains these sections:
|
|||
| `[[mixer_layout]]` | Durable order, separators, visibility, and fader density |
|
||||
| `[[bindings]]` | Surface messages assigned to volume or mute actions |
|
||||
|
||||
The array sections default to empty and may be omitted. The TUI creates a
|
||||
missing section when the first corresponding object or MIDI binding is added;
|
||||
an omitted `[[bindings]]` section is therefore a valid profile, not corruption.
|
||||
If a section is present with the wrong shape or invalid contents, startup fails
|
||||
before activating the profile unless a supported schema migration can upgrade it.
|
||||
|
||||
### Application capture
|
||||
|
||||
Selectors are ORed. Each selector chooses exactly one supported metadata field
|
||||
|
|
|
|||
5
task.md
5
task.md
|
|
@ -73,7 +73,10 @@ Dependencies: M1 types; runtime activation follows in M10.
|
|||
fallback. Private layout creation, effective-owner/symlink checks, mode-0600
|
||||
streaming atomic writes, directory sync, recoverable state loading,
|
||||
comment-preserving validated edits, and backed-up forward migration are
|
||||
covered by seven persistence integration tests.
|
||||
covered by seven persistence integration tests. Optional default-empty profile
|
||||
arrays may remain omitted: editor additions materialize them lazily and empty
|
||||
removals are no-ops, while malformed present sections still fail startup
|
||||
validation.
|
||||
- [x] **M2.3 Checkpoints:** per-profile observed state and separate validated desired object volume/mute, surface assignments, UI preferences, debounce and shutdown flush. Tests with a fake clock: sustained movement causes bounded writes and final state persists; crash/restart treats cached observations as stale, never restores runtime IDs or pending requests; an offline command survives restart as saved intent but only explicit restore applies it when the application launches (adopt emits no write).
|
||||
A runtime-independent monotonic coordinator now keeps only the newest complete
|
||||
snapshot, flushes after 500 ms quiet or two seconds continuously dirty, retries
|
||||
|
|
|
|||
Loading…
Reference in New Issue