fix(pm): polish card attachment image pre-fetching in readWorkItemWithMedia#946
Merged
zbigniewsobiecki merged 1 commit intodevfrom Mar 18, 2026
Merged
Conversation
…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>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.Attachmenttype — remove localinterface Attachmentshadow that weakenedmimeTypeto optional, causing a spurious.filter()guard and!non-null assertion. Now importsAttachmentdirectly fromsrc/pm/index.ts.formatInlineMedia→formatPreFetchedImages, heading## Inline Media→## Pre-fetched Images(card-level attachments are not "inline").allMediaby 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.Attachmentcontract by omittingmimeTypeentirely. Replace with a validapplication/pdffixture that tests the real invariant: non-image MIME types are excluded.Test plan
readWorkItemunit tests pass (npx vitest run tests/unit/gadgets/pm/core/readWorkItem.test.ts)inlineMedia+getAttachments; asserts length=1 andsource: 'description'wins)Attachmentfixture withmimeType: 'application/pdf'npm run lint— cleannpm run typecheck— clean🤖 Generated with Claude Code