[PR #104] fix: resolve failing tests in gh-desktop-release-notification and gh-core-tag-notification #105

Open
opened 2026-10-27 21:09:37 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Comfy-Org/Comfy-PR/pull/104
Author: @snomiao
Created: 11/5/2025
Status: 🔄 Open

Base: main ← Head: sno-fix-test-2025-11-05


📝 Commits (10+)

  • a35e766 fix: resolve failing tests in gh-desktop-release-notification and gh-core-tag-notification
  • e1a2b96 refactor: improve test mocking with factory pattern in gh-desktop-release-notification
  • 6bc19f4 refactor: improve test mocking with factory pattern in gh-core-tag-notification
  • 38d211c ci: enable tests to run on pull requests
  • 22a6799 feat: add desktop issue transfer task (#105)
  • 85fcb7d perf: optimize easylabel performance with metadata caching and streaming improvements (#110)
  • d493c3d Improve documentation consistency in frontend-to-desktop issue transfer task (#107)
  • e7ae199 docs: use generic repository references in transfer task documentation (#106)
  • a624c96 feat: add notify label pattern to easylabel allowlist (#112)
  • e39c456 docs: add comment about update notification feature in coreping (#111)

📊 Changes

368 files changed (+33551 additions, -6387 deletions)

View changed files

➕ .bot/AGENT.md (+898 -0)
➕ .bot/CLAUDE.md (+1 -0)
➕ .bot/README.md (+1 -0)
➕ .bot/SMART-READ-FEATURE.md (+144 -0)
➕ .bot/skills/code-search/SKILL.md (+22 -0)
➕ .bot/skills/github-issue-search/SKILL.md (+19 -0)
➕ .bot/skills/github-pr-bot/SKILL.md (+19 -0)
➕ .bot/skills/notion-search/SKILL.md (+19 -0)
➕ .bot/skills/registry-search/SKILL.md (+19 -0)
➕ .bot/skills/repo-reading/SKILL.md (+21 -0)
➕ .bot/skills/slack-file-sharing/SKILL.md (+31 -0)
➕ .bot/skills/slack-messaging/SKILL.md (+24 -0)
➕ .bot/skills/web-research/SKILL.md (+13 -0)
➕ .claude/skills/code-search/SKILL.md (+67 -0)
➕ .claude/skills/github-issue-search/SKILL.md (+83 -0)
➕ .claude/skills/github-pr-bot/SKILL.md (+60 -0)
➕ .claude/skills/notion-search/SKILL.md (+50 -0)
➕ .claude/skills/pr-bot-cli/SKILL.md (+127 -0)
➕ .claude/skills/registry-search/SKILL.md (+85 -0)
➕ .claude/skills/slack-msg-update/SKILL.md (+38 -0)

...and 80 more files

📄 Description

Summary

This PR fixes test failures in GitHub Actions CI and improves test code quality with a cleaner mocking pattern.

Root Cause

The tests were failing because:

  1. The database module (src/db/index.ts) uses top-level await to initialize MongoDB connection
  2. Jest-style mocks (jest.mock()) were not being applied before module imports in Bun's test runner
  3. Tests attempted to connect to MongoDB even though the database was supposed to be mocked

Changes Made

Test Infrastructure (Initial Fix)

  • Migrated from Jest mocks to Bun's native mocking: Replaced jest.mock() with mock.module() from bun:test
  • Dynamic imports: Used await import() to ensure mocks are set up before modules are loaded
  • MONGODB_URI environment variable: Added in src/test/msw-setup.ts to prevent production database connections

Code Quality Improvements (Refactoring)

  • Introduced factory pattern: Created createMockState() factory function for fresh test state
  • Closure-based mocking: Implemented createMockCollection() that references mockState via closure
  • Declarative state management: Replaced imperative mock reassignment with simple state reset in beforeEach
  • Per-test customization: Added findOneImpl and findOneAndUpdateImpl for easy test-specific behavior
  • Reduced boilerplate: Eliminated verbose manual mock function reassignments

Files Modified

  • app/tasks/gh-desktop-release-notification/index.spec.ts - Converted to Bun-native mocking + factory pattern
  • app/tasks/gh-core-tag-notification/index.spec.ts - Converted to Bun-native mocking + factory pattern
  • src/test/msw-setup.ts - Added MONGODB_URI environment variable for tests

Test Corrections

  • Fixed expected text formats to match actual implementation
  • Updated repo name format from `"desktop"` to `"Comfy-Org/desktop"` in assertions

Test Results

✅ All 16 tests now pass:

  • 10 tests in gh-desktop-release-notification
  • 6 tests in gh-core-tag-notification

```
16 pass
0 fail
23 expect() calls
Ran 16 tests across 2 files. [237.00ms]
```

Benefits of Refactoring

  1. Less verbose: No need to reassign mock functions in `beforeEach`
  2. More functional: State creation is pure and predictable
  3. More flexible: Easy per-test customization without mutation
  4. Better maintainability: Cleaner separation of concerns
  5. Consistent pattern: Same approach across both test files

Fixes failing tests from: https://github.com/Comfy-Org/Comfy-PR/actions/runs/19085256036/job/54523916169

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Comfy-Org/Comfy-PR/pull/104 **Author:** [@snomiao](https://github.com/snomiao) **Created:** 11/5/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `sno-fix-test-2025-11-05` --- ### 📝 Commits (10+) - [`a35e766`](https://github.com/Comfy-Org/Comfy-PR/commit/a35e7660265a1160ad5ef1a5132ba1f3c87a090a) fix: resolve failing tests in gh-desktop-release-notification and gh-core-tag-notification - [`e1a2b96`](https://github.com/Comfy-Org/Comfy-PR/commit/e1a2b96ffc2777fde4bd29db687f0d4887729bfc) refactor: improve test mocking with factory pattern in gh-desktop-release-notification - [`6bc19f4`](https://github.com/Comfy-Org/Comfy-PR/commit/6bc19f457dad5d89fd7d0c5b7f2260afe813c3b6) refactor: improve test mocking with factory pattern in gh-core-tag-notification - [`38d211c`](https://github.com/Comfy-Org/Comfy-PR/commit/38d211c827071df66dbd6ec2d4021cf8f459a811) ci: enable tests to run on pull requests - [`22a6799`](https://github.com/Comfy-Org/Comfy-PR/commit/22a67999fc0adb00708c12e01ffc462ecdf87695) feat: add desktop issue transfer task (#105) - [`85fcb7d`](https://github.com/Comfy-Org/Comfy-PR/commit/85fcb7df6f370b485b8784e1b75a9962d3a4f7d8) perf: optimize easylabel performance with metadata caching and streaming improvements (#110) - [`d493c3d`](https://github.com/Comfy-Org/Comfy-PR/commit/d493c3dd6fc0b3ff731774a5166169f48fa04a5e) Improve documentation consistency in frontend-to-desktop issue transfer task (#107) - [`e7ae199`](https://github.com/Comfy-Org/Comfy-PR/commit/e7ae199db3ae72370b0807e1014002cdf8b01fde) docs: use generic repository references in transfer task documentation (#106) - [`a624c96`](https://github.com/Comfy-Org/Comfy-PR/commit/a624c96abdae6483d9a2d7291ee40059652c9090) feat: add notify label pattern to easylabel allowlist (#112) - [`e39c456`](https://github.com/Comfy-Org/Comfy-PR/commit/e39c456929d97e2d1234e3fe5e123b267c33f1e7) docs: add comment about update notification feature in coreping (#111) ### 📊 Changes **368 files changed** (+33551 additions, -6387 deletions) <details> <summary>View changed files</summary> ➕ `.bot/AGENT.md` (+898 -0) ➕ `.bot/CLAUDE.md` (+1 -0) ➕ `.bot/README.md` (+1 -0) ➕ `.bot/SMART-READ-FEATURE.md` (+144 -0) ➕ `.bot/skills/code-search/SKILL.md` (+22 -0) ➕ `.bot/skills/github-issue-search/SKILL.md` (+19 -0) ➕ `.bot/skills/github-pr-bot/SKILL.md` (+19 -0) ➕ `.bot/skills/notion-search/SKILL.md` (+19 -0) ➕ `.bot/skills/registry-search/SKILL.md` (+19 -0) ➕ `.bot/skills/repo-reading/SKILL.md` (+21 -0) ➕ `.bot/skills/slack-file-sharing/SKILL.md` (+31 -0) ➕ `.bot/skills/slack-messaging/SKILL.md` (+24 -0) ➕ `.bot/skills/web-research/SKILL.md` (+13 -0) ➕ `.claude/skills/code-search/SKILL.md` (+67 -0) ➕ `.claude/skills/github-issue-search/SKILL.md` (+83 -0) ➕ `.claude/skills/github-pr-bot/SKILL.md` (+60 -0) ➕ `.claude/skills/notion-search/SKILL.md` (+50 -0) ➕ `.claude/skills/pr-bot-cli/SKILL.md` (+127 -0) ➕ `.claude/skills/registry-search/SKILL.md` (+85 -0) ➕ `.claude/skills/slack-msg-update/SKILL.md` (+38 -0) _...and 80 more files_ </details> ### 📄 Description ## Summary This PR fixes test failures in GitHub Actions CI and improves test code quality with a cleaner mocking pattern. ## Root Cause The tests were failing because: 1. The database module (`src/db/index.ts`) uses top-level `await` to initialize MongoDB connection 2. Jest-style mocks (`jest.mock()`) were not being applied before module imports in Bun's test runner 3. Tests attempted to connect to MongoDB even though the database was supposed to be mocked ## Changes Made ### Test Infrastructure (Initial Fix) - **Migrated from Jest mocks to Bun's native mocking**: Replaced `jest.mock()` with `mock.module()` from `bun:test` - **Dynamic imports**: Used `await import()` to ensure mocks are set up before modules are loaded - **MONGODB_URI environment variable**: Added in `src/test/msw-setup.ts` to prevent production database connections ### Code Quality Improvements (Refactoring) - **Introduced factory pattern**: Created `createMockState()` factory function for fresh test state - **Closure-based mocking**: Implemented `createMockCollection()` that references `mockState` via closure - **Declarative state management**: Replaced imperative mock reassignment with simple state reset in `beforeEach` - **Per-test customization**: Added `findOneImpl` and `findOneAndUpdateImpl` for easy test-specific behavior - **Reduced boilerplate**: Eliminated verbose manual mock function reassignments ### Files Modified - `app/tasks/gh-desktop-release-notification/index.spec.ts` - Converted to Bun-native mocking + factory pattern - `app/tasks/gh-core-tag-notification/index.spec.ts` - Converted to Bun-native mocking + factory pattern - `src/test/msw-setup.ts` - Added MONGODB_URI environment variable for tests ### Test Corrections - Fixed expected text formats to match actual implementation - Updated repo name format from \`"desktop"\` to \`"Comfy-Org/desktop"\` in assertions ## Test Results ✅ All 16 tests now pass: - 10 tests in gh-desktop-release-notification - 6 tests in gh-core-tag-notification \`\`\` 16 pass 0 fail 23 expect() calls Ran 16 tests across 2 files. [237.00ms] \`\`\` ## Benefits of Refactoring 1. **Less verbose**: No need to reassign mock functions in \`beforeEach\` 2. **More functional**: State creation is pure and predictable 3. **More flexible**: Easy per-test customization without mutation 4. **Better maintainability**: Cleaner separation of concerns 5. **Consistent pattern**: Same approach across both test files ## Related Issue Fixes failing tests from: https://github.com/Comfy-Org/Comfy-PR/actions/runs/19085256036/job/54523916169 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Comfy-Org/Comfy-PR#105
No description provided.