Skip to content

Commit 3d1e081

Browse files
committed
fix(settings): expose inherited boolean and list values explicitly
1 parent 337ec2a commit 3d1e081

3 files changed

Lines changed: 43 additions & 15 deletions

File tree

‎rust/crates/plugin-model/src/settings/sources.rs‎

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -396,18 +396,34 @@ pub fn state_command(payload: Value) -> Result<Value, CoreError> {
396396
)
397397
})
398398
.collect();
399-
let effective_displays:BTreeMap<_,BTreeMap<_,Value>>=snapshot.sources.iter().map(|source|{
400-
(source.id.clone(),source.fields.iter().filter(|field|!field.value.is_null()&&field.value!=field.effective_value).map(|field|{
401-
let value=&field.effective_value;
402-
let display=if value.is_null(){json!({"kind":"unknown"})}else{match field.kind.as_str(){
403-
"enum"=>json!({"kind":"text","text":field.options.iter().find(|option|Some(option.value.as_str())==value.as_str()).map(|option|option.title.as_str()).unwrap_or_default()}),
404-
"boolean"=>json!({"kind":"boolean","on":value.as_bool().unwrap_or_default()}),
405-
"fileList"|"stringList"=>json!({"kind":"list","count":value.as_array().map_or(0,Vec::len)}),
406-
_=>json!({"kind":"text","text":value.as_str().unwrap_or_default()}),
407-
}};
408-
(field.id.clone(),display)
409-
}).collect())
410-
}).collect();
399+
let effective_displays: BTreeMap<_, BTreeMap<_, Value>> = snapshot
400+
.sources
401+
.iter()
402+
.map(|source| {
403+
let displays = source.fields.iter().filter(|field| {
404+
(field.value.is_null() && field.kind != "enum")
405+
|| (!field.value.is_null() && field.value != field.effective_value)
406+
}).map(|field| {
407+
let value = &field.effective_value;
408+
let mut display = if value.is_null() {
409+
json!({"kind":"unknown"})
410+
} else {
411+
match field.kind.as_str() {
412+
"enum" => {
413+
let title = field.options.iter().find(|option| Some(option.value.as_str()) == value.as_str())
414+
.map(|option| option.title.as_str()).unwrap_or_default();
415+
json!({"kind":"text","text":title})
416+
}
417+
"boolean" => json!({"kind":"boolean","on":value.as_bool().unwrap_or_default()}),
418+
"fileList" | "stringList" => json!({"kind":"list","count":value.as_array().map_or(0, Vec::len)}),
419+
_ => json!({"kind":"text","text":value.as_str().unwrap_or_default()}),
420+
}
421+
};
422+
display["inherited"] = json!(field.value.is_null());
423+
(field.id.clone(), display)
424+
}).collect();
425+
(source.id.clone(), displays)
426+
}).collect();
411427
let layout: Vec<_> = snapshot
412428
.groups
413429
.iter()

‎rust/crates/plugin-model/src/settings/sources/tests.rs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ fn inheritance_and_current_effective_values_remain_distinct_from_an_override() {
149149
);
150150
assert_eq!(
151151
result["state"]["effectiveDisplays"]["child"]["target"],
152-
json!({"kind":"text","text":"Version 1"})
152+
json!({"kind":"text","text":"Version 1","inherited":false})
153+
);
154+
}
155+
156+
#[test]
157+
fn absent_boolean_values_expose_inheritance_and_unknown_effective_values() {
158+
let mut fixture = snapshot();
159+
fixture["sources"][0]["fields"][1]["value"] = Value::Null;
160+
fixture["sources"][0]["fields"][1]["effectiveValue"] = Value::Null;
161+
let result = state_command(json!({"result":fixture})).unwrap();
162+
assert_eq!(
163+
result["state"]["effectiveDisplays"]["root"]["checks"],
164+
json!({"kind":"unknown","inherited":true})
153165
);
154166
}

‎shared/plugins/contract/v1/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,8 @@ model inputs or logs. The host presents inherited values without creating an
656656
override, maintains drafts and displays each confirmed target path. Core
657657
`plugins.settings.sourceState` supplies `inputs`, `inheritedInputs`, ordered
658658
`layout`, native I/O `limits`, and `effectiveDisplays`. The latter describes
659-
actual values differing from explicit raw values as `unknown`, `text`,
660-
`boolean`, or list `count`; the host localizes these presentation hints.
659+
inherited non-enum values and actual values differing from explicit raw values as `unknown`, `text`,
660+
`boolean`, or list `count`, with an `inherited` flag; the host localizes these presentation hints.
661661

662662
On explicit Save the host uses `plugins.settings.sourceEdit` to derive only
663663
changed raw fields. It captures each target with a bounded native reader,

0 commit comments

Comments
 (0)