Skip to content

test(triggers): add unit tests for github trigger utilities and agent result handler#315

Merged
zbigniewsobiecki merged 1 commit intodevfrom
feature/github-trigger-utils-tests
Feb 16, 2026
Merged

test(triggers): add unit tests for github trigger utilities and agent result handler#315
zbigniewsobiecki merged 1 commit intodevfrom
feature/github-trigger-utils-tests

Conversation

@zbigniewsobiecki
Copy link
Copy Markdown
Member

Summary

This PR adds comprehensive unit tests for two critical utility modules in the trigger system:

  • src/triggers/github/utils.ts — URL parsing and work item extraction logic (was at 53.22% coverage)
  • src/triggers/shared/agent-result-handler.ts — Result artifact handling and cost accumulation (was at 0% coverage)

Test Coverage

github-utils.test.ts (27 tests):

  • extractTrelloCardId — null input, no URL, valid URL with/without slug, multiple URLs, alphanumeric IDs
  • hasTrelloCardUrl — truthy/falsy cases
  • extractJiraIssueKey — null input, no key found, valid keys, embedded keys, word boundaries
  • extractWorkItemId — Trello vs JIRA delegation, null handling
  • requireWorkItemId — returns null with logging when no ID, returns ID when present

agent-result-handler.test.ts (9 tests):

  • handleAgentResultArtifacts — cost accumulation, rounding to 4 decimals
  • ✅ Skips when no cost field configured (Trello and JIRA)
  • ✅ Skips when cost is zero or undefined
  • ✅ Uses correct cost field for JIRA vs Trello projects
  • ✅ Handles failed agent results with cost

Key Test Patterns

  • Pure function testing for URL/text parsers (no mocks needed)
  • Mocked getPMProvider and safeOperation for side-effect tests
  • Follows existing tests/unit/triggers/ conventions
  • All tests pass, lint clean, type checks clean

Related

Trello Card: https://trello.com/c/6993804d370da297fe1d6da8

@aaight
Copy link
Copy Markdown
Collaborator

aaight commented Feb 16, 2026

🔍 Reviewing PR...

Copy link
Copy Markdown
Collaborator

@aaight aaight left a comment

Choose a reason for hiding this comment

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

LGTM — Clean, well-structured unit tests that correctly exercise the source implementations.

I verified the tests against the source code in src/triggers/github/utils.ts and src/triggers/shared/agent-result-handler.ts:

  • github-utils tests: Correctly test all exported pure functions against the actual regex patterns (TRELLO_CARD_URL_REGEX, JIRA_ISSUE_KEY_REGEX). Edge cases (null input, multiple matches, word boundaries) are well-covered. The extractWorkItemId and requireWorkItemId delegation tests correctly reflect the pm.type === 'jira' branching logic.
  • agent-result-handler tests: The safeOperation mock correctly bypasses the wrapper to test the inner callback logic. The getPMProvider mock works correctly since it's called inside the safeOperation callback. The rounding test (1.123456 + 0.987654 = 2.1111) matches the actual Math.round(x * 10000) / 10000 logic. Both Trello and JIRA cost field resolution paths are tested, including skip-conditions (no field configured, zero cost, undefined cost).
  • Test conventions follow existing patterns in tests/unit/triggers/.
  • All CI checks pass.

One minor observation (not blocking): the comment on line 128 of github-utils.test.ts ("Should not match partial strings") is slightly misleading — the test actually demonstrates that word boundaries correctly truncate the match at NOTAKEY-123 rather than including -MORE. The expectation is correct; it's just the comment phrasing that's a bit ambiguous.

@zbigniewsobiecki zbigniewsobiecki merged commit 6cfca57 into dev Feb 16, 2026
4 checks passed
@zbigniewsobiecki zbigniewsobiecki deleted the feature/github-trigger-utils-tests branch March 16, 2026 16:43
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.

2 participants