Skip to content

fix(pm): polish card attachment image pre-fetching in readWorkItemWithMedia#946

Merged
zbigniewsobiecki merged 1 commit intodevfrom
fix/readworkitem-attachment-media-polish
Mar 18, 2026
Merged

fix(pm): polish card attachment image pre-fetching in readWorkItemWithMedia#946
zbigniewsobiecki merged 1 commit intodevfrom
fix/readworkitem-attachment-media-polish

Conversation

@zbigniewsobiecki
Copy link
Copy Markdown
Member

Summary

Follows up on the initial implementation that added card-level attachment images to readWorkItemWithMedia(), addressing four code-quality issues and one correctness bug identified in review.

  • Use canonical Attachment type — remove local interface Attachment shadow that weakened mimeType to optional, causing a spurious .filter() guard and ! non-null assertion. Now imports Attachment directly from src/pm/index.ts.
  • Rename section headingformatInlineMediaformatPreFetchedImages, heading ## Inline Media## Pre-fetched Images (card-level attachments are not "inline").
  • Fix JIRA/Trello deduplication bug — deduplicate allMedia by URL before building the text output and returning. In JIRA, description images are always backed by an attachment, so the same URL appeared twice (wasting an image slot and printing the entry twice). First occurrence wins, preserving description > attachment > comment priority.
  • Fix test fixture — the "no mimeType" test violated the canonical Attachment contract by omitting mimeType entirely. Replace with a valid application/pdf fixture that tests the real invariant: non-image MIME types are excluded.

Test plan

  • All 22 readWorkItem unit tests pass (npx vitest run tests/unit/gadgets/pm/core/readWorkItem.test.ts)
  • New deduplication test covers JIRA scenario (same URL in inlineMedia + getAttachments; asserts length=1 and source: 'description' wins)
  • Fixed test now uses valid Attachment fixture with mimeType: 'application/pdf'
  • Pre-push hook: 97 test files / 1952 tests all pass
  • npm run lint — clean
  • npm run typecheck — clean

🤖 Generated with Claude Code

…hMedia

Four code-quality issues identified in review, plus a correctness bug:

1. **Type deduplication** — remove local `interface Attachment` shadow that
   weakened `mimeType` to optional. Import the canonical `Attachment` type
   from `src/pm/index.ts` (`mimeType: string`, required), eliminating the
   spurious `.filter((att) => att.mimeType)` guard and `!` non-null assertion.

2. **Section heading** — rename `formatInlineMedia` → `formatPreFetchedImages`
   and change the rendered heading from `## Inline Media` to
   `## Pre-fetched Images` (card-level attachments are not "inline").

3. **URL deduplication** — deduplicate `allMedia` by URL before building the
   text section and returning. In JIRA, description images are always backed
   by an attachment, so the same URL appeared twice (once via
   `item.inlineMedia` with `source: 'description'`, once via
   `getAttachments()` with `source: 'attachment'`), wasting one of the
   MAX_IMAGES_PER_WORK_ITEM slots and printing the image line twice.
   First occurrence wins, preserving description > attachment > comment priority.

4. **Test correctness** — fix the "no mimeType" test, which violated the
   canonical Attachment contract by omitting `mimeType` entirely. Replace with
   a valid fixture (`mimeType: 'application/pdf'`) that tests the real
   invariant: non-image MIME types are excluded.

5. **New deduplication test** — covers the JIRA scenario where the same image
   URL appears in both `inlineMedia` (source: description) and `getAttachments`
   (source: attachment); asserts length=1 and that description source wins.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@zbigniewsobiecki zbigniewsobiecki merged commit 0b63b0d into dev Mar 18, 2026
8 checks passed
@zbigniewsobiecki zbigniewsobiecki deleted the fix/readworkitem-attachment-media-polish branch March 18, 2026 17:50
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

1 participant