Skip to content

keep applicability when move composites#1006

Open
souissimai wants to merge 6 commits into
mainfrom
composite-modifications-applicability
Open

keep applicability when move composites#1006
souissimai wants to merge 6 commits into
mainfrom
composite-modifications-applicability

Conversation

@souissimai

Copy link
Copy Markdown
Contributor

PR Summary

SOUISSI Maissa (Externe) and others added 2 commits June 9, 2026 14:25
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: df212964-67a5-4c5b-8826-839add8e7e11

📥 Commits

Reviewing files that changed from the base of the PR and between 441c0ce and 333c618.

📒 Files selected for processing (1)
  • src/test/java/org/gridsuite/study/server/SupervisionControllerTest.java

📝 Walkthrough

Walkthrough

moveNetworkModifications now expands moved modification UUIDs to leaf-level UUIDs before updating node exclusion mappings. Tests add WireMock stubs/verifications for the children-UUIDs endpoint and mock expandToLeafUuids; test setup now removes root network trees before deleting studies.

Changes

Leaf UUID Expansion for Moved Modifications

Layer / File(s) Summary
Leaf UUID expansion in moveNetworkModifications
src/main/java/org/gridsuite/study/server/service/StudyService.java, src/test/java/org/gridsuite/study/server/rootnetworks/ModificationToExcludeTest.java
moveNetworkModifications calls expandToLeafUuids() on moved modification UUIDs before passing them to moveModificationsToExclude(). Unit test stubs expandToLeafUuids() to return the moved UUIDs as a HashSet, ensuring exclusion updates use the expanded set.
Integration test coverage for children-UUIDs endpoint
src/test/java/org/gridsuite/study/server/NetworkModificationTest.java
Tests add WireMock stubs for GET /v1/network-composite-modifications/children-uuids and verify it is invoked with uuids containing the moved composite UUID in both reorder and cut-and-paste flows, returning expected child UUID lists.
Test setup cleanup for supervision controller
src/test/java/org/gridsuite/study/server/SupervisionControllerTest.java
setup() now iterates existing studies and calls networkModificationTreeService.doDeleteTree for each study ID before calling studyRepository.deleteAll().

Suggested reviewers

  • Mathieu-Deharbe
  • SlimaneAmar
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The pull request description is empty, providing no information about the changeset beyond what the title conveys. Provide a meaningful description explaining the motivation, impact, and technical details of the changes made in this pull request.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'keep applicability when move composites' is directly related to the main change: updating modification exclusion logic to use expanded leaf UUIDs when moving composite modifications, thereby preserving applicability.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@souissimai souissimai requested a review from Meklo June 11, 2026 12:20

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/test/java/org/gridsuite/study/server/rootnetworks/ModificationToExcludeTest.java (1)

805-808: ⚡ Quick win

Make the test prove expansion is actually part of the behavior, not just stubbed.

Right now the stub returns the same set as input, so this path still passes without validating that expansion materially impacts exclusion remapping. Add an interaction assertion (verify(expandToLeafUuids(...))) and preferably return a superset (includes a leaf UUID) to make the assertion behavior-sensitive.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/test/java/org/gridsuite/study/server/rootnetworks/ModificationToExcludeTest.java`
around lines 805 - 808, The test currently stubs
networkModificationService.expandToLeafUuids(modificationsToMove) to return the
same set so expansion isn't exercised; change the stub to return a superset that
includes an additional leaf UUID (e.g., create a new
HashSet<>(modificationsToMove) and add a specific leafUuid) and update expected
remapped exclusions to account for that leaf so the behavior is sensitive to
expansion, then add a
Mockito.verify(networkModificationService).expandToLeafUuids(modificationsToMove)
interaction assertion to ensure the method was actually invoked during the test;
keep references to expandToLeafUuids, networkModificationService,
modificationsToMove, and the new leaf UUID in your changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/java/org/gridsuite/study/server/service/StudyService.java`:
- Around line 2271-2272: The code calls
rootNetworkNodeInfoService.moveModificationsToExclude immediately after
performing the remote move but dereferences the expansion result without
checking for failure, which can skip local exclusion remapping if
expandToLeafUuids fails; first call
networkModificationService.expandToLeafUuids(networkModificationsResult.modificationUuids())
and validate its result (handle null or exceptions) before—or as part of—a
single transactional flow so the remote move and local remapping stay
consistent; if expansion fails, fall back to an empty list or retry/log and
still attempt to update local exclusion mappings (or roll back the remote move),
and ensure expandToLeafUuids and moveModificationsToExclude calls are wrapped
with try/catch that logs errors and preserves consistency between remote
modifications and local exclusion state using the originNodeUuid and
targetNodeUuid identifiers.

In `@src/test/java/org/gridsuite/study/server/NetworkModificationTest.java`:
- Around line 2432-2438: The WireMock stub in NetworkModificationTest currently
only verifies that the "uuids" query param contains modification1, which is
insufficient for MOVE payloads that include both modification1 and
modification2; update the withQueryParam matcher on the stubFor call (the
WireMock.get(...).withQueryParam("uuids", ...)) to assert that both
modification1.toString() and modification2.toString() are present (for example
by using a matching/regex or a combined containing matcher that checks for both
UUID substrings) so the test fails if either UUID is omitted.

---

Nitpick comments:
In
`@src/test/java/org/gridsuite/study/server/rootnetworks/ModificationToExcludeTest.java`:
- Around line 805-808: The test currently stubs
networkModificationService.expandToLeafUuids(modificationsToMove) to return the
same set so expansion isn't exercised; change the stub to return a superset that
includes an additional leaf UUID (e.g., create a new
HashSet<>(modificationsToMove) and add a specific leafUuid) and update expected
remapped exclusions to account for that leaf so the behavior is sensitive to
expansion, then add a
Mockito.verify(networkModificationService).expandToLeafUuids(modificationsToMove)
interaction assertion to ensure the method was actually invoked during the test;
keep references to expandToLeafUuids, networkModificationService,
modificationsToMove, and the new leaf UUID in your changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 57db6a4d-69ee-43b0-ad36-5e3c0b2bfc8f

📥 Commits

Reviewing files that changed from the base of the PR and between 4c32ece and 441c0ce.

📒 Files selected for processing (3)
  • src/main/java/org/gridsuite/study/server/service/StudyService.java
  • src/test/java/org/gridsuite/study/server/NetworkModificationTest.java
  • src/test/java/org/gridsuite/study/server/rootnetworks/ModificationToExcludeTest.java

Comment on lines +2271 to +2272
Set<UUID> allMovedUuids = networkModificationService.expandToLeafUuids(networkModificationsResult.modificationUuids());
rootNetworkNodeInfoService.moveModificationsToExclude(originNodeUuid, targetNodeUuid, new ArrayList<>(allMovedUuids));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Prevent post-move failure from desynchronizing remote modifications and local exclusion mappings.

Line 2270 executes the remote move first; then Line 2271 performs another remote call and Line 2272 dereferences it directly. If expansion fails (or returns null), this throws after the move already happened remotely, so local exclusion remapping is skipped.

Suggested hardening
             NetworkModificationsResult networkModificationsResult = networkModificationService.moveModifications(originGroupUuid, targetGroupUuid, beforeUuid, Pair.of(modificationUuidList, modificationApplicationContexts), isTargetInDifferentNodeTree);
-            Set<UUID> allMovedUuids = networkModificationService.expandToLeafUuids(networkModificationsResult.modificationUuids());
-            rootNetworkNodeInfoService.moveModificationsToExclude(originNodeUuid, targetNodeUuid, new ArrayList<>(allMovedUuids));
+            List<UUID> movedUuids = networkModificationsResult.modificationUuids();
+            Set<UUID> allMovedUuids;
+            try {
+                allMovedUuids = Optional.ofNullable(networkModificationService.expandToLeafUuids(movedUuids))
+                    .orElseGet(() -> new HashSet<>(movedUuids));
+            } catch (Exception e) {
+                LOGGER.warn("Leaf expansion failed after move; falling back to moved UUIDs", e);
+                allMovedUuids = new HashSet<>(movedUuids);
+            }
+            rootNetworkNodeInfoService.moveModificationsToExclude(originNodeUuid, targetNodeUuid, new ArrayList<>(allMovedUuids));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/java/org/gridsuite/study/server/service/StudyService.java` around
lines 2271 - 2272, The code calls
rootNetworkNodeInfoService.moveModificationsToExclude immediately after
performing the remote move but dereferences the expansion result without
checking for failure, which can skip local exclusion remapping if
expandToLeafUuids fails; first call
networkModificationService.expandToLeafUuids(networkModificationsResult.modificationUuids())
and validate its result (handle null or exceptions) before—or as part of—a
single transactional flow so the remote move and local remapping stay
consistent; if expansion fails, fall back to an empty list or retry/log and
still attempt to update local exclusion mappings (or roll back the remote move),
and ensure expandToLeafUuids and moveModificationsToExclude calls are wrapped
with try/catch that logs errors and preserves consistency between remote
modifications and local exclusion state using the originNodeUuid and
targetNodeUuid identifiers.

Comment on lines +2432 to +2438
UUID childrenStubId = wireMockServer.stubFor(
WireMock.get(WireMock.urlPathEqualTo("/v1/network-composite-modifications/children-uuids"))
.withQueryParam("uuids", WireMock.containing(modification1.toString()))
.willReturn(WireMock.ok()
.withBody(mapper.writeValueAsString(List.of(modification1, modification2)))
.withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))
).getId();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Strengthen children-UUIDs assertions for multi-UUID MOVE payloads.

At Line 2434 and Line 2493, the matcher only checks modification1. In this test, MOVE sends [modification1, modification2] (Line 2430), so the current checks can still pass if modification2 is accidentally omitted from the request.

Suggested tightening
-        UUID childrenStubId = wireMockServer.stubFor(
+        UUID childrenStubId = wireMockServer.stubFor(
                 WireMock.get(WireMock.urlPathEqualTo("/v1/network-composite-modifications/children-uuids"))
                         .withQueryParam("uuids", WireMock.containing(modification1.toString()))
+                        .withQueryParam("uuids", WireMock.containing(modification2.toString()))
                         .willReturn(WireMock.ok()
                                 .withBody(mapper.writeValueAsString(List.of(modification1, modification2)))
                                 .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE))
         ).getId();
@@
         WireMockUtils.verifyGetRequest(wireMockServer, childrenStubId,
                 "/v1/network-composite-modifications/children-uuids",
                 Map.of("uuids", WireMock.containing(modification1.toString())),
                 2);
+        WireMockUtils.verifyGetRequest(wireMockServer, childrenStubId,
+                "/v1/network-composite-modifications/children-uuids",
+                Map.of("uuids", WireMock.containing(modification2.toString())),
+                2);

Also applies to: 2491-2494

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/test/java/org/gridsuite/study/server/NetworkModificationTest.java` around
lines 2432 - 2438, The WireMock stub in NetworkModificationTest currently only
verifies that the "uuids" query param contains modification1, which is
insufficient for MOVE payloads that include both modification1 and
modification2; update the withQueryParam matcher on the stubFor call (the
WireMock.get(...).withQueryParam("uuids", ...)) to assert that both
modification1.toString() and modification2.toString() are present (for example
by using a matching/regex or a combined containing matcher that checks for both
UUID substrings) so the test fails if either UUID is omitted.

@Meklo Meklo force-pushed the composite-modifications-applicability branch from 333c618 to 441c0ce Compare June 12, 2026 10:20
@sonarqubecloud

Copy link
Copy Markdown

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