Skip to content

Commit 058a71c

Browse files
organize_imports test: pin import range by content, not CRLF offsets
returnsImportRangeWithLineNumbers pinned raw byte offsets (24/154) that are Windows-CRLF values; on a Linux (LF) checkout the same range is 22/152, so the release build failed on CI. Keep the exact 0-based start/end lines (2/6) and bracket the offsets by the exact five-import block content (CRLF-normalized), which is determinate and portable across line-ending normalization.
1 parent 78dc5e6 commit 058a71c

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

org.javalens.mcp.tests/src/org/javalens/mcp/tools/refactoring/OrganizeImportsToolTest.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void organizeImports_returnsCompleteResponse() {
8484

8585
@Test
8686
@DisplayName("returns import range with line numbers when imports exist")
87-
void returnsImportRangeWithLineNumbers() {
87+
void returnsImportRangeWithLineNumbers() throws Exception {
8888
ObjectNode args = objectMapper.createObjectNode();
8989
args.put("filePath", refactoringTargetPath);
9090

@@ -96,11 +96,24 @@ void returnsImportRangeWithLineNumbers() {
9696
@SuppressWarnings("unchecked")
9797
Map<String, Object> range = (Map<String, Object>) data.get("importRange");
9898
assertNotNull(range, "importRange must be present when imports exist");
99-
// RefactoringTarget's 5 imports span 0-based lines 2-6 (offsets 24..154).
99+
// RefactoringTarget's 5 imports span 0-based lines 2-6.
100100
assertEquals(2, ((Number) range.get("startLine")).intValue());
101101
assertEquals(6, ((Number) range.get("endLine")).intValue());
102-
assertEquals(24, ((Number) range.get("startOffset")).intValue());
103-
assertEquals(154, ((Number) range.get("endOffset")).intValue());
102+
// Raw byte offsets are checkout-line-ending dependent (CRLF vs LF), so pin them by
103+
// the content they bracket rather than absolute values: the range must cover exactly
104+
// RefactoringTarget's five-import block.
105+
int startOffset = ((Number) range.get("startOffset")).intValue();
106+
int endOffset = ((Number) range.get("endOffset")).intValue();
107+
assertTrue(endOffset > startOffset, "import range must be non-empty; got [" + startOffset + "," + endOffset + ")");
108+
String source = java.nio.file.Files.readString(java.nio.file.Path.of(refactoringTargetPath));
109+
assertEquals(
110+
"import java.util.List;\n"
111+
+ "import java.util.ArrayList;\n"
112+
+ "import java.util.Map;\n"
113+
+ "import java.util.HashMap;\n"
114+
+ "import java.io.IOException;",
115+
source.substring(startOffset, endOffset).replace("\r\n", "\n"),
116+
"importRange must bracket exactly the five-import block");
104117
}
105118

106119
@Test

0 commit comments

Comments
 (0)