huskies: merge 1062
This commit is contained in:
@@ -533,4 +533,48 @@ mod tests {
|
||||
let args = serde_json::json!({ "mode": "persistent" });
|
||||
assert_eq!(parse_mode(&args), FireMode::Persistent);
|
||||
}
|
||||
|
||||
/// Regression test: once-mode triggers with a server-restarting action (e.g.
|
||||
/// rebuild_and_restart) must be removed from the store BEFORE the action is
|
||||
/// dispatched. If cancellation happens after dispatch, a server restart
|
||||
/// caused by the action reloads the persisted store and replays the trigger.
|
||||
#[test]
|
||||
fn once_mode_rebuild_trigger_cancelled_before_action() {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let path = dir.path().join("triggers.json");
|
||||
let store = EventTriggerStore::load(path.clone());
|
||||
|
||||
let trigger = store
|
||||
.add(
|
||||
TriggerPredicate {
|
||||
story_id: None,
|
||||
from_stage: None,
|
||||
to_stage: Some("Current".to_string()),
|
||||
event_kind: None,
|
||||
},
|
||||
TriggerAction::Mcp {
|
||||
method: "rebuild_and_restart".to_string(),
|
||||
args: serde_json::json!({}),
|
||||
},
|
||||
FireMode::Once,
|
||||
)
|
||||
.unwrap();
|
||||
let id = trigger.id.clone();
|
||||
|
||||
// Simulate the subscriber: cancel BEFORE the action runs.
|
||||
store.cancel(&id);
|
||||
|
||||
// Trigger must be absent immediately (simulates "right after match").
|
||||
assert!(
|
||||
store.list().is_empty(),
|
||||
"once-mode trigger must be absent before its action fires"
|
||||
);
|
||||
|
||||
// Simulate server restart: reload from persisted store.
|
||||
let reloaded = EventTriggerStore::load(path);
|
||||
assert!(
|
||||
reloaded.list().is_empty(),
|
||||
"trigger must not survive a server restart caused by its own action"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user