Skip to content

Conversation

@KATO-Hiro
Copy link
Collaborator

@KATO-Hiro KATO-Hiro commented Dec 30, 2025

close #3005

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an initialization error that could crash the app when loading contest data.
    • Improved validation of saved contest type settings; invalid/null/corrupted values now reset to default automatically.
    • Enhanced error handling to prevent crashes when contest provider data is unavailable.
  • Tests

    • Expanded test coverage for contest type initialization, invalid/null values, sequential changes, and validation.
  • Documentation

    • Added a plan and verification steps describing the validation and fixes.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 30, 2025

Walkthrough

Fixes initialization faults in ActiveContestTypeStore by validating stored contest-type keys against available contestTableProviderGroups; invalid or missing values are reset to a default. TaskTable is made defensive against undefined providerGroups. Unit tests expanded to cover invalid/null/sequence cases and cleanup.

Changes

Cohort / File(s) Summary
Plan Document
docs/dev-notes/2025-12-30/improve-validation-for-active-contest-type-store/plan.md
New plan describing bug, validation approach, component defensive fix, expanded tests, verification steps, and Q&A.
Store Validation Logic
src/lib/stores/active_contest_type.svelte.ts
Added private isValidContestType that validates a stored key against contestTableProviderGroups; constructor uses it to reset invalid/absent values to the default.
Component Defensive Fix
src/lib/components/TaskTables/TaskTable.svelte
providerGroups type widened to allow undefined; providers now derives from providerGroups?.getAllProviders() with an empty-array fallback to avoid runtime errors.
Expanded Unit Tests
src/test/lib/stores/active_contest_type.svelte.test.ts
Added test cleanup (afterEach), cleared mockStorage in beforeEach, removed one constructor-arg test, and added tests for invalid keys, null/undefined init, custom defaults, and sequential type changes.

Sequence Diagram(s)

sequenceDiagram
  participant TaskTable as TaskTable component
  participant Store as ActiveContestTypeStore
  participant LS as localStorage
  participant Providers as contestTableProviderGroups

  Note over LS,Store: App load / store initialization
  LS->>Store: read("activeContestType")
  Store->>Providers: query available contest types
  alt stored value is valid
    Providers-->>Store: contains(key)
    Store-->>TaskTable: expose current contest type
  else stored value invalid or missing
    Providers-->>Store: does not contain(key)
    Store->>LS: write(defaultContestType)
    Store-->>TaskTable: expose default contest type
  end

  Note over TaskTable,Providers: rendering providers list
  TaskTable->>Providers: access providerGroups (may be undefined)
  alt providerGroups defined
    Providers-->>TaskTable: getAllProviders() -> list
  else providerGroups undefined
    Providers-->>TaskTable: undefined -> fallback []
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I sniffed the keys where values slept,

found some askew where defaults kept.
A tiny hop, a gentle nudge,
now tables wake without a grudge.
🥕✨

Pre-merge checks and finishing touches

✅ 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 describes the main change: adding validation for the active contest type store to fix an initialization bug.
Linked Issues check ✅ Passed The pull request addresses the core requirement of fixing the table display bug by validating stored contest types and handling undefined states.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the initialization bug: validation logic, defensive fixes, and comprehensive test coverage are all in scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 29fef8c and 5cfe807.

📒 Files selected for processing (1)
  • src/test/lib/stores/active_contest_type.svelte.test.ts
🧰 Additional context used
🧬 Code graph analysis (1)
src/test/lib/stores/active_contest_type.svelte.test.ts (2)
src/lib/stores/active_contest_type.svelte.ts (1)
  • ActiveContestTypeStore (18-84)
src/lib/utils/contest_table_provider.ts (1)
  • ContestTableProviderGroups (1263-1263)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: preview
🔇 Additional comments (6)
src/test/lib/stores/active_contest_type.svelte.test.ts (6)

1-1: LGTM! Proper test cleanup import added.

The addition of afterEach to the imports is correct and supports the cleanup logic added later in the test suite.


28-31: LGTM! Proper test isolation implemented.

Clearing mockStorage before each test ensures a clean state and prevents test pollution, which is especially important for the new validation tests.


39-41: LGTM! Proper global cleanup added.

The afterEach hook correctly cleans up global stubs, ensuring no side effects leak between tests.


96-102: LGTM! Validation test for invalid contest type.

This test correctly verifies that the store resets to the default value when initialized with an invalid contest type from localStorage, which aligns with the PR's validation objectives.


104-109: LGTM! Validation test for null value.

This test correctly verifies that the store handles null values gracefully and resets to the default, covering an important edge case in the validation logic.


111-122: LGTM! Previous issue resolved.

The invalid contest type 'arcLatest20Rounds' mentioned in the previous review has been corrected to 'abcLatest20Rounds', which is a valid default value. The test now correctly verifies sequential contest type changes with valid types.


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.

❤️ Share

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

Copy link

@coderabbitai coderabbitai bot left a comment

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)
docs/dev-notes/2025-12-30/improve-validation-for-active-contest-type-store/plan.md (1)

7-7: Address markdown formatting issues.

The static analysis tool flags minor markdown formatting inconsistencies:

  • Line 7: Code block missing language specifier
  • Lines 52, 75: Using bold text instead of proper heading tags

These don't affect functionality but improve markdown consistency.

🔎 Proposed fixes
-```
+```text
 Cannot read properties of undefined (reading 'getAllProviders')
 at TaskTable.svelte:52:42

```diff
-**修正内容**
+### 修正内容
-**修正内容**
+### 修正内容

Also applies to: 52-52, 75-75

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between ed3f8e1 and 29fef8c.

📒 Files selected for processing (4)
  • docs/dev-notes/2025-12-30/improve-validation-for-active-contest-type-store/plan.md
  • src/lib/components/TaskTables/TaskTable.svelte
  • src/lib/stores/active_contest_type.svelte.ts
  • src/test/lib/stores/active_contest_type.svelte.test.ts
🧰 Additional context used
🧬 Code graph analysis (2)
src/lib/stores/active_contest_type.svelte.ts (1)
src/lib/utils/contest_table_provider.ts (2)
  • ContestTableProviderGroups (1263-1263)
  • contestTableProviderGroups (1242-1261)
src/test/lib/stores/active_contest_type.svelte.test.ts (2)
src/lib/stores/active_contest_type.svelte.ts (1)
  • ActiveContestTypeStore (18-84)
src/lib/utils/contest_table_provider.ts (1)
  • ContestTableProviderGroups (1263-1263)
🪛 markdownlint-cli2 (0.18.1)
docs/dev-notes/2025-12-30/improve-validation-for-active-contest-type-store/plan.md

7-7: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


52-52: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


75-75: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: preview
🔇 Additional comments (7)
docs/dev-notes/2025-12-30/improve-validation-for-active-contest-type-store/plan.md (1)

1-148: Excellent documentation quality.

The plan document provides comprehensive coverage of the bug, root cause analysis, implementation approach, and verification steps. The Q&A section adds valuable context about why this issue appeared after JOI additions.

src/lib/components/TaskTables/TaskTable.svelte (1)

49-52: Good defensive programming approach.

The type widening to ContestTableProviderGroup | undefined and the optional chaining with fallback (providerGroups?.getAllProviders() ?? []) provide robust handling of edge cases. This works well in conjunction with the validation logic added to ActiveContestTypeStore, creating a defense-in-depth strategy.

src/lib/stores/active_contest_type.svelte.ts (3)

2-5: LGTM! Import enables validation logic.

The expanded import correctly includes contestTableProviderGroups to support the new validation method.


42-48: Validation logic correctly addresses root cause.

The isValidContestType method properly validates against null, undefined, and invalid keys by checking existence in contestTableProviderGroups. This prevents the undefined reference error that occurred when localStorage contained obsolete contest type keys.


30-34: Constructor properly validates and resets invalid values.

The simplified constructor logic delegates to isValidContestType and correctly resets to defaultContestType when localStorage contains invalid values. This ensures the store always has a valid state.

src/test/lib/stores/active_contest_type.svelte.test.ts (2)

28-31: Good test isolation improvements.

Clearing mockStorage in beforeEach ensures proper test isolation and prevents state leakage between tests. The afterEach cleanup is also appropriate.

Also applies to: 39-41


96-109: Excellent coverage for validation edge cases.

The new tests properly verify that the store resets to default when localStorage contains invalid or null values. These tests directly validate the bug fix.

Copy link
Collaborator Author

@KATO-Hiro KATO-Hiro left a comment

Choose a reason for hiding this comment

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

LGTM

@KATO-Hiro KATO-Hiro merged commit e851d50 into staging Dec 30, 2025
3 checks passed
@KATO-Hiro KATO-Hiro deleted the #3005 branch December 30, 2025 11:30
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.

[Bug] テーブルが表示されない不具合を修正しましょう

2 participants