Skip to content
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

Stochastic Ponder 使用時の表示と周辺実装の改善 #1096

Merged
merged 1 commit into from
Feb 2, 2025

Conversation

sunfish-shogi
Copy link
Owner

@sunfish-shogi sunfish-shogi commented Feb 1, 2025

説明 / Description

#993

  • やねうら王の Stochastic_Ponder を使用した時の読み筋の表示を改善
  • 読み筋を受信した時の処理を軽量化

チェックリスト / Checklist

  • MUST
    • npm test passed
    • npm run lint was applied without warnings
    • changes of /docs/webapp not included (except release branch)
    • console.log not included (except script file)
  • MUST for Outside Contributor
  • RECOMMENDED (it depends on what you change)
    • unit test added/updated
    • i18n

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced an option for stochastic pondering to enhance engine analysis.
    • Enhanced the processing of move suggestions and engine updates by using the current game position for more precise evaluations.
    • Added support for handling checkmate scenarios within the USI player.
  • Refactor

    • Streamlined the internal handling of pondering states with improved state tracking.
    • Adjusted update routines with asynchronous delays to ensure smoother, more responsive performance.
    • Consolidated the handling of USI information by removing specific ponder-related callbacks.
  • Bug Fixes

    • Removed unused code related to ponder information handling, simplifying the overall logic.
  • Tests

    • Updated tests to utilize structured position data, enhancing type safety and clarity in position handling.
    • Added new tests for the stochastic pondering functionality.
    • Introduced tests for checkmate scenarios to validate appropriate handler invocations.

@sunfish-shogi sunfish-shogi self-assigned this Feb 1, 2025
Copy link

coderabbitai bot commented Feb 1, 2025

Walkthrough

This pull request updates several USI-related modules. In the settings module, a new constant and function are added to support and evaluate a stochastic pondering option. The USI player module now uses refined type signatures and state management, replacing an old pondering flag with a new ponder move mechanism and adding a getter for stochastic pondering. In the store modules, method signatures have been modified to use position information and an optional ponder move. Additionally, an asynchronous delay has been introduced in the monitor’s endIteration process.

Changes

File(s) Change Summary
src/common/settings/usi.ts Added new constant StochasticPonder and function getUSIEngineStochasticPonder to retrieve and evaluate the stochastic pondering setting.
src/renderer/players/usi.ts Updated type signatures for USI handlers to use ImmutablePosition, removed onUpdateUSIPonderInfo, replaced inPonder with ponderMove, and added a stochasticPonder getter.
src/renderer/store/index.ts Removed unused import; updated method signatures (endUSIInfoIteration, updateUSIInfo) to accept positions and an optional ponderMove; revised candidate filtering logic.
src/renderer/store/usi.ts Modified the endIteration method to wrap dequeue() and monitor.endIteration calls in a setTimeout.
src/tests/renderer/store/index.spec.ts Updated tests to replace usi string with ImmutablePosition object; removed updateUSIPonderInfo method calls; added ponderMove parameter handling in tests.
src/background/usi/engine.ts Removed ponderInfoCallback and related logic from EngineProcess, simplifying the handling of information received from the engine.
src/background/usi/index.ts Removed onUSIPonderInfo from the Handlers interface and updated event listeners to consolidate information handling.
src/background/window/ipc.ts Removed onUSIPonderInfo handler function, ceasing the transmission of ponder information in IPC.
src/command/common/preload.ts Removed onUSIPonderInfo method from the bridge object, simplifying the interface.
src/common/ipc/channel.ts Removed USI_PONDER_INFO from the Renderer enum, indicating a shift in handling USI ponder information.
src/renderer/ipc/bridge.ts Removed onUSIPonderInfo method from the Bridge interface, altering how USI ponder information is processed.
src/renderer/ipc/preload.ts Removed onUSIPonderInfo method from the api object, affecting the handling of USI ponder information.
src/renderer/ipc/setup.ts Removed onUSIPonderInfo event handler from the bridge object, changing control flow for USI ponder events.
src/renderer/ipc/web.ts Removed onUSIPonderInfo method from the webAPI object, simplifying the interface without affecting other functionalities.
src/tests/background/usi/engine.spec.ts Removed ponderInfo handler from tests and updated references to use info handler instead.
src/tests/common/settings/usi.spec.ts Introduced getUSIEngineStochasticPonder function; modified existing tests to streamline engine object structure.
src/tests/mock/mate.ts Added new constant engine of type USIEngine and a new exported constant mateSearchSettings of type MateSearchSettings.
src/tests/renderer/players/usi.spec.ts Added new handlers for checkmate scenarios and corresponding test cases to verify their behavior.

Suggested labels

bug

Poem

I'm a little rabbit, hopping through the code,
With constants and functions upon a winding road.
I nibble on changes, crisp and refined,
Type tweaks and async calls in every line defined.
Happy as carrots in a field so wide,
I celebrate these changes with a joyful, twitchy stride!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 0

🧹 Nitpick comments (1)
src/renderer/store/usi.ts (1)

254-258: Specify an explicit timeout value for clarity.

The setTimeout call doesn't specify a delay value. While it defaults to 0ms, it's better to be explicit for maintainability.

-      setTimeout(() => {
+      setTimeout(() => {
         this.dequeue(); // flush the queue
         monitor.endIteration(sfen);
-      });
+      }, 0);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fba458b and c43838b.

📒 Files selected for processing (4)
  • src/common/settings/usi.ts (2 hunks)
  • src/renderer/players/usi.ts (12 hunks)
  • src/renderer/store/index.ts (3 hunks)
  • src/renderer/store/usi.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (8)
src/renderer/players/usi.ts (4)

16-27: LGTM! Type signatures improved for better type safety.

The changes enhance type safety by:

  • Using ImmutablePosition instead of string for position data
  • Adding explicit Move type for ponder moves

48-48: LGTM! Improved ponder state management.

Replacing the boolean inPonder with ponderMove?: Move is a good improvement as it:

  • Provides more information about what move is being pondered
  • Makes the code more explicit and type-safe
  • Helps prevent state synchronization issues

Also applies to: 90-96, 111-113


129-131: LGTM! Clean implementation of stochastic ponder support.

The changes properly integrate stochastic pondering by:

  • Only doing the ponder move if stochastic pondering is disabled
  • Adding a clean getter to access the engine setting

Also applies to: 329-331


186-186: LGTM! Consistent handler implementation updates.

The changes properly update all handlers to use the new parameter types, maintaining consistency throughout the codebase.

Also applies to: 219-219, 270-270

src/common/settings/usi.ts (1)

14-14: LGTM! Clean implementation of stochastic ponder settings.

The changes follow the established patterns in the codebase:

  • Consistent naming for the option constant
  • Implementation matches other option getter functions
  • Proper type safety and null checks

Also applies to: 94-97

src/renderer/store/index.ts (3)

60-60: LGTM! Simplified imports.

Removing the separate ponder info handler import aligns with the unified handler approach.


461-463: LGTM! Proper filtering of pondering sessions.

The change correctly excludes sessions that are currently pondering from contributing to the candidates list.


534-535: LGTM! Consistent method signature updates.

The changes properly update the method signatures to use ImmutablePosition and include ponderMove, maintaining consistency with the changes in the USI player implementation.

Also applies to: 538-544

@sunfish-shogi sunfish-shogi force-pushed the fix-for-stochastic-ponder branch from c43838b to 59d0559 Compare February 1, 2025 09:39
Copy link

codecov bot commented Feb 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.45%. Comparing base (fba458b) to head (cf994b8).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1096      +/-   ##
==========================================
+ Coverage   77.86%   78.45%   +0.59%     
==========================================
  Files         122      122              
  Lines       15932    15891      -41     
  Branches     2587     2605      +18     
==========================================
+ Hits        12406    12468      +62     
+ Misses       3507     3404     -103     
  Partials       19       19              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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: 0

🧹 Nitpick comments (1)
src/tests/renderer/store/index.spec.ts (1)

Line range hint 138-182: Consider extracting the SFEN string to a constant.

The test case correctly validates the updateUSIInfo functionality with the new position-based API. However, the readability could be improved by extracting the repeated SFEN string to a constant at the top of the test file.

+const TEST_POSITION_SFEN = "lnsgkgsnl/1r5b1/ppppppppp/9/9/2P6/PP1PPPPPP/1B5R1/LNSGKGSNL w - 2";
+
 it("updateUSIInfo", () => {
   vi.useFakeTimers();
   const usi = "position startpos moves 7g7f";
-  const position = Position.newBySFEN(
-    "lnsgkgsnl/1r5b1/ppppppppp/9/9/2P6/PP1PPPPPP/1B5R1/LNSGKGSNL w - 2",
-  ) as ImmutablePosition;
+  const position = Position.newBySFEN(TEST_POSITION_SFEN) as ImmutablePosition;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c43838b and 59d0559.

📒 Files selected for processing (5)
  • src/common/settings/usi.ts (2 hunks)
  • src/renderer/players/usi.ts (12 hunks)
  • src/renderer/store/index.ts (3 hunks)
  • src/renderer/store/usi.ts (1 hunks)
  • src/tests/renderer/store/index.spec.ts (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/renderer/store/usi.ts
  • src/renderer/players/usi.ts
  • src/renderer/store/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: build
🔇 Additional comments (5)
src/common/settings/usi.ts (2)

14-14: LGTM!

The new constant follows the established naming convention and is well-placed among other option name constants.


94-97: LGTM!

The function follows the established pattern of other getter functions and uses the existing helper correctly.

src/tests/renderer/store/index.spec.ts (3)

3-3: LGTM!

The import statement correctly includes the required types from the tsshogi library.


Line range hint 188-262: LGTM!

The test case correctly validates the multipv functionality with the new position-based API. The assertions properly verify the behavior of multiple PV lines and their updates.


269-310: LGTM!

The test case correctly validates the candidates functionality with the new position-based API. The assertions properly verify the behavior of candidate moves with different settings and engines.

@sunfish-shogi sunfish-shogi force-pushed the fix-for-stochastic-ponder branch from 59d0559 to 2adc376 Compare February 1, 2025 11:50
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: 0

🧹 Nitpick comments (1)
src/renderer/players/usi.ts (1)

129-133: Add comments explaining stochastic pondering behavior.

The conditional position update based on stochastic pondering would benefit from documentation explaining:

  1. Why position is not updated during stochastic pondering
  2. The implications of this behavior on the engine's analysis

Add comments above the condition:

+  // In stochastic pondering mode, we don't update the position as the engine
+  // needs to analyze multiple possible positions probabilistically
   if (!this.stochasticPonder) {
     this.position.doMove(ponderMove);
   }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 59d0559 and 2adc376.

📒 Files selected for processing (5)
  • src/common/settings/usi.ts (2 hunks)
  • src/renderer/players/usi.ts (12 hunks)
  • src/renderer/store/index.ts (3 hunks)
  • src/renderer/store/usi.ts (3 hunks)
  • src/tests/renderer/store/index.spec.ts (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/common/settings/usi.ts
  • src/renderer/store/usi.ts
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/renderer/store/index.ts

[warning] 461-462: src/renderer/store/index.ts#L461-L462
Added lines #L461 - L462 were not covered by tests

src/renderer/players/usi.ts

[warning] 219-219: src/renderer/players/usi.ts#L219
Added line #L219 was not covered by tests


[warning] 365-365: src/renderer/players/usi.ts#L365
Added line #L365 was not covered by tests

🔇 Additional comments (6)
src/renderer/players/usi.ts (3)

16-27: LGTM! Type signature changes improve type safety.

The changes from string-based USI to strongly-typed ImmutablePosition enhance type safety and make the code more maintainable.


90-97: LGTM! Improved pondering state management.

The changes improve state management by:

  1. Using explicit ponderMove state instead of a boolean flag
  2. Properly cleaning up the ponderMove state after search

329-331: LGTM! Clean interface for stochastic pondering setting.

The getter provides a clean way to access the engine's stochastic pondering setting.

src/tests/renderer/store/index.spec.ts (1)

266-297: LGTM! Comprehensive test coverage for USI info iteration.

The new test case thoroughly verifies:

  1. Proper state management during USI info iterations
  2. Correct handling of refresh flags
  3. Multiple engine scenarios
src/renderer/store/index.ts (2)

533-543: LGTM! Clean method signatures for USI info handling.

The updated method signatures using ImmutablePosition and optional ponderMove parameter improve type safety and clarity.


460-462: Add test coverage for pondering session filtering.

The pondering session filtering logic in the candidates getter lacks test coverage.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 461-462: src/renderer/store/index.ts#L461-L462
Added lines #L461 - L462 were not covered by tests

@sunfish-shogi sunfish-shogi force-pushed the fix-for-stochastic-ponder branch 2 times, most recently from b9c4c34 to 8c59249 Compare February 1, 2025 13:58
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: 0

🧹 Nitpick comments (1)
src/background/usi/engine.ts (1)

627-630: LGTM! Clean refactoring of info handling.

The consolidation of info handling into a single path simplifies the code while maintaining functionality. The use of optional chaining (?.) provides safe callback handling.

Consider extracting the info handling logic into a separate method for better maintainability:

-      if (this.infoCallback) {
-        const args = command.substring(5);
-        this.infoCallback?.(this.currentPosition, parseInfoCommand(args));
-      }
+      this.handleInfoCommand(command.substring(5));
+    }
+  }
+
+  private handleInfoCommand(args: string): void {
+    this.infoCallback?.(this.currentPosition, parseInfoCommand(args));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b9c4c34 and 8c59249.

📒 Files selected for processing (16)
  • src/background/usi/engine.ts (1 hunks)
  • src/background/usi/index.ts (1 hunks)
  • src/background/window/ipc.ts (0 hunks)
  • src/command/common/preload.ts (0 hunks)
  • src/common/ipc/channel.ts (0 hunks)
  • src/common/settings/usi.ts (2 hunks)
  • src/renderer/ipc/bridge.ts (0 hunks)
  • src/renderer/ipc/preload.ts (0 hunks)
  • src/renderer/ipc/setup.ts (0 hunks)
  • src/renderer/ipc/web.ts (0 hunks)
  • src/renderer/players/usi.ts (12 hunks)
  • src/renderer/store/index.ts (3 hunks)
  • src/renderer/store/usi.ts (3 hunks)
  • src/tests/background/usi/engine.spec.ts (2 hunks)
  • src/tests/common/settings/usi.spec.ts (4 hunks)
  • src/tests/renderer/store/index.spec.ts (7 hunks)
💤 Files with no reviewable changes (7)
  • src/renderer/ipc/web.ts
  • src/common/ipc/channel.ts
  • src/renderer/ipc/setup.ts
  • src/command/common/preload.ts
  • src/renderer/ipc/preload.ts
  • src/renderer/ipc/bridge.ts
  • src/background/window/ipc.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/common/settings/usi.ts
  • src/background/usi/index.ts
  • src/renderer/store/usi.ts
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/renderer/players/usi.ts

[warning] 219-219: src/renderer/players/usi.ts#L219
Added line #L219 was not covered by tests

src/renderer/store/index.ts

[warning] 461-462: src/renderer/store/index.ts#L461-L462
Added lines #L461 - L462 were not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (12)
src/tests/background/usi/engine.spec.ts (1)

238-238: LGTM! Test updates match the refactored implementation.

The test expectations have been correctly updated to use the consolidated info handler instead of the removed ponderInfo handler, maintaining test coverage while aligning with the simplified event handling in the engine implementation.

Also applies to: 350-350

src/renderer/players/usi.ts (5)

6-6: LGTM!

The import of getUSIEngineStochasticPonder is correctly added to support the new stochastic ponder functionality.


16-28: LGTM! Type changes improve type safety.

The handler type changes enhance type safety by:

  • Using ImmutablePosition instead of string for position data
  • Adding optional ponderMove parameter to onUpdateUSIInfoHandler

48-48: LGTM! Improved ponder state tracking.

Replacing inPonder boolean with ponderMove?: Move enhances the pondering state management by:

  • Providing more information about which move is being pondered
  • Improving type safety with the Move type

129-131: LGTM! Conditional position update for stochastic ponder.

The position update is correctly guarded by the stochastic ponder check, ensuring proper handling of the stochastic pondering feature.


329-331: LGTM! Clean getter implementation.

The stochasticPonder getter is correctly implemented to retrieve the stochastic ponder setting from the engine.

src/tests/common/settings/usi.spec.ts (1)

268-328: LGTM! Comprehensive test coverage for stochastic ponder.

The test cases for getUSIEngineStochasticPonder are well-structured and cover all important scenarios:

  • Explicit false value
  • Explicit true value
  • Default value inheritance
  • Non-existent option handling
src/tests/renderer/store/index.spec.ts (2)

Line range hint 138-182: LGTM! Test cases properly updated for new API.

The updateUSIInfo test cases are well-updated to:

  • Use Position object instead of string
  • Test ponderMove functionality
  • Maintain comprehensive assertions

266-297: LGTM! Well-structured test for endUSIInfoIteration.

The new test case thoroughly verifies the iteration ending functionality:

  • Tests iteration ending for specific engines
  • Verifies refresh flag behavior
  • Checks multiple engine updates
src/renderer/store/index.ts (3)

59-59: LGTM! Simplified imports.

Removed setOnUpdateUSIPonderInfoHandler as ponder information is now handled through the main USI info handler.


460-462: Add test coverage for ponderMove check in candidates method.

The ponderMove check is correctly implemented but lacks test coverage.

Please add test cases to verify the behavior when session.ponderMove is set. This will help ensure the skip logic works as expected.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 461-462: src/renderer/store/index.ts#L461-L462
Added lines #L461 - L462 were not covered by tests


533-543: LGTM! Improved type safety in USI info handling.

The changes enhance type safety and clarity by:

  • Using Position instead of string
  • Adding ponderMove parameter
  • Maintaining consistent parameter ordering

@sunfish-shogi sunfish-shogi force-pushed the fix-for-stochastic-ponder branch from 8c59249 to cf994b8 Compare February 2, 2025 06:47
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: 0

🧹 Nitpick comments (3)
src/tests/mock/mate.ts (1)

4-13: Consider adding JSDoc documentation for the mock engine configuration.

The mock engine configuration is well-structured with all required fields. Consider adding JSDoc documentation to explain its purpose in tests.

+/**
+ * Mock USI engine configuration for mate search tests.
+ * Uses a test engine with minimal configuration.
+ */
 const engine: USIEngine = {
   uri: "es://usi/test-engine",
   name: "my usi engine",
   defaultName: "engine",
   author: "author",
   path: "/engines/engines",
   options: {},
   labels: {},
   enableEarlyPonder: false,
 };
src/tests/renderer/players/usi.spec.ts (2)

134-134: Consider extracting common test position setup.

The same position setup is duplicated across all three checkmate test cases. Consider extracting it into a shared constant or helper function to improve maintainability.

+const TEST_CHECKMATE_POSITION = "position sfen 3sks3/9/4+P4/9/7+B1/9/9/9/9 b S2rb4gs4n4l17p 1";
+
 it("checkmate", async () => {
   mockAPI.usiLaunch.mockResolvedValueOnce(100);
   mockAPI.usiGoMate.mockResolvedValueOnce();
-  const usi = "position sfen 3sks3/9/4+P4/9/7+B1/9/9/9/9 b S2rb4gs4n4l17p 1";
+  const usi = TEST_CHECKMATE_POSITION;

Also applies to: 165-165, 193-193


139-145: Consider extracting common handler setup.

The handler setup with mock functions is duplicated across all checkmate test cases. Consider extracting it into a helper function to reduce duplication and improve maintainability.

+function createCheckmateHandler() {
+  return {
+    onCheckmate: vi.fn(),
+    onNotImplemented: vi.fn(),
+    onTimeout: vi.fn(),
+    onNoMate: vi.fn(),
+    onError: vi.fn(),
+  };
+}
+
 it("checkmate", async () => {
   // ...
-  const handler = {
-    onCheckmate: vi.fn(),
-    onNotImplemented: vi.fn(),
-    onTimeout: vi.fn(),
-    onNoMate: vi.fn(),
-    onError: vi.fn(),
-  };
+  const handler = createCheckmateHandler();

Also applies to: 170-176, 198-204

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c59249 and cf994b8.

📒 Files selected for processing (18)
  • src/background/usi/engine.ts (1 hunks)
  • src/background/usi/index.ts (1 hunks)
  • src/background/window/ipc.ts (0 hunks)
  • src/command/common/preload.ts (0 hunks)
  • src/common/ipc/channel.ts (0 hunks)
  • src/common/settings/usi.ts (2 hunks)
  • src/renderer/ipc/bridge.ts (0 hunks)
  • src/renderer/ipc/preload.ts (0 hunks)
  • src/renderer/ipc/setup.ts (0 hunks)
  • src/renderer/ipc/web.ts (0 hunks)
  • src/renderer/players/usi.ts (12 hunks)
  • src/renderer/store/index.ts (3 hunks)
  • src/renderer/store/usi.ts (3 hunks)
  • src/tests/background/usi/engine.spec.ts (2 hunks)
  • src/tests/common/settings/usi.spec.ts (4 hunks)
  • src/tests/mock/mate.ts (1 hunks)
  • src/tests/renderer/players/usi.spec.ts (2 hunks)
  • src/tests/renderer/store/index.spec.ts (10 hunks)
💤 Files with no reviewable changes (7)
  • src/renderer/ipc/bridge.ts
  • src/common/ipc/channel.ts
  • src/background/window/ipc.ts
  • src/renderer/ipc/setup.ts
  • src/command/common/preload.ts
  • src/renderer/ipc/preload.ts
  • src/renderer/ipc/web.ts
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/common/settings/usi.ts
  • src/background/usi/index.ts
  • src/renderer/store/usi.ts
  • src/renderer/players/usi.ts
  • src/tests/background/usi/engine.spec.ts
  • src/tests/renderer/store/index.spec.ts
  • src/renderer/store/index.ts
🔇 Additional comments (9)
src/tests/common/settings/usi.spec.ts (3)

15-15: LGTM!

The new import is correctly placed and follows the existing import pattern.


139-139: LGTM! Good test code cleanup.

The engine object simplification improves test readability by including only the necessary properties for testing. The type assertion is appropriately used to satisfy TypeScript's type checking.

Also applies to: 201-201, 263-263


268-328: LGTM! Comprehensive test coverage.

The test cases for getUSIEngineStochasticPonder are well-structured and cover all important scenarios:

  1. Explicit false value
  2. Explicit true value
  3. Default true value
  4. Missing option (false)

The implementation follows the established patterns in the codebase.

src/tests/mock/mate.ts (1)

15-17: LGTM!

The mate search settings correctly wrap the engine configuration.

src/background/usi/engine.ts (1)

627-630: LGTM! Simplified info command handling.

The changes streamline the info command processing by:

  1. Using a single callback for all states
  2. Directly passing the current position and parsed info
  3. Removing the redundant ponder-specific handling

This simplification aligns with the PR objectives of improving reading line processing efficiency.

src/tests/renderer/players/usi.spec.ts (4)

2-9: LGTM! Well-organized imports.

The new checkmate-related handlers are properly imported and grouped with other USI-related imports.


131-160: LGTM! Comprehensive test for successful checkmate scenario.

The test thoroughly verifies:

  • Correct initialization and API calls
  • Proper handling of checkmate moves
  • Validation that other handlers aren't called

162-188: LGTM! Good coverage of not-implemented scenario.

The test properly verifies the behavior when checkmate search is not implemented by the engine.


190-216: LGTM! Well-structured test for no-mate scenario.

The test effectively verifies the behavior when no checkmate is found in the position.

@sunfish-shogi sunfish-shogi merged commit 75e404f into main Feb 2, 2025
5 checks passed
@sunfish-shogi sunfish-shogi deleted the fix-for-stochastic-ponder branch February 2, 2025 06:51
@coderabbitai coderabbitai bot mentioned this pull request Feb 6, 2025
7 tasks
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