Skip to content

test(pm): add comprehensive tests for PM lifecycle, factory, and context modules#313

Merged
zbigniewsobiecki merged 1 commit intodevfrom
test/pm-lifecycle-module
Feb 16, 2026
Merged

test(pm): add comprehensive tests for PM lifecycle, factory, and context modules#313
zbigniewsobiecki merged 1 commit intodevfrom
test/pm-lifecycle-module

Conversation

@zbigniewsobiecki
Copy link
Copy Markdown
Member

Summary

  • Added comprehensive unit tests for src/pm/lifecycle.ts (PMLifecycleManager class and resolveProjectPMConfig function)
  • Added unit tests for src/pm/factory.ts (createPMProvider factory function)
  • Added unit tests for src/pm/context.ts (AsyncLocalStorage-based PM provider scoping)
  • Achieved 100% code coverage for all three target modules

Test Coverage

PMLifecycleManager (lifecycle.test.ts)

  • prepareForAgent() - adds processing label, removes ready/processed labels, moves to inProgress for implementation agents
  • handleSuccess() - adds processed label, moves to inReview for implementation agents, adds PR comment when URL provided
  • handleFailure() - adds error label, posts error comment when message provided
  • handleBudgetExceeded() - removes processing label, adds error label, posts budget exceeded message
  • handleBudgetWarning() - adds error label, posts budget warning message
  • cleanupProcessing() - removes processing label
  • handleError() - adds error label and error comment
  • ✅ Handles undefined labels/statuses gracefully

resolveProjectPMConfig (lifecycle.test.ts)

  • ✅ Returns correct JIRA config (hardcoded label strings + status names from config)
  • ✅ Returns correct Trello config (label IDs + list IDs from config)
  • ✅ Defaults to Trello when pm.type is undefined
  • ✅ Handles missing optional labels/lists

createPMProvider (factory.test.ts)

  • ✅ Returns TrelloPMProvider for pm.type='trello'
  • ✅ Returns TrelloPMProvider when pm.type is undefined (default)
  • ✅ Returns JiraPMProvider for pm.type='jira' with valid config
  • ✅ Throws error when pm.type='jira' but jira config is missing
  • ✅ Throws error for unknown pm.type

PM Context (context.test.ts)

  • withPMProvider() - makes provider available within async context
  • ✅ Isolates provider scope between concurrent calls
  • ✅ Removes provider from context after callback completes
  • ✅ Propagates errors from callback
  • ✅ Returns callback result
  • getPMProvider() - returns provider when in context, throws helpful error when not
  • getPMProviderOrNull() - returns provider when in context, returns null when not (no throw)
  • ✅ Handles nested contexts correctly (inner overrides outer, outer restored after inner completes)

Test Results

All 40 tests pass with 100% coverage:

  • lifecycle.ts: 100% statements, 97.29% branches, 100% functions, 100% lines
  • factory.ts: 100% coverage across all metrics
  • context.ts: 100% coverage across all metrics

Related

Fixes: https://trello.com/c/YA4xP5oD/13

@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 — Tests are well-structured, correctly exercise all public APIs of the three modules, and the mocking strategy is sound. The safeOperation mock correctly bypasses error-swallowing to allow direct assertion on provider calls, the context.test.ts exercises the real AsyncLocalStorage implementation with proper concurrency and nesting scenarios, and the factory.test.ts correctly leverages Vitest's mock hoisting. All assertions match the source code.

@zbigniewsobiecki zbigniewsobiecki merged commit 66f1b5d into dev Feb 16, 2026
4 checks passed
@zbigniewsobiecki zbigniewsobiecki deleted the test/pm-lifecycle-module 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