Fix nullable stored-history constructor switching
Rust checks / check (ubuntu-latest) (push) Canceled after 0s
Rust checks / check (windows-latest) (push) Canceled after 0s

This commit is contained in:
Codex
2026-09-10 11:13:27 -07:00
parent 01bb52a76d
commit b6b76efc0d
5 changed files with 239 additions and 4 deletions
@@ -382,6 +382,45 @@ fn branch_has_fields(schema: &'static Value) -> bool {
.is_none_or(|values| values.len() > 1)
}
/// Constructor identity is independent of a primitive's edited content. In
/// particular, absent, an empty UUID/text, a number and a list are different
/// branches. String enum tags and externally tagged objects retain their variant.
pub(super) fn constructor_tag(path: &str, value: &Value) -> String {
fn enum_value(schema: &'static Value, value: &Value, depth: usize) -> bool {
if depth > MAX_DEPTH {
return false;
}
let Ok(schema) = resolve(schema) else {
return false;
};
if let Some(options) = alternatives(schema) {
return options
.iter()
.any(|option| enum_value(option, value, depth + 1));
}
schema
.get("enum")
.and_then(Value::as_array)
.is_some_and(|values| values.contains(value))
}
match value {
Value::Null => "null".into(),
Value::Bool(_) => "boolean".into(),
Value::Number(_) => "number".into(),
Value::Array(_) => "array".into(),
Value::String(word)
if schema_at(path).is_some_and(|schema| enum_value(schema, value, 0)) =>
{
format!("enum:{word}")
}
Value::String(_) => "string".into(),
Value::Object(fields) => format!(
"object:{}",
fields.keys().cloned().collect::<Vec<_>>().join("/")
),
}
}
fn paging<'a>(draft: &'a Draft, path: &str, count: usize) -> (usize, View<'a, Message>) {
let last = count.saturating_sub(1) / PAGE_SIZE;
let page = draft