Skip to content

ship/cr733 p2 counters ledgers - #6521

Merged
matthewevans merged 5 commits into
mainfrom
ship/cr733-p2-counters-ledgers
Jul 22, 2026
Merged

ship/cr733 p2 counters ledgers#6521
matthewevans merged 5 commits into
mainfrom
ship/cr733-p2-counters-ledgers

Conversation

@matthewevans

@matthewevans matthewevans commented Jul 22, 2026

Copy link
Copy Markdown
Member
  • cr733(p2): apply resolved counter and ledger commands
  • cr733(p2): record counter and ledger tranche
  • cr733(p2): drop unused u8 turn-count binding in ledger invalid pre-screen
  • cr733(p2): fix test-module path for trigger occurrence refs
  • cr733(p2): scope trigger-occurrence ref imports to the test module

Summary by CodeRabbit

  • New Features

    • Added reliable tracking for spell casts, activated abilities, trigger limits, and once-per-turn permissions.
    • Added support for recording and replaying counter changes while preserving game state and related effects.
  • Bug Fixes

    • Improved validation for repeated, stale, invalid, or out-of-order game actions.
    • Ensured zero-value counter changes behave as harmless no-ops.
    • Improved consistency when replaying gameplay history and rejecting duplicate updates.

…reen

The SpellCast arm of ledger_edit_is_invalid destructured expected_turn_count
(u8) but never used it — the u32::MAX sentinel screen only applies to the u32
count fields. A u8 advanced via saturating_add treats 255 as a legitimate
saturated value, not a reserved sentinel, so the field has no invalid state to
pre-screen. Drop it from the pattern (already covered by ..) and document why.

Fixes -D unused-variables clippy failure on the counters/ledgers tranche.
The TriggerFired ledger test qualified TriggerDefinitionOccurrenceRef and
TriggerBaseSetInstanceRef as super::ability::* from inside #[cfg(test)] mod
tests, where super resolves to resolved_commands (no ability submodule) rather
than crate::types. Import both siblings alongside the already-imported
TriggerDefinitionRef and reference them bare, matching the test's own usage.

This E0433 was masked by the disk-full failure that aborted Run 7's test-engine
gate before the test binary compiled.
TriggerDefinitionOccurrenceRef and TriggerBaseSetInstanceRef are used only by
the TriggerFired ledger test, so importing them at module scope tripped
-D unused-imports in the non-test lib build. Move them into mod tests alongside
the existing crate::types::* test imports; TriggerDefinitionRef stays top-level
since production code uses it too.
@matthewevans
matthewevans enabled auto-merge July 22, 2026 23:16
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e4f9420e-8ce9-477e-83ed-159ca37ec40b

📥 Commits

Reviewing files that changed from the base of the PR and between ddf2cf2 and d2aed44.

📒 Files selected for processing (11)
  • .agents/cr733/RUN7-REPORT.md
  • crates/engine/src/game/casting_costs.rs
  • crates/engine/src/game/effects/counters.rs
  • crates/engine/src/game/engine.rs
  • crates/engine/src/game/ledger.rs
  • crates/engine/src/game/mod.rs
  • crates/engine/src/game/restrictions.rs
  • crates/engine/src/game/triggers.rs
  • crates/engine/src/types/mod.rs
  • crates/engine/src/types/resolved_commands.rs
  • crates/engine/tests/integration/cr733_resolved_commands_p2.rs

📝 Walkthrough

Walkthrough

Adds journaled object-counter and ledger-edit commands with strict replay validation. Counter mutations now use an exact applier, while spell casts, abilities, triggers, and once-per-turn permissions route through centralized ledger helpers with expanded replay tests.

Changes

Resolved command replay

Layer / File(s) Summary
Command contracts and validation
crates/engine/src/types/resolved_commands.rs, crates/engine/src/types/mod.rs, crates/engine/src/game/mod.rs
Adds object-counter and ledger command payloads, replay errors, journal methods, public exports, and validation for malformed, legacy, sentinel, and predecessor-invalid commands.
Exact counter delivery
crates/engine/src/game/effects/counters.rs
Routes counter additions and removals through an incarnation-aware applier that validates preconditions, updates derived characteristics, prunes counters, marks layers dirty, and records additions.
Ledger authority and integrations
crates/engine/src/game/ledger.rs, crates/engine/src/game/restrictions.rs, crates/engine/src/game/triggers.rs, crates/engine/src/game/engine.rs, crates/engine/src/game/casting_costs.rs
Centralizes spell-cast, ability, trigger, and once-per-turn permission accounting through validated ledger edits.
Replay coverage and tranche record
crates/engine/tests/integration/cr733_resolved_commands_p2.rs, .agents/cr733/RUN7-REPORT.md
Adds counter and ledger replay tests, duplicate/stale application checks, zero-count coverage, and records tranche scope and verification details.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GameRules
  participant Ledger
  participant CounterApplier
  participant GameState
  participant ResolvedRulesJournal
  GameRules->>Ledger: record spell, ability, trigger, or permission fact
  Ledger->>GameState: validate ledger preconditions and mutate state
  Ledger->>ResolvedRulesJournal: append ledger command
  GameRules->>CounterApplier: apply resolved counter command
  CounterApplier->>GameState: validate incarnation and counter predecessor
  CounterApplier->>ResolvedRulesJournal: append counter command
Loading

Possibly related PRs

  • phase-rs/phase#6336: Extends the same resolved-command and journal infrastructure from mana commands to object counters and ledger edits.
  • phase-rs/phase#6339: Adds adjacent PlayerEdit and ObjectStatus command variants within the same validation framework.

Suggested labels: enhancement

Suggested reviewers: lgray, kiannidev

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is related to the change, but it is too terse and generic to clearly describe the main update. Use a clearer title that names the core change, such as resolved counter and ledger command support for CR733 P2.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.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-p2-counters-ledgers

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

@matthewevans
matthewevans added this pull request to the merge queue Jul 22, 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 ee90409 Jul 22, 2026
15 checks passed
@matthewevans
matthewevans deleted the ship/cr733-p2-counters-ledgers branch July 22, 2026 23:52
jsdevninja pushed a commit to jsdevninja/phase that referenced this pull request Jul 24, 2026
* cr733(p2): apply resolved counter and ledger commands

* cr733(p2): record counter and ledger tranche

* cr733(p2): drop unused u8 turn-count binding in ledger invalid pre-screen

The SpellCast arm of ledger_edit_is_invalid destructured expected_turn_count
(u8) but never used it — the u32::MAX sentinel screen only applies to the u32
count fields. A u8 advanced via saturating_add treats 255 as a legitimate
saturated value, not a reserved sentinel, so the field has no invalid state to
pre-screen. Drop it from the pattern (already covered by ..) and document why.

Fixes -D unused-variables clippy failure on the counters/ledgers tranche.

* cr733(p2): fix test-module path for trigger occurrence refs

The TriggerFired ledger test qualified TriggerDefinitionOccurrenceRef and
TriggerBaseSetInstanceRef as super::ability::* from inside #[cfg(test)] mod
tests, where super resolves to resolved_commands (no ability submodule) rather
than crate::types. Import both siblings alongside the already-imported
TriggerDefinitionRef and reference them bare, matching the test's own usage.

This E0433 was masked by the disk-full failure that aborted Run 7's test-engine
gate before the test binary compiled.

* cr733(p2): scope trigger-occurrence ref imports to the test module

TriggerDefinitionOccurrenceRef and TriggerBaseSetInstanceRef are used only by
the TriggerFired ledger test, so importing them at module scope tripped
-D unused-imports in the non-test lib build. Move them into mod tests alongside
the existing crate::types::* test imports; TriggerDefinitionRef stays top-level
since production code uses it too.

---------

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