ship/sealed pack opening - #7149
Conversation
|
Warning Review limit reached
Next review available in: 13 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughThe draft engine now provides grouped pools and sealed packs through protocol version 9. The client adds sealed setup, sequential pack opening, pool review, deckbuilding completion, translated labels, and persisted opening-phase handling. ChangesSealed draft opening flow
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
crates/server-core/src/protocol.rs (1)
2090-2120: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winExercise populated
sealed_packson theDraftStateUpdatewire path.Line 2098 sets
sealed_packstoNone, so this round-trip only covers the empty case. Build a SealedDraftPlayerViewwith multiple non-empty packs, serialize and deserialize it throughServerMessage::DraftStateUpdate, and assert the decoded value preserves card order and pack boundaries. Add equivalent coverage for WebSocket JSON transport as well.🤖 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/server-core/src/protocol.rs` around lines 2090 - 2120, Update the DraftStateUpdate round-trip test around DraftPlayerView to use DraftStatus::Sealed with multiple non-empty sealed_packs, then assert deserialization preserves each pack’s card order and boundaries. Add equivalent assertions through the WebSocket JSON transport test path, reusing the same populated sealed-pack fixture where appropriate.Source: Path instructions
🤖 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 `@client/src/components/draft/poolGrouping.ts`:
- Around line 14-116: The draft-pool classification logic currently lives in the
frontend; move color/type/CMC grouping, ordering, and duplicate identity into
the engine and expose typed pre-grouped pool data. Replace primaryType parsing
and the helpers used by groupDraftPool with the engine-provided model, then map
group kinds to localized labels only at the rendering boundary. Update both
PoolPanel and SealedPackOpening to consume the shared engine grouping.
In `@client/src/i18n/locales/de/draft.json`:
- Around line 85-97: Translate the sealed-flow messages, preserving keys and
interpolation placeholders: in client/src/i18n/locales/de/draft.json ranges
85-97, 145-148, and 179; client/src/i18n/locales/es/draft.json ranges 85-97,
145-148, and 179; client/src/i18n/locales/fr/draft.json ranges 85-97, 145-148,
and 179; and client/src/i18n/locales/it/draft.json ranges 85-97, 145-148, and
179. Translate sealedOpening, landing.sealed.description, and quickPhase.opening
into each locale without changing the JSON structure or placeholder names.
In `@client/src/i18n/locales/pl/draft.json`:
- Around line 85-97: Translate all sealed-pack UI strings currently in English:
update the sealedOpening values in client/src/i18n/locales/pl/draft.json:85-97
and client/src/i18n/locales/pt/draft.json:85-97 into Polish and Portuguese
respectively; also translate landing.sealed.description at
client/src/i18n/locales/pl/draft.json:145-148 and
client/src/i18n/locales/pt/draft.json:145-148, plus quickPhase.opening at
client/src/i18n/locales/pl/draft.json:177-179 and
client/src/i18n/locales/pt/draft.json:177-179. Preserve all interpolation
placeholders such as current, total, count, and the existing locale structure.
---
Outside diff comments:
In `@crates/server-core/src/protocol.rs`:
- Around line 2090-2120: Update the DraftStateUpdate round-trip test around
DraftPlayerView to use DraftStatus::Sealed with multiple non-empty sealed_packs,
then assert deserialization preserves each pack’s card order and boundaries. Add
equivalent assertions through the WebSocket JSON transport test path, reusing
the same populated sealed-pack fixture where appropriate.
🪄 Autofix
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: 0283da89-dfa0-4a37-bf54-ef2a01b73e28
⛔ Files ignored due to path filters (2)
client/public/changelog-meta.jsonis excluded by!client/public/changelog*.jsonclient/public/changelog.jsonis excluded by!client/public/changelog*.json
📒 Files selected for processing (20)
client/src/adapter/draft-adapter.tsclient/src/components/draft/DraftSteps.tsxclient/src/components/draft/PoolPanel.tsxclient/src/components/draft/SealedPackOpening.tsxclient/src/components/draft/__tests__/SealedPackOpening.test.tsxclient/src/components/draft/poolGrouping.tsclient/src/i18n/locales/de/draft.jsonclient/src/i18n/locales/en/draft.jsonclient/src/i18n/locales/es/draft.jsonclient/src/i18n/locales/fr/draft.jsonclient/src/i18n/locales/it/draft.jsonclient/src/i18n/locales/pl/draft.jsonclient/src/i18n/locales/pt/draft.jsonclient/src/pages/DraftLandingPage.tsxclient/src/pages/DraftPage.tsxclient/src/services/quickDraftPersistence.tsclient/src/stores/draftStore.tscrates/draft-core/src/view.rscrates/server-core/src/protocol.rsscripts/changelog/state.json
| function colorGroupKey(card: DraftCardInstance): string { | ||
| if (card.colors.length === 0) return "Colorless"; | ||
| if (card.colors.length > 1) return "Multicolor"; | ||
| return card.colors[0]; | ||
| } | ||
|
|
||
| const COLOR_GROUP_ORDER: Record<string, number> = { | ||
| W: 0, U: 1, B: 2, R: 3, G: 4, Multicolor: 5, Colorless: 6, | ||
| }; | ||
|
|
||
| const COLOR_GROUP_LABELS: Record<string, string> = { | ||
| W: "White", U: "Blue", B: "Black", R: "Red", G: "Green", | ||
| Multicolor: "Multicolor", Colorless: "Colorless", | ||
| }; | ||
|
|
||
| function primaryType(typeLine: string): string { | ||
| const lower = typeLine.toLowerCase(); | ||
| if (lower.includes("creature")) return "Creature"; | ||
| if (lower.includes("instant")) return "Instant"; | ||
| if (lower.includes("sorcery")) return "Sorcery"; | ||
| if (lower.includes("enchantment")) return "Enchantment"; | ||
| if (lower.includes("artifact")) return "Artifact"; | ||
| if (lower.includes("planeswalker")) return "Planeswalker"; | ||
| if (lower.includes("land")) return "Land"; | ||
| return "Other"; | ||
| } | ||
|
|
||
| const TYPE_ORDER: Record<string, number> = { | ||
| Creature: 0, Instant: 1, Sorcery: 2, Enchantment: 3, | ||
| Artifact: 4, Planeswalker: 5, Land: 6, Other: 7, | ||
| }; | ||
|
|
||
| function dedup(cards: DraftCardInstance[]): DraftPoolEntry[] { | ||
| const map = new Map<string, DraftPoolEntry>(); | ||
| for (const card of cards) { | ||
| const existing = map.get(card.name); | ||
| if (existing) { | ||
| existing.count++; | ||
| } else { | ||
| map.set(card.name, { card, count: 1 }); | ||
| } | ||
| } | ||
| return [...map.values()]; | ||
| } | ||
|
|
||
| function sortWithinGroup(cards: DraftCardInstance[]): DraftPoolEntry[] { | ||
| const sorted = [...cards].sort((a, b) => a.cmc - b.cmc || a.name.localeCompare(b.name)); | ||
| return dedup(sorted); | ||
| } | ||
|
|
||
| function groupByColor(pool: DraftCardInstance[]): DraftPoolGroup[] { | ||
| const groups = new Map<string, DraftCardInstance[]>(); | ||
| for (const card of pool) { | ||
| const key = colorGroupKey(card); | ||
| const list = groups.get(key) ?? []; | ||
| list.push(card); | ||
| groups.set(key, list); | ||
| } | ||
| return [...groups.entries()] | ||
| .sort(([a], [b]) => (COLOR_GROUP_ORDER[a] ?? 99) - (COLOR_GROUP_ORDER[b] ?? 99)) | ||
| .map(([key, cards]) => ({ | ||
| label: COLOR_GROUP_LABELS[key] ?? key, | ||
| cards: sortWithinGroup(cards), | ||
| })); | ||
| } | ||
|
|
||
| export function groupDraftPoolByType(pool: DraftCardInstance[]): DraftPoolGroup[] { | ||
| const groups = new Map<string, DraftCardInstance[]>(); | ||
| for (const card of pool) { | ||
| const key = primaryType(card.type_line); | ||
| const list = groups.get(key) ?? []; | ||
| list.push(card); | ||
| groups.set(key, list); | ||
| } | ||
| return [...groups.entries()] | ||
| .sort(([a], [b]) => (TYPE_ORDER[a] ?? 99) - (TYPE_ORDER[b] ?? 99)) | ||
| .map(([label, cards]) => ({ label, cards: sortWithinGroup(cards) })); | ||
| } | ||
|
|
||
| function groupByCmc(pool: DraftCardInstance[]): DraftPoolGroup[] { | ||
| const groups = new Map<string, DraftCardInstance[]>(); | ||
| for (const card of pool) { | ||
| const key = card.cmc >= 6 ? "6+" : String(card.cmc); | ||
| const list = groups.get(key) ?? []; | ||
| list.push(card); | ||
| groups.set(key, list); | ||
| } | ||
| const cmcOrder = ["0", "1", "2", "3", "4", "5", "6+"]; | ||
| return cmcOrder | ||
| .filter((key) => groups.has(key)) | ||
| .map((key) => ({ | ||
| label: `${key} CMC`, | ||
| cards: dedup([...groups.get(key)!].sort((a, b) => a.name.localeCompare(b.name))), | ||
| })); | ||
| } | ||
|
|
||
| export function groupDraftPool(pool: DraftCardInstance[], mode: PoolSortMode): DraftPoolGroup[] { | ||
| switch (mode) { | ||
| case "color": return groupByColor(pool); | ||
| case "type": return groupDraftPoolByType(pool); | ||
| case "cmc": return groupByCmc(pool); | ||
| } | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Move draft-pool classification into the engine.
These functions derive color groups, type groups, CMC groups, ordering, and duplicate identity from card data. primaryType also parses Oracle type lines in the frontend. For example, an Artifact Creature always enters the Creature group because of this client-defined priority.
Expose typed, pre-grouped pool data from the engine. Map its group kind to localized UI labels at the rendering boundary. Reuse that model in both PoolPanel and SealedPackOpening.
🤖 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 `@client/src/components/draft/poolGrouping.ts` around lines 14 - 116, The
draft-pool classification logic currently lives in the frontend; move
color/type/CMC grouping, ordering, and duplicate identity into the engine and
expose typed pre-grouped pool data. Replace primaryType parsing and the helpers
used by groupDraftPool with the engine-provided model, then map group kinds to
localized labels only at the rendering boundary. Update both PoolPanel and
SealedPackOpening to consume the shared engine grouping.
Source: Path instructions
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (4)
client/src/components/draft/PoolPanel.tsx (1)
88-96: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueMake the sort-mode selection exhaustive.
The nested ternary treats any value other than
"color"and"type"as the CMC grouping. IfpoolSortModegains a mode, the panel silently renders CMC groups instead of failing the type check. A keyed lookup makes the union exhaustive and removes the nesting.♻️ Proposed refactor
- const groups = view - ? poolSortMode === "color" - ? view.pool_groups.color_groups - : poolSortMode === "type" - ? view.pool_groups.type_groups - : view.pool_groups.cmc_groups - : []; + const GROUPS_BY_SORT_MODE = { + color: "color_groups", + type: "type_groups", + cmc: "cmc_groups", + } as const; + const groups = view ? view.pool_groups[GROUPS_BY_SORT_MODE[poolSortMode]] : [];Declare
GROUPS_BY_SORT_MODEat module scope next toCOLOR_COUNT_KEYS.🤖 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 `@client/src/components/draft/PoolPanel.tsx` around lines 88 - 96, Replace the nested sort-mode ternary in PoolPanel with a module-scope GROUPS_BY_SORT_MODE keyed by every PoolSortMode value, declared alongside COLOR_COUNT_KEYS. Use the keyed lookup for view.pool_groups so adding a new mode requires updating the mapping and preserves exhaustive type checking.crates/draft-core/src/view.rs (2)
433-478: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueReplace the
sort_by_cmc: boolparameter with a typed ordering enum.
groups_forandsorted_entriestake a positionalboolthat encodes the sort key. At the call sites ingrouped_pool, the literalstrue,true,falsecarry no meaning at a glance. A small enum makes the intent explicit and lets the compiler check new orderings later.♻️ Proposed refactor
+enum EntryOrder { + ManaValueThenName, + Name, +} + fn grouped_pool(pool: &[DraftCardInstance]) -> DraftPoolGroups { DraftPoolGroups { - color_groups: groups_for(pool, &COLOR_GROUP_ORDER, color_group, true), - type_groups: groups_for(pool, &TYPE_GROUP_ORDER, type_group, true), - cmc_groups: groups_for(pool, &CMC_GROUP_ORDER, mana_value_group, false), + color_groups: groups_for(pool, &COLOR_GROUP_ORDER, color_group, EntryOrder::ManaValueThenName), + type_groups: groups_for(pool, &TYPE_GROUP_ORDER, type_group, EntryOrder::ManaValueThenName), + cmc_groups: groups_for(pool, &CMC_GROUP_ORDER, mana_value_group, EntryOrder::Name), color_counts: color_counts(pool), } }Then match on
EntryOrderinsidesorted_entriesinstead of branching on the flag.🤖 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/draft-core/src/view.rs` around lines 433 - 478, Replace the positional sort_by_cmc boolean in groups_for and sorted_entries with a typed EntryOrder enum that represents the supported sort keys. Update grouped_pool call sites to pass the appropriate enum variant instead of true or false, and match on EntryOrder inside sorted_entries while preserving the existing CMC-then-name and name-only ordering behavior.Source: Coding guidelines
455-478: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win
sorted_entriesdeduplicates by card name only, so the group count and the pull count diverge.
sorted_entriescollapses copies into oneDraftPoolEntrywithcount. The group itself exposes onlycards, so any consumer that needs the number of physical cards in the group must sumcountover the entries.PoolPanel.tsxusesgroup.cards.lengthand therefore under-reports every group that contains duplicates. Consider adding an engine-computed total toDraftPoolGroupso the client never has to derive it.♻️ Proposed engine-owned total
pub struct DraftPoolGroup { pub kind: DraftPoolGroupKind, pub cards: Vec<DraftPoolEntry>, + /// Total physical cards in this group, including duplicates. + pub total: usize, }Populate it in
groups_forfromcards.len()before deduplication.🤖 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/draft-core/src/view.rs` around lines 455 - 478, Update DraftPoolGroup and groups_for to include an engine-computed total representing the physical card count; set it from cards.len() before sorted_entries deduplicates cards by name. Ensure PoolPanel.tsx and other consumers use this total instead of group.cards.length when displaying group size.Source: Path instructions
client/src/adapter/__tests__/draftPodAdapter.test.ts (1)
115-120: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueTwo fixtures inline the empty pool-group literal that
draft-adapter.tsalready exports.EMPTY_DRAFT_POOL_GROUPSis the single source for this shape, andserver-draft-adapter.test.tsimports it. A new field onDraftPoolGroupswould require edits in each inlined copy.
client/src/adapter/__tests__/draftPodAdapter.test.ts#L115-L120: importEMPTY_DRAFT_POOL_GROUPSfrom../draft-adapterand assign it topool_groups.client/src/components/draft/__tests__/PackDisplay.pod.test.tsx#L42-L47: importEMPTY_DRAFT_POOL_GROUPSfrom../../../adapter/draft-adapterand assign it topool_groups.🤖 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 `@client/src/adapter/__tests__/draftPodAdapter.test.ts` around lines 115 - 120, Replace the inline empty pool-group fixture with the shared EMPTY_DRAFT_POOL_GROUPS export. In client/src/adapter/__tests__/draftPodAdapter.test.ts:115-120, import it from ../draft-adapter and assign it to pool_groups; make the same replacement in client/src/components/draft/__tests__/PackDisplay.pod.test.tsx:42-47 using ../../../adapter/draft-adapter.
🤖 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 `@client/src/adapter/draft-adapter.ts`:
- Around line 33-39: The mana-value group labels in
client/src/adapter/draft-adapter.ts:33-39 and
client/src/components/draft/poolGroupLabels.ts:20-26 must match Rust
serialization: use mana_value0 through mana_value5 and mana_value6_plus, without
an underscore before the digit. Update the related DraftPoolGroupKind and
poolGroupLabels entries, and add an engine serialization test covering all
mana-value variants to prevent protocol drift.
In `@client/src/network/__tests__/draftProtocol.test.ts`:
- Around line 148-153: Add non-empty pool_groups entries matching the two
fixture cards in the draft protocol round-trip test, including color_groups,
type_groups, and cmc_groups data plus accurate color_counts. Extend the
decoded-view assertions to compare decoded.view.pool_groups with
longView.pool_groups, covering every group field consumed by SealedPackOpening.
In `@crates/draft-core/src/view.rs`:
- Around line 455-478: Update crates/draft-core/src/view.rs:455-478 by adding a
total field to DraftPoolGroup and populating it in groups_for from the
pre-deduplication card count produced before sorted_entries collapses
duplicates. Update client/src/components/draft/PoolPanel.tsx:150-152 to render
group.total instead of group.cards.length.
In `@crates/server-core/src/protocol.rs`:
- Line 2119: Update the round-trip test’s pool_groups fixture instead of using
DraftPoolGroups::default(): populate non-empty color_groups, type_groups, and
cmc_groups from the two pool cards, with non-zero color_counts, then assert the
decoded v.pool_groups matches those groups and counts, including
DraftPoolGroupKind values.
---
Nitpick comments:
In `@client/src/adapter/__tests__/draftPodAdapter.test.ts`:
- Around line 115-120: Replace the inline empty pool-group fixture with the
shared EMPTY_DRAFT_POOL_GROUPS export. In
client/src/adapter/__tests__/draftPodAdapter.test.ts:115-120, import it from
../draft-adapter and assign it to pool_groups; make the same replacement in
client/src/components/draft/__tests__/PackDisplay.pod.test.tsx:42-47 using
../../../adapter/draft-adapter.
In `@client/src/components/draft/PoolPanel.tsx`:
- Around line 88-96: Replace the nested sort-mode ternary in PoolPanel with a
module-scope GROUPS_BY_SORT_MODE keyed by every PoolSortMode value, declared
alongside COLOR_COUNT_KEYS. Use the keyed lookup for view.pool_groups so adding
a new mode requires updating the mapping and preserves exhaustive type checking.
In `@crates/draft-core/src/view.rs`:
- Around line 433-478: Replace the positional sort_by_cmc boolean in groups_for
and sorted_entries with a typed EntryOrder enum that represents the supported
sort keys. Update grouped_pool call sites to pass the appropriate enum variant
instead of true or false, and match on EntryOrder inside sorted_entries while
preserving the existing CMC-then-name and name-only ordering behavior.
- Around line 455-478: Update DraftPoolGroup and groups_for to include an
engine-computed total representing the physical card count; set it from
cards.len() before sorted_entries deduplicates cards by name. Ensure
PoolPanel.tsx and other consumers use this total instead of group.cards.length
when displaying group size.
🪄 Autofix
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: a029359b-63f4-4364-8538-612b42ad8149
📒 Files selected for processing (23)
client/src/adapter/__tests__/draftPodAdapter.test.tsclient/src/adapter/__tests__/server-draft-adapter.test.tsclient/src/adapter/draft-adapter.tsclient/src/adapter/p2p-draft-host.tsclient/src/components/draft/PoolPanel.tsxclient/src/components/draft/SealedPackOpening.tsxclient/src/components/draft/__tests__/LimitedDeckBuilder.test.tsxclient/src/components/draft/__tests__/PackDisplay.pod.test.tsxclient/src/components/draft/__tests__/SealedPackOpening.test.tsxclient/src/components/draft/poolGroupLabels.tsclient/src/i18n/locales/de/draft.jsonclient/src/i18n/locales/en/draft.jsonclient/src/i18n/locales/es/draft.jsonclient/src/i18n/locales/fr/draft.jsonclient/src/i18n/locales/it/draft.jsonclient/src/i18n/locales/pl/draft.jsonclient/src/i18n/locales/pt/draft.jsonclient/src/network/__tests__/draftProtocol.test.tsclient/src/network/draftProtocol.tsclient/src/pages/DraftLandingPage.tsxclient/src/stores/__tests__/multiplayerDraftStore.test.tscrates/draft-core/src/view.rscrates/server-core/src/protocol.rs
🚧 Files skipped from review as they are similar to previous changes (6)
- client/src/pages/DraftLandingPage.tsx
- client/src/i18n/locales/es/draft.json
- client/src/i18n/locales/pl/draft.json
- client/src/i18n/locales/fr/draft.json
- client/src/components/draft/SealedPackOpening.tsx
- client/src/components/draft/tests/SealedPackOpening.test.tsx
Summary by CodeRabbit