Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,16 @@ pub async fn apply_legacy_config_mutation_with_model_snapshot(
.await
.map_err(|error| error.to_string())?
};
let effective_value = config_service
.get_config(Some(path))
.await
.map_err(|error| error.to_string())?;
// Some fields omit their default (or `None`) when serialized so legacy
// files stay unchanged, so a write that restores it leaves no leaf to read
// back. Report that as null, matching an optional read of the path. Only a
// write that changed the config qualifies: serde drops unknown fields
// without changing anything, and those writes must keep failing loudly.
let effective_value = match config_service.get_config(Some(path)).await {
Ok(value) => value,
Err(crate::util::errors::OpenBitFunError::NotFound(_)) if changed => Value::Null,
Err(error) => return Err(error.to_string()),
};
Ok(AppliedLegacyProductConfig {
changed,
changed_path: path.to_string(),
Expand Down Expand Up @@ -739,6 +745,53 @@ mod tests {
);
}

#[tokio::test]
async fn legacy_mutation_accepts_writes_of_an_omitted_default() {
let (service, _dir) = test_service("legacy-omitted-default").await;
let path = "app.flow_chat.send_during_turn";

let queued = apply_legacy_config_mutation(&service, path, json!("queue"))
.await
.expect("queue write");
assert!(queued.changed);
assert_eq!(queued.effective_value, json!("queue"));

let immediate = apply_legacy_config_mutation(&service, path, json!("immediate"))
.await
.expect("writing the omitted default must not fail its read-back");
assert!(immediate.changed);
assert_eq!(immediate.effective_value, Value::Null);
let config: GlobalConfig = service.get_config(None).await.unwrap();
assert_eq!(
serde_json::to_value(config.app.flow_chat.send_during_turn).unwrap(),
json!("immediate")
);

let cleared_path = "app.flow_chat.last_mode_id";
apply_legacy_config_mutation(&service, cleared_path, json!("Plan"))
.await
.expect("optional write");
let cleared = apply_legacy_config_mutation(&service, cleared_path, Value::Null)
.await
.expect("clearing an optional leaf must not fail its read-back");
assert!(cleared.changed);
assert_eq!(cleared.effective_value, Value::Null);
}

#[tokio::test]
async fn legacy_mutation_still_rejects_paths_the_config_drops() {
let (service, _dir) = test_service("legacy-unknown-path").await;

let error = apply_legacy_config_mutation(
&service,
"app.flow_chat.not_a_known_field",
json!("queue"),
)
.await
.expect_err("a write that serde drops must not report success");
assert!(error.contains("not found"), "{error}");
}

#[tokio::test]
async fn config_handler_round_trips_through_the_shared_service() {
let (service, _dir) = test_service("product-control-round-trip").await;
Expand Down
Loading