-
-
Notifications
You must be signed in to change notification settings - Fork 145
fix(engine): stop search tutors double-firing landfall/ETB observers #6881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CodeOptimist
wants to merge
1
commit into
phase-rs:main
Choose a base branch
from
CodeOptimist:fix/search-landfall-double-fire
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+180
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
crates/engine/tests/integration/search_landfall_double_fire_repro.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| //! Repro for the reported double-fire: casting a search tutor that puts a land | ||
| //! onto the battlefield (Prishe's Wanderings / Nature's Lore pattern) fires each | ||
| //! landfall observer trigger twice for the single land entry. | ||
| //! | ||
| //! A landfall permanent ("Whenever a land enters the battlefield under your | ||
| //! control, <effect>") must produce EXACTLY ONE trigger per land entry. | ||
|
|
||
| use engine::game::scenario::{GameScenario, P0}; | ||
| use engine::types::mana::ManaColor; | ||
| use engine::types::phase::Phase; | ||
| use engine::types::zones::Zone; | ||
|
|
||
| const LANDFALL_ORACLE: &str = | ||
| "Whenever a land enters the battlefield under your control, draw a card."; | ||
|
|
||
| const NATURES_LORE_ORACLE: &str = | ||
| "Search your library for a Forest card, put that card onto the battlefield, then shuffle."; | ||
|
|
||
| fn seed_forest_on_library_top( | ||
| runner: &mut engine::game::scenario::GameRunner, | ||
| ) -> engine::types::identifiers::ObjectId { | ||
| use engine::types::card_type::CoreType; | ||
| let card_id = engine::types::identifiers::CardId(runner.state().next_object_id); | ||
| let id = engine::game::zones::create_object( | ||
| runner.state_mut(), | ||
| card_id, | ||
| P0, | ||
| "Forest".to_string(), | ||
| Zone::Library, | ||
| ); | ||
| let obj = runner.state_mut().objects.get_mut(&id).unwrap(); | ||
| obj.card_types.core_types.push(CoreType::Land); | ||
| obj.base_card_types = obj.card_types.clone(); | ||
| obj.card_types.subtypes.push("Forest".to_string()); | ||
| runner.state_mut().players[P0.0 as usize] | ||
| .library | ||
| .insert(0, id); | ||
| id | ||
| } | ||
|
|
||
| #[test] | ||
| fn landfall_fires_once_per_land_etb_from_search_tutor() { | ||
| let mut scenario = GameScenario::new(); | ||
| scenario.at_phase(Phase::PreCombatMain); | ||
| scenario.add_basic_land(P0, ManaColor::Green); | ||
|
|
||
| // A landfall permanent on the battlefield. | ||
| scenario | ||
| .add_creature_from_oracle(P0, "Landfall Scout", 1, 1, LANDFALL_ORACLE) | ||
| .id(); | ||
|
|
||
| let natures_lore = scenario | ||
| .add_spell_to_hand_from_oracle(P0, "Nature's Lore", false, NATURES_LORE_ORACLE) | ||
| .id(); | ||
|
|
||
| let mut runner = scenario.build(); | ||
| let forest = seed_forest_on_library_top(&mut runner); | ||
| runner.cast(natures_lore).search_first_legal().resolve(); | ||
|
|
||
| // The land entered the battlefield exactly once. | ||
| assert_eq!( | ||
| runner.state().objects[&forest].zone, | ||
| Zone::Battlefield, | ||
| "Nature's Lore must put the searched Forest onto the battlefield" | ||
| ); | ||
|
|
||
| // Drain the search tutor to a priority window so deferred triggers settle. | ||
| runner.advance_until_stack_empty(); | ||
|
|
||
| // Exactly ONE landfall trigger must have fired for the single land entry. | ||
| let landfall_count = runner | ||
| .state() | ||
| .deferred_triggers | ||
| .iter() | ||
| .filter(|ctx| { | ||
| ctx.pending | ||
| .description | ||
| .as_deref() | ||
| .unwrap_or("") | ||
| .contains("Whenever a land enters") | ||
| }) | ||
| .count(); | ||
| assert_eq!( | ||
| landfall_count, | ||
| 1, | ||
| "landfall must fire exactly once per land ETB; deferred=[{:?}]", | ||
| runner | ||
| .state() | ||
| .deferred_triggers | ||
| .iter() | ||
| .map(|c| c.pending.description.clone().unwrap_or_default()) | ||
| .collect::<Vec<_>>() | ||
| ); | ||
| } | ||
|
|
||
| /// The reported shape: TWO separate landfall permanents on the battlefield and | ||
| /// one land entering via a search tutor. Each landfall permanent must fire | ||
| /// exactly ONE trigger for the single land — two total, never four (the | ||
| /// double-fire reported for Sazh's Chocobo + Bird token). | ||
| #[test] | ||
| fn two_landfall_sources_fire_once_each_for_single_search_land() { | ||
| let mut scenario = GameScenario::new(); | ||
| scenario.at_phase(Phase::PreCombatMain); | ||
| scenario.add_basic_land(P0, ManaColor::Green); | ||
|
|
||
| scenario | ||
| .add_creature_from_oracle(P0, "Landfall Scout", 1, 1, LANDFALL_ORACLE) | ||
| .id(); | ||
| scenario | ||
| .add_creature_from_oracle(P0, "Landfall Warden", 2, 2, LANDFALL_ORACLE) | ||
| .id(); | ||
|
|
||
| let natures_lore = scenario | ||
| .add_spell_to_hand_from_oracle(P0, "Nature's Lore", false, NATURES_LORE_ORACLE) | ||
| .id(); | ||
|
|
||
| let mut runner = scenario.build(); | ||
| let forest = seed_forest_on_library_top(&mut runner); | ||
| runner.cast(natures_lore).search_first_legal().resolve(); | ||
| runner.advance_until_stack_empty(); | ||
|
|
||
| // The land entered the battlefield exactly once. | ||
| assert_eq!( | ||
| runner.state().objects[&forest].zone, | ||
| Zone::Battlefield, | ||
| "Nature's Lore must put the searched Forest onto the battlefield" | ||
| ); | ||
|
|
||
| let landfall_count = runner | ||
| .state() | ||
| .deferred_triggers | ||
| .iter() | ||
| .filter(|ctx| { | ||
| ctx.pending | ||
| .description | ||
| .as_deref() | ||
| .unwrap_or("") | ||
| .contains("Whenever a land enters") | ||
| }) | ||
| .count(); | ||
| assert_eq!( | ||
| landfall_count, | ||
| 2, | ||
| "two landfall sources must fire exactly once each for the single land ETB; deferred=[{:?}]", | ||
| runner | ||
| .state() | ||
| .deferred_triggers | ||
| .iter() | ||
| .map(|c| ( | ||
| c.pending.source_id, | ||
| c.pending.description.clone().unwrap_or_default() | ||
| )) | ||
| .collect::<Vec<_>>() | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Assert each landfall source ID.
Lines 106 and 109 discard the source IDs. The aggregate count at lines 129-140 can pass if one source fires twice and the other source does not fire. Retain both IDs. Assert that the matching deferred triggers contain each ID exactly once.
🤖 Prompt for AI Agents
Source: Path instructions