Skip to content

Fix canMergeCompleteBundle returning true for empty attachment logs#1283

Closed
chiaramapellimt wants to merge 4 commits into
mainfrom
NIAD-3467
Closed

Fix canMergeCompleteBundle returning true for empty attachment logs#1283
chiaramapellimt wants to merge 4 commits into
mainfrom
NIAD-3467

Conversation

@chiaramapellimt
Copy link
Copy Markdown
Contributor

@chiaramapellimt chiaramapellimt commented Jun 3, 2026

What

Add an empty list guard to canMergeCompleteBundle in InboundMessageMergingService to prevent premature bundle building when all attachment logs have been deleted. Also adds a new unit test When_AllAttachmentLogsDeleted_CanMergeCompleteBundle_Expect_ReturnFalse and renames When_AllUploadsComplete_CanMergeCompleteBundle_Expect_ReturnTrue to When_AllUploadsComplete_AndLogsNotEmpty_CanMergeCompleteBundle_Expect_ReturnTrue for clarity.

Why

When the last attachment chunk of a large GP2GP patient record transfer arrives, checkAndMergeFileParts merges the fragments and then deletes their logs from the DB as cleanup. Immediately after, canMergeCompleteBundle checks those same logs to decide if the bundle is ready to build but they've just been deleted, so the list is empty. Java's allMatch() on an empty list always returns true, so the bundle gets built too early with no attachments.

The result is a blank patient record in Medicus after the transfer.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Internal change (non-breaking change with no effect on the functionality affecting end users)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I have performed a self-review of my code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the Changelog with details of my change in the UNRELEASED section if this change will affect end users
  • A corresponding change has been made to the Mapping Documentation repository

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

Images built and published to ECR using a Build Id of PR-1115-6c39583

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a bug in the GP2GP translator’s large-message flow where canMergeCompleteBundle could return true when there are no undeleted attachment logs (because Stream.allMatch(...) is vacuously true on an empty stream), leading to premature bundle creation with missing attachments.

Changes:

  • Add an explicit empty-list guard to InboundMessageMergingService.canMergeCompleteBundle.
  • Update/extend unit tests to cover the empty/“all deleted” attachment log scenario and clarify an existing test name.
  • Document the fix in CHANGELOG.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
gp2gp-translator/src/main/java/uk/nhs/adaptors/pss/translator/service/InboundMessageMergingService.java Adds an undeletedLogs.isEmpty() guard to prevent vacuous allMatch() returning true.
gp2gp-translator/src/test/java/uk/nhs/adaptors/pss/translator/service/InboundMessageMergingServiceTests.java Adds/renames tests around canMergeCompleteBundle, including the “logs deleted/empty” case.
CHANGELOG.md Adds an Unreleased note describing the bug fix (should be categorized under “Fixed”).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread CHANGELOG.md
chiaramapellimt and others added 3 commits June 3, 2026 14:21
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

Looks good. All 3 mutations in this change were killed.

class surviving killed
💯uk.nhs.adaptors.pss.translator.service.InboundMessageMergingService 0 3

See https://pitest.org

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