Skip to content

refactor: extend test helper to eliminate remaining duplication#106

Merged
teng-lin merged 1 commit intomainfrom
fix/pr105-review-followup
Feb 21, 2026
Merged

refactor: extend test helper to eliminate remaining duplication#106
teng-lin merged 1 commit intomainfrom
fix/pr105-review-followup

Conversation

@teng-lin
Copy link
Copy Markdown
Owner

Summary

Follow-up to PR #105's Gemini code review, which suggested extracting repeated logic into helpers to reduce test duplication.

  • Extended makeAssistantMsg helper with optional metadata overrides parameter
  • Converted 5 pre-existing mapAssistantMessage tests to use the helper
  • Kept 2 edge-case tests (message_id missing, usage missing) with raw createUnifiedMessage since they intentionally test absent fields
  • Net -49 lines of duplicated metadata boilerplate

Test plan

  • All 33 consumer-message-mapper tests pass
  • Full suite: 2449/2449 tests pass
  • Biome check clean

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @teng-lin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors test code within the consumer-message-mapper to improve maintainability and reduce duplication. By enhancing an existing test helper, several test cases now benefit from a more concise and reusable structure. Additionally, associated documentation has been updated to reflect current system capabilities and resolve previously noted inconsistencies, ensuring consistency across the project.

Highlights

  • Test Helper Extension: The makeAssistantMsg helper in consumer-message-mapper.test.ts has been extended to accept an optional metadata overrides parameter, allowing for more flexible test case creation.
  • Test Duplication Reduction: Five pre-existing mapAssistantMessage tests were converted to utilize the extended helper, significantly reducing metadata boilerplate and resulting in a net reduction of 49 lines of code.
  • Documentation Updates: The README.md and docs/unified-message-protocol.md files were updated to reflect changes in terminology, clarify message processing flows, and mark previously identified issues as resolved.
  • Claude Adapter Capabilities: The documentation now accurately states that the Claude adapter handles all seven content types (text, tool_use, tool_result, thinking, image, code, refusal), resolving a previous 'silent drop' issue.
Changelog
  • README.md
    • Renamed 'SessionBridge' to 'BeamCode' in diagrams and descriptive text for consistency.
    • Updated the description of session collaboration to clarify the N:1 relationship.
    • Removed the 'Programmatic usage' section, streamlining the documentation.
  • docs/unified-message-protocol.md
    • Updated the description of the State Reducer to accurately reflect its explicit switch cases and team scan functionality.
    • Corrected entries in the 'UnifiedMessage Type Coverage' table, specifically for the State Reducer column, to reflect current message handling.
    • Revised notes regarding permission_request filtering and the control_response stub in the state reducer.
    • Updated the 'Adapter content block handling' section to indicate that the Claude adapter now supports all 7 content types.
    • Adjusted the 'Complete Silent Drop Inventory' count from 15 to 14 and clarified the description for item 4.
    • Marked 'ISSUE 1: Claude Adapter Drops Rich Content Blocks' and 'ISSUE 4: Test Coverage Gaps for Content Types' as resolved.
    • Renumbered the 'Remaining Open Issues' section from 8 to 7.
  • src/core/consumer-message-mapper.test.ts
    • Modified the makeAssistantMsg helper function to accept an optional metadata parameter, allowing custom metadata overrides.
    • Refactored five existing test cases (maps text content blocks, maps tool_use content blocks, maps tool_result content blocks, maps mixed content blocks, maps unknown content block types to empty text) to leverage the extended makeAssistantMsg helper, reducing boilerplate.
Activity
  • This pull request is a direct follow-up to a Gemini code review from PR fix: close remaining unified message protocol gaps #105, which recommended extracting repeated logic into helpers.
  • All 33 consumer-message-mapper tests have passed successfully.
  • The full test suite, comprising 2449 tests, has passed without failures.
  • The Biome check for code quality and formatting is clean.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively reduces test duplication in consumer-message-mapper.test.ts by extending the makeAssistantMsg helper, which improves code maintainability. The accompanying documentation updates are also valuable. I've left two comments: one concerning the removal of the 'Programmatic usage' section from the README, and another suggesting a small adjustment to a test case to better preserve its original data.

Comment thread README.md
Comment on lines 157 to 201
## Security
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.

medium

The 'Programmatic usage' section has been removed. This seems to be a significant documentation change that is out of scope for a test refactoring PR. This section appears valuable for users who want to integrate BeamCode as a library. If this removal was intentional, could you please explain the reasoning in the PR description? If the example is outdated, it would be better to update it or mark it as such, rather than removing it completely.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed — rebased onto current main so the README and docs changes are no longer in this PR's diff. The scope is now limited to the test refactoring only.

Comment on lines +117 to +123
const msg = makeAssistantMsg(
[
{ type: "text", text: "Let me run that" },
{ type: "tool_use", id: "tu-1", name: "Bash", input: { command: "ls" } },
],
metadata: {
message_id: "msg-004",
model: "claude-sonnet-4-5-20250929",
stop_reason: "end_turn",
usage: {
input_tokens: 100,
output_tokens: 50,
cache_creation_input_tokens: 10,
cache_read_input_tokens: 5,
},
parent_tool_use_id: null,
},
});
"msg-004",
);
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.

medium

The refactoring to use makeAssistantMsg here omits the metadata argument that was present in the original createUnifiedMessage call. The original call included specific stop_reason and usage values. While the current test assertions don't check these fields, removing this data makes the test case less representative. It would be better to preserve the original metadata by passing it to the helper to maintain test data fidelity.

    const msg = makeAssistantMsg(
      [
        { type: "text", text: "Let me run that" },
        { type: "tool_use", id: "tu-1", name: "Bash", input: { command: "ls" } },
      ],
      "msg-004",
      {
        stop_reason: "end_turn",
        usage: {
          input_tokens: 100,
          output_tokens: 50,
          cache_creation_input_tokens: 10,
          cache_read_input_tokens: 5,
        },
      },
    );

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Good catch — restored the original stop_reason and usage values via metadata overrides to preserve test data fidelity.

Address the broader Gemini review feedback from PR #105 by converting
pre-existing mapAssistantMessage tests to use the makeAssistantMsg
helper, adding optional metadata overrides support. Net -49 lines.
@teng-lin teng-lin force-pushed the fix/pr105-review-followup branch from a9a870c to 8a65834 Compare February 21, 2026 21:02
@teng-lin teng-lin merged commit 9f124f4 into main Feb 21, 2026
7 checks passed
@teng-lin teng-lin deleted the fix/pr105-review-followup branch February 21, 2026 21:10
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