Skip to content

Conversation

@dereknance
Copy link
Contributor

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-27862

📔 Objective

This PR is a follow-up to #17245 for fixing the memory storage tests that were skipped as part of those changes.

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

This commit fixes the tests that were skipped as part of #17245.
@dereknance dereknance requested a review from a team as a code owner December 31, 2025 18:19
@dereknance dereknance requested a review from djsmith85 December 31, 2025 18:19
@dereknance dereknance added the ai-review Request a Claude code review label Dec 31, 2025
@dereknance dereknance enabled auto-merge (squash) December 31, 2025 18:20
@claude
Copy link
Contributor

claude bot commented Dec 31, 2025

Claude finished @dereknance's task in 2m 8s —— View job


Overall Assessment: APPROVE

This PR correctly fixes the skipped memory storage tests from #17245 by completing the mock port implementation and using the appropriate Jest cleanup method.

Code Review Details

Changes Reviewed:

  • apps/browser/spec/mock-port.spec-util.ts - Added origin property to mock port sender
  • apps/browser/src/platform/storage/memory-storage-service-interactions.spec.ts - Un-skipped tests and switched to clearAllMocks()

Analysis:

The root cause of the test failures was that PR #17245 added BrowserApi.senderIsInternal() validation which checks sender?.origin, but the mock only provided sender.url. Adding the origin property completes the mock to match real Chrome runtime port behavior.

The change from jest.resetAllMocks() to jest.clearAllMocks() is correct because:

  • resetAllMocks() would reset the mock implementations set up in beforeEach
  • clearAllMocks() preserves implementations while clearing call history
  • This pattern is consistent with other test files in the browser codebase

No issues found. The changes are minimal, targeted, and correctly address the test failures.


🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.5 [email protected]

@github-actions
Copy link
Contributor

Logo
Checkmarx One – Scan Summary & Details7d0eab67-46b8-4c42-8e3b-96c775f72009

Great job! No new security vulnerabilities introduced in this pull request

@codecov
Copy link

codecov bot commented Dec 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.32%. Comparing base (c6b0208) to head (9ece594).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #18168      +/-   ##
==========================================
+ Coverage   42.27%   42.32%   +0.05%     
==========================================
  Files        3599     3599              
  Lines      104548   104548              
  Branches    15780    15780              
==========================================
+ Hits        44194    44251      +57     
+ Misses      58473    58412      -61     
- Partials     1881     1885       +4     

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@diffray-bot
Copy link

Changes Summary

This PR re-enables previously skipped memory storage interaction tests by fixing the mock port utility. The fix addresses issues introduced in PR #17245 by adding the missing origin property to the mock port.sender object and changing jest.resetAllMocks() to jest.clearAllMocks() in the test cleanup.

Type: bugfix

Components Affected: browser/spec/mock-port.spec-util, browser/platform/storage/memory-storage-service-interactions.spec

Files Changed
File Summary Change Impact
...kspace/apps/browser/spec/mock-port.spec-util.ts Added missing origin property to mock port sender object alongside existing url property ✏️ 🟡
...age/memory-storage-service-interactions.spec.ts Re-enabled previously skipped test suite by removing describe.skip and changed jest.resetAllMocks() to jest.clearAllMocks() for proper mock cleanup ✏️ 🟡

Risk Areas: Test isolation: Switching from resetAllMocks() to clearAllMocks() changes mock cleanup behavior - resetAllMocks() clears all implementations and call history, while clearAllMocks() only clears call history. This could affect test isolation if not properly understood., Mock completeness: The origin property addition suggests the mock was incomplete in handling chrome.runtime.Port types. Need to verify this property is used correctly by the services being tested., Port.sender requirements: Changes to mock sender object may reveal assumptions about chrome extension messaging APIs that weren't previously tested.

Suggestions
  • Verify that jest.clearAllMocks() provides sufficient cleanup for this test suite - confirm there are no lingering mock implementations from previous tests
  • Document why the origin property was necessary and wasn't included in the original mock port utility
  • Consider if other tests using mockPorts() need similar updates or are affected by the origin property addition

Full review in progress... | Powered by diffray

Comment on lines 12 to +18
(chrome.runtime.connect as jest.Mock).mockImplementation((portInfo) => {
const port = mockDeep<chrome.runtime.Port>();
port.name = portInfo.name;
port.sender = { url: chrome.runtime.getURL("") };
port.sender = {
url: chrome.runtime.getURL(""),
origin: chrome.runtime.getURL(""),
};

Choose a reason for hiding this comment

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

🟠 HIGH - JSDoc parameters do not match function signature
Agent: react

Category: docs

Description:
The JSDoc comment documents @param name and @param immediateOnConnectExecution, but the mockPorts() function takes no parameters. This creates misleading documentation.

Suggestion:
Remove the @param tags from the JSDoc since the function takes no parameters, or add the documented parameters to the function signature if they were intended.

Confidence: 95%
Rule: ts_always_use_jsdoc_for_documentation
Review ID: 17ab85c0-047a-4959-8626-3febe24d50d5
Rate it 👍 or 👎 to improve future reviews | Powered by diffray

};

// convert to internal port
delete (port as any).tab;

Choose a reason for hiding this comment

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

🟡 MEDIUM - Multiple uses of 'any' type assertion for port deletion
Agent: react

Category: quality

Description:
Lines 21-24 use 'as any' type assertions to delete properties from the port object. This defeats type safety.

Suggestion:
Use a more specific type assertion like 'delete (port as Partial<chrome.runtime.Port>).tab' or create a properly typed test utility.

Confidence: 75%
Rule: ts_prefer_specific_types_over_any_unknown_w
Review ID: 17ab85c0-047a-4959-8626-3febe24d50d5
Rate it 👍 or 👎 to improve future reviews | Powered by diffray

jest.clearAllMocks();
});

test.each(["has", "get"])(

Choose a reason for hiding this comment

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

🟠 HIGH - Missing edge case tests for null/undefined values
Agent: testing

Category: quality

Description:
The parametrized test for 'has' and 'get' actions only tests with a simple string value. Missing tests for null, undefined, empty string edge cases.

Suggestion:
Add additional test cases covering edge cases: null values, undefined, empty strings to verify the service handles these appropriately

Confidence: 75%
Rule: test_js_missing_edge_cases
Review ID: 17ab85c0-047a-4959-8626-3febe24d50d5
Rate it 👍 or 👎 to improve future reviews | Powered by diffray


// These are succeeding individually but failing in a batch run - skipping for now
describe.skip("foreground background memory storage interaction", () => {
describe("foreground background memory storage interaction", () => {

Choose a reason for hiding this comment

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

🟡 MEDIUM - Missing error condition tests
Agent: testing

Category: quality

Description:
The test suite only covers happy paths. No tests for error conditions such as rejected promises or service failures.

Suggestion:
Add tests using mockRejectedValue() to cover error scenarios and verify error propagation

Confidence: 70%
Rule: test_js_missing_edge_cases
Review ID: 17ab85c0-047a-4959-8626-3febe24d50d5
Rate it 👍 or 👎 to improve future reviews | Powered by diffray

@diffray-bot
Copy link

Review Summary

Free public review - Want AI code reviews on your PRs? Check out diffray.ai

Validated 10 issues: 5 kept (documentation bug, quality concerns, testing gaps), 5 filtered (low confidence, minor impact, or inaccurate analysis)

Issues Found: 5

💬 See 4 individual line comment(s) for details.

📊 4 unique issue type(s) across 5 location(s)

📋 Full issue list (click to expand)

🟠 HIGH - JSDoc parameters do not match function signature

Agent: react

Category: docs

File: apps/browser/spec/mock-port.spec-util.ts:12-18

Description: The JSDoc comment documents @param name and @param immediateOnConnectExecution, but the mockPorts() function takes no parameters. This creates misleading documentation.

Suggestion: Remove the @param tags from the JSDoc since the function takes no parameters, or add the documented parameters to the function signature if they were intended.

Confidence: 95%

Rule: ts_always_use_jsdoc_for_documentation


🟠 HIGH - Missing edge case tests for null/undefined values (2 occurrences)

Agent: testing

Category: quality

📍 View all locations
File Description Suggestion Confidence
apps/browser/src/platform/storage/memory-storage-service-interactions.spec.ts:33 The parametrized test for 'has' and 'get' actions only tests with a simple string value. Missing tes... Add additional test cases covering edge cases: null values, undefined, empty strings to verify the s... 75%
apps/browser/src/platform/storage/memory-storage-service-interactions.spec.ts:16 The test suite only covers happy paths. No tests for error conditions such as rejected promises or s... Add tests using mockRejectedValue() to cover error scenarios and verify error propagation 70%

Rule: test_js_missing_edge_cases


🟡 MEDIUM - Multiple uses of 'any' type assertion for port deletion

Agent: react

Category: quality

File: apps/browser/spec/mock-port.spec-util.ts:21

Description: Lines 21-24 use 'as any' type assertions to delete properties from the port object. This defeats type safety.

Suggestion: Use a more specific type assertion like 'delete (port as Partial<chrome.runtime.Port>).tab' or create a properly typed test utility.

Confidence: 75%

Rule: ts_prefer_specific_types_over_any_unknown_w


🟡 MEDIUM - Private property access breaks encapsulation

Agent: quality

Category: quality

File: apps/browser/src/platform/storage/memory-storage-service-interactions.spec.ts:72-82

Description: The test accesses private _port property using bracket notation (secondForeground['_port']) to bypass TypeScript's access modifiers. This makes the test brittle to internal refactoring.

Suggestion: Expose the port as a protected/internal property for testing, or refactor to test behavior only via public APIs.

Confidence: 70%

Rule: quality_missing_project_pattern


ℹ️ 1 issue(s) outside PR diff (click to expand)

These issues were found in lines not modified in this PR.

🟡 MEDIUM - Private property access breaks encapsulation

Agent: quality

Category: quality

File: apps/browser/src/platform/storage/memory-storage-service-interactions.spec.ts:72-82

Description: The test accesses private _port property using bracket notation (secondForeground['_port']) to bypass TypeScript's access modifiers. This makes the test brittle to internal refactoring.

Suggestion: Expose the port as a protected/internal property for testing, or refactor to test behavior only via public APIs.

Confidence: 70%

Rule: quality_missing_project_pattern



Review ID: 17ab85c0-047a-4959-8626-3febe24d50d5
Rate it 👍 or 👎 to improve future reviews | Powered by diffray

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants