Skip to content

cr733(p2): journal cost-settlement consume-before-priority occurrences#6558

Merged
matthewevans merged 1 commit into
mainfrom
ship/cr733-consumed-before-priority
Jul 23, 2026
Merged

cr733(p2): journal cost-settlement consume-before-priority occurrences#6558
matthewevans merged 1 commit into
mainfrom
ship/cr733-consumed-before-priority

Conversation

@matthewevans

@matthewevans matthewevans commented Jul 23, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes

    • Fixed trigger handling during sacrifice and mana-cost settlement.
    • Ensured triggered abilities are collected exactly once when replacement choices pause an action.
    • Improved journal tracking so consumed trigger events remain accurate after resuming settlement.
  • Tests

    • Added regression coverage for paused cost settlement, replacement choices, zone changes, and trigger collection.

@matthewevans
matthewevans enabled auto-merge July 23, 2026 18:19
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Cost settlement now resolves consumed-before-priority trigger occurrences through resolve_and_apply_trigger_collection. Integration tests cover paused mana and sacrifice settlements, replacement choices, journal entries, and prevention of duplicate trigger collection.

Changes

Consumed-trigger settlement

Layer / File(s) Summary
Route consumed occurrences through trigger resolution
crates/engine/src/game/casting_costs.rs, crates/engine/src/game/mana_abilities.rs
Mana and sacrifice cost settlement now submit ConsumeBeforePriority occurrences to the shared trigger resolver and require a live journal cause.
Validate paused settlement journaling
crates/engine/tests/integration/cr733_resolved_trigger_collection.rs
Helpers and regression tests verify exact journaled occurrences and single trigger collection across paused mana-cost and sacrifice-cost settlement flows.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CostSettlement
  participant TriggerResolver
  participant ResolvedRulesJournal
  CostSettlement->>TriggerResolver: submit ConsumeBeforePriority occurrences
  TriggerResolver->>ResolvedRulesJournal: record TriggerCollection command
  TriggerResolver-->>CostSettlement: apply collected triggers
Loading

Possibly related PRs

  • phase-rs/phase#6536: Adds related consumed-before-priority trigger-collection journaling infrastructure.

Suggested labels: bug

Suggested reviewers: bitfathers94, lgray, ntindle

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: journaling consume-before-priority occurrences during cost settlement.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ship/cr733-consumed-before-priority

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
crates/engine/src/game/casting_costs.rs (1)

2387-2400: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the consumed-occurrence builder into one shared helper. Both cost-settlement sites build Vec<ConsumedTriggerEventOccurrence> with identical prefix-count semantics; keeping two copies risks divergence of the dedup index. A single helper (e.g. crate::game::triggers::consumed_occurrences(events: &[GameEvent], start: usize, end: usize)) covers both slice shapes.

  • crates/engine/src/game/casting_costs.rs#L2387-L2400: replace the inline loop with a call passing current_start/current_end.
  • crates/engine/src/game/mana_abilities.rs#L2494-L2507: replace the skip(current_start) inline loop with the same helper passing current_start and events.len().
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/engine/src/game/casting_costs.rs` around lines 2387 - 2400, Extract
the shared prefix-count construction into a helper such as consumed_occurrences
in the triggers module, accepting events, start, and end and returning
Vec<ConsumedTriggerEventOccurrence>. In
crates/engine/src/game/casting_costs.rs:2387-2400, replace the inline builder
with the helper using current_start and current_end; in
crates/engine/src/game/mana_abilities.rs:2494-2507, replace the skip-based
builder with the same helper using current_start and events.len().

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/engine/tests/integration/cr733_resolved_trigger_collection.rs`:
- Around line 93-105: Update current_action_occurrences and its fixtures so
occurrence indices match the full events prefix used by both settle_* call
sites, including events before current_start. Add a genuinely repeated GameEvent
to the fixture and ensure the expected occurrences assert a non-zero dedup
index, exercising ConsumeBeforePriority behavior.

---

Nitpick comments:
In `@crates/engine/src/game/casting_costs.rs`:
- Around line 2387-2400: Extract the shared prefix-count construction into a
helper such as consumed_occurrences in the triggers module, accepting events,
start, and end and returning Vec<ConsumedTriggerEventOccurrence>. In
crates/engine/src/game/casting_costs.rs:2387-2400, replace the inline builder
with the helper using current_start and current_end; in
crates/engine/src/game/mana_abilities.rs:2494-2507, replace the skip-based
builder with the same helper using current_start and events.len().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 19484ce8-ea28-42d7-a130-f068fb1a4408

📥 Commits

Reviewing files that changed from the base of the PR and between e731b73 and 690b3a0.

📒 Files selected for processing (3)
  • crates/engine/src/game/casting_costs.rs
  • crates/engine/src/game/mana_abilities.rs
  • crates/engine/tests/integration/cr733_resolved_trigger_collection.rs

Comment on lines +93 to +105
fn current_action_occurrences(events: &[GameEvent]) -> Vec<ConsumedTriggerEventOccurrence> {
events
.iter()
.enumerate()
.map(|(index, event)| ConsumedTriggerEventOccurrence {
event: event.clone(),
occurrence: events[..index]
.iter()
.filter(|prior| *prior == event)
.count(),
})
.collect()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Helper occurrence semantics diverge from production; assertion may not exercise the dedup index.

current_action_occurrences counts prior identical events only within the passed slice, whereas both settle_* sites count over the full events prefix (events[..index] including pre-current_start events). These agree here only because every fixture event is unique, so occurrence is always 0. That means the occurrences == &expected assertion never actually validates a non-zero dedup index — the core behavior of ConsumeBeforePriority. Consider a fixture that emits a genuinely repeated GameEvent so a non-zero occurrence is asserted, or align the helper to the production global-prefix semantics.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/engine/tests/integration/cr733_resolved_trigger_collection.rs` around
lines 93 - 105, Update current_action_occurrences and its fixtures so occurrence
indices match the full events prefix used by both settle_* call sites, including
events before current_start. Add a genuinely repeated GameEvent to the fixture
and ensure the expected occurrences assert a non-zero dedup index, exercising
ConsumeBeforePriority behavior.

Source: Path instructions

@matthewevans
matthewevans added this pull request to the merge queue Jul 23, 2026
@github-actions

Copy link
Copy Markdown

Parse changes introduced by this PR

✓ No card-parse changes detected.

Merged via the queue into main with commit 1dd966a Jul 23, 2026
15 checks passed
@matthewevans
matthewevans deleted the ship/cr733-consumed-before-priority branch July 23, 2026 19:13
jsdevninja pushed a commit to jsdevninja/phase that referenced this pull request Jul 24, 2026
phase-rs#6558)

Co-authored-by: matthewevans <matthewevans@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant