Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion crates/tinyflows-bus/src/schedule/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,16 @@ pub struct CronJobPatch {
/// "clear the agent definition" (`Some(None)`). See
/// [`deserialize_double_option`] for why the custom deserializer is required
/// to honor a wire `null` as a clear rather than a silent no-op.
#[serde(default, deserialize_with = "deserialize_double_option")]
///
/// Omitted when serialized for `None`: the custom deserializer reads a
/// present `null` as a clear, so a patch that leaves the agent alone must
/// not write `"agent_id": null` or crossing a serialized boundary (the bus)
/// would turn every unrelated patch into "clear the agent definition".
#[serde(
default,
deserialize_with = "deserialize_double_option",
skip_serializing_if = "Option::is_none"
)]
pub agent_id: Option<Option<String>>,
/// Set (`Some(Some(_))`) or clear (`Some(None)`) the job's origin
/// conversation; `None` leaves it unchanged (and is omitted when
Expand Down
23 changes: 23 additions & 0 deletions crates/tinyflows-bus/src/schedule/wire_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,26 @@ fn job_with_origin_and_run_with_delivery_status_wire_bytes() {
let run: CronRun = serde_json::from_str(run_json).unwrap();
assert_eq!(serde_json::to_string(&run).unwrap(), run_json);
}

/// A patch that does not mention the agent definition must still not mention it
/// after a trip over the wire; only an explicit clear writes `null`.
#[test]
fn an_unrelated_patch_does_not_clear_the_agent_definition_on_a_round_trip() {
let untouched = CronJobPatch {
enabled: Some(false),
..CronJobPatch::default()
};
let wire = serde_json::to_value(&untouched).unwrap();
assert!(wire.get("agent_id").is_none(), "{wire}");
let back: CronJobPatch = serde_json::from_value(wire).unwrap();
assert_eq!(back.agent_id, None);

let cleared = CronJobPatch {
agent_id: Some(None),
..CronJobPatch::default()
};
let wire = serde_json::to_value(&cleared).unwrap();
assert_eq!(wire["agent_id"], serde_json::Value::Null);
let back: CronJobPatch = serde_json::from_value(wire).unwrap();
assert_eq!(back.agent_id, Some(None));
}
Loading