AI Agents SDE Task Viewer
      • Context
      • Plan
      • Prd
  1. Home
  2. AgentSDE
  3. agent-core
  4. gh-553
  5. plan
  6. plan.md
plan.md(3.6 KB)· Apr 23, 2026· 2 min read
  • Summary
  • Files
  • Steps
  • Verification
  • Risks
  • Assumptions

BJ-13: Unit tests — Bitbucket + Jira adapters#

Summary#

Add Jest unit specs for BitbucketAdapter and JiraAdapter covering verifySignature(), normalize() for every supported event, bot-self filtering, and /agentsde directive detection. Mirror the structure of github.adapter.spec.ts.

Files#

PathActionPurpose
src/webhook/adapters/__fixtures__/bitbucket/*.jsoncreateRealistic payloads from Atlassian docs — one per event key (7 files)
src/webhook/adapters/__fixtures__/jira/*.jsoncreateRealistic payloads from Atlassian docs — one per webhookEvent (5 files)
src/webhook/adapters/bitbucket.adapter.spec.tscreateFull spec for Bitbucket adapter
src/webhook/adapters/jira.adapter.spec.tscreateFull spec for Jira adapter
src/webhook/adapters/github.adapter.spec.tsinspectReference for structure, DI wiring, and assertion style

Steps#

  1. Author Bitbucket fixture JSON files for the 7 supported X-Event-Keys: pullrequest:created, pullrequest:updated, pullrequest:approved, pullrequest:changes_request_created, pullrequest:fulfilled, pullrequest:comment_created, repo:push. Source from Atlassian webhook docs.
  2. Write bitbucket.adapter.spec.ts with a TestingModule that provides ConfigService + PLATFORM_AUTH_PROVIDER mock returning AGENT_USERNAME. Cover: (a) verifySignature() — valid ?secret= query, missing secret, wrong secret, disallowed IP when BITBUCKET_WEBHOOK_IP_ALLOWLIST is set; (b) normalize() — one it per event key asserting resulting eventType/issueNumber/prNumber/actor; (c) pullrequest:comment_created by bot → { event: null } with reason mentioning AGENT_USERNAME; (d) /agentsde directive and legacy /agent detection; (e) unsupported X-Event-Key → { event: null, reason }.
  3. Author Jira fixture JSON files for the 5 supported webhookEvent values: jira:issue_created, jira:issue_updated (with changelog), jira:issue_deleted, comment_created, jira:issuelink_created. Source from Atlassian webhook docs.
  4. Write jira.adapter.spec.ts with identical DI wiring. Cover: (a) verifySignature() — valid HMAC, missing header, bad signature, tampered body via the shared verifyHmacSha256 helper in src/webhook/crypto.ts; (b) normalize() — one it per webhookEvent asserting correct eventType; (c) jira:issue_updated inspects changelog for label transitions; (d) comment_created by bot → { event: null }; (e) /agentsde directive detection on comment events; (f) unsupported webhookEvent → { event: null, reason }.
  5. Run npm run lint and npm run test -- --testPathPattern 'adapters/(bitbucket|jira)' until green (zero warnings, all specs pass).

Verification#

  • Every switch-case branch in both adapters has at least one dedicated spec.
  • npm run test passes; npm run lint reports zero warnings.
  • Bot-self filter, /agentsde detection, and unsupported-event fallbacks are each exercised by a named test.

Risks#

  • Depends on #546 and #547 merging first — without the adapter files, tests cannot compile. Delivery phase must wait until those adapters land on rc/atlassian-integration.
  • Fixture shape drift: if the adapter implementations diverge from the documented event maps, specs will fail. Mitigate by sourcing fixtures from Atlassian docs rather than inventing fields.

Assumptions#

  • Branch target is rc/atlassian-integration (per issue).
  • verifyHmacSha256 helper exists at src/webhook/crypto.ts by the time tests run (extracted in #547).
  • Bot-self filter reads username from PLATFORM_AUTH_PROVIDER.getBotUsername(), matching the pattern in github.adapter.ts:22.
ContextPrd