Skip to content

[Test Improver] Add unit tests for SteveWatchEventListenerManager - #119

Draft
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/subscribe-events-manager-156ff3e27de1c924
Draft

[Test Improver] Add unit tests for SteveWatchEventListenerManager#119
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/subscribe-events-manager-156ff3e27de1c924

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

🤖 This PR was created by Test Improver, an automated AI assistant focused on improving test coverage.

Goal and Rationale

shell/plugins/subscribe-events.ts (SteveWatchEventListenerManager) had zero test coverage. This class manages WebSocket watch registrations, event listeners, and callbacks — a critical part of Rancher's real-time resource update system. All 11 public methods are now covered.

Approach

  • Tested each public method of SteveWatchEventListenerManager in isolation
  • Used beforeEach to create a fresh instance to eliminate state leakage between tests
  • Used a makeParams helper to create STEVE_WATCH_PARAMS fixtures
  • Discovered and documented a type-declaration discrepancy: hasStandardWatch() declares boolean return type but returns undefined when no watch entry exists (uses optional chaining ?.hasStandardWatch)

Coverage Impact

File Before After
shell/plugins/subscribe-events.ts 0% ~100% (all branches)

Tests Added (36 total)

Method Cases
isSupportedEventType 4 — CHANGES=true, START/CREATE/REMOVE=false
getWatch 3 — undefined, after set, separate params
hasStandardWatch 3 — no watch, set true, cleared→undefined
setStandardWatch 5 — no-op on missing, creates, deletes, keeps with listeners, sets flag
hasEventListeners 3 — no watch, no callbacks, with callbacks
getEventListener 5 — no watch, wrong event, entryOnly, no callbacks, with callbacks
addEventListener 4 — throws on empty event, creates, idempotent, multiple events
triggerEventListener 3 — no listener, calls all callbacks, wrong event
triggerAllEventListeners 1 — calls callbacks for all events
addEventListenerCallback 2 — creates+registers, no duplicate overwrite
removeEventListenerCallback 3 — no-op, removes targeted, leaves others

Trade-offs

  • One test deliberately omits triggerAllEventListeners when no watch exists — the method does not guard against undefined watch and would throw TypeError; this is an implicit contract of the API (caller must ensure watch exists)
  • No mocking of keyForSubscribe — it's a pure string-formatting function and letting it run naturally keeps tests simpler and more realistic

Reproducibility

YARN_IGNORE_ENGINES=true NODE_OPTIONS=--max_old_space_size=8192 yarn test:ci --testPathPattern=shell/plugins/__tests__/subscribe-events.test.ts

Test Status

✅ 36/36 tests passing
✅ ESLint: no warnings

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • download.cypress.io

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "download.cypress.io"

See Network Configuration for more information.

Generated by Daily Test Improver · ● 3.6M ·

36 unit tests covering all public methods of SteveWatchEventListenerManager
in shell/plugins/subscribe-events.ts:

- isSupportedEventType: 4 cases (CHANGES=true, START/CREATE/REMOVE=false)
- getWatch: 3 cases (undefined, after setStandardWatch, separate params)
- hasStandardWatch: 3 cases (no watch, set true, cleared→undefined)
- setStandardWatch: 5 cases (no-op on missing, creates, deletes, keeps with listeners)
- hasEventListeners: 3 cases (no watch, no callbacks, with callbacks)
- getEventListener: 5 cases (no watch, wrong event, entryOnly, no-callbacks, with-callbacks)
- addEventListener: 4 cases (throws no event, creates, idempotent, multiple events)
- triggerEventListener: 3 cases (no listener, calls all callbacks, wrong event)
- triggerAllEventListeners: 1 case (calls callbacks for all events)
- addEventListenerCallback: 2 cases (creates+registers, no duplicate overwrite)
- removeEventListenerCallback: 3 cases (no-op, removes targeted, leaves others)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants