Skip to content

refactor(router): decompose acknowledgments.ts god module into focused modules#590

Merged
zbigniewsobiecki merged 1 commit intodevfrom
feature/router-acknowledgments-refactor
Mar 1, 2026
Merged

refactor(router): decompose acknowledgments.ts god module into focused modules#590
zbigniewsobiecki merged 1 commit intodevfrom
feature/router-acknowledgments-refactor

Conversation

@aaight
Copy link
Copy Markdown
Collaborator

@aaight aaight commented Mar 1, 2026

Summary

Refactors src/router/acknowledgments.ts — a 242-line "God Module" mixing 4 unrelated concerns — into focused, single-responsibility modules.

Changes:

  • Extract bot identity resolution into new src/router/bot-identity-resolvers.ts — moves resolveJiraBotAccountId(), resolveTrelloBotMemberId() and their TTL caches out of acknowledgments.ts; re-exported from acknowledgments.ts for backward compatibility
  • Extract GitHub token resolution into new src/router/github-token-resolver.ts — moves resolveGitHubTokenForAck() and resolveGitHubTokenForAckByAgent() into their own module; re-exported from acknowledgments.ts for backward compatibility
  • Eliminate duplicate JIRA ack logicJiraPlatformClient.postComment() now uses JIRA API v3 with ADF bodies (matching what postJiraAck() was doing inline), so postJiraAck() and deleteJiraAck() now delegate to the client, removing ~30 lines of duplicated fetch code and the direct markdownToAdf import from acknowledgments.ts
  • Add 5s TTL cache to loadProjectConfig() — eliminates ~10 redundant DB queries per webhook event across the adapter chain; adds _resetProjectConfigCache() for testing
  • Clean up acknowledgments.ts — reduced from 242 lines to ~90 lines; now only contains ack CRUD wrappers that delegate to PlatformCommentClient implementations
  • Add test files for the two new modules: bot-identity-resolvers.test.ts and github-token-resolver.test.ts
  • Update tests to reflect new log message patterns and caching behavior

Card: https://trello.com/c/69a43240de86804a4bcf78cc

Test plan

  • All 3575 unit tests pass
  • TypeScript type checking passes (zero errors)
  • Lint passes (zero errors, 11 pre-existing warnings)
  • New test files added for bot-identity-resolvers.ts and github-token-resolver.ts (18 new tests)
  • Config cache test updated to verify TTL cache behavior
  • Acknowledgments test updated for new JiraPlatformClient log message prefix
  • Notifications test updated for JIRA API v3 endpoint

🤖 Generated with Claude Code

@nhopeatall
Copy link
Copy Markdown
Collaborator

nhopeatall commented Mar 1, 2026

✨ On it — checking the router acknowledgments refactor


Progress: [░░░░░░░░░░] 3% (iteration 2/70)

🔍 Code Review Update (1 min)

I've started my review by examining the PR diff to understand the overall changes. I'm now focusing on key files to grasp existing patterns and ensure the proposed changes align with them. My next step will be to drill down into specific modules, starting with backend.core.configuration.backend-config.router-configuration, to assess the quality and correctness of the code.

Last updated: iteration 2 · review

@nhopeatall
Copy link
Copy Markdown
Collaborator

nhopeatall commented Mar 1, 2026

Review complete — APPROVED

Clean god module decomposition. The extraction is behavior-preserving, backward compatibility is maintained via re-exports, the config cache design is appropriate for Node.js's single-threaded model, and all CI checks pass. No issues found.

Full review

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

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

Summary

LGTM — Clean god module decomposition that correctly extracts 4 concerns into focused modules while maintaining full backward compatibility through re-exports. All CI checks pass.

Notes

  • Extraction is behavior-preserving: The bot identity resolvers and GitHub token resolver are moved verbatim. The JIRA ack functions now delegate to JiraPlatformClient which was already performing the same fetch logic — the only difference being the upgrade from api/2 to api/3 with ADF, which was already happening inline in acknowledgments.ts before this PR (the old postJiraAck already used markdownToAdf + api/3). The client now owns that conversion, eliminating the duplication.

  • Cache design is appropriate: The loadProjectConfig() TTL cache uses module-level variables with Date.now() comparison. In Node.js's single-threaded model, there are no race conditions. The 5s TTL is short enough to pick up config changes without meaningful staleness. The _resetProjectConfigCache() escape hatch for tests is consistent with the existing _reset* pattern used by BotIdentityCache and _resetJiraCloudIdCache.

  • deleteComment still uses api/2: JiraPlatformClient.deleteComment() (line 65) uses /rest/api/2/ while postComment() was upgraded to /rest/api/3/. This is fine — JIRA's DELETE endpoint is version-agnostic and doesn't require ADF — just noting the intentional asymmetry.

  • Re-exports preserve public API: All existing import paths through acknowledgments.ts continue to work. The new ResolvedGitHubToken named interface is structurally identical to the previous inline { token: string; project: ProjectConfig } return type.

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

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

Review already submitted — APPROVED. See #590 (review)

@zbigniewsobiecki zbigniewsobiecki merged commit a09b969 into dev Mar 1, 2026
6 checks passed
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.

3 participants