Skip to content

Commit 05fe567

Browse files
andrusclaude
andcommitted
fix CgenRunMcpIT cross-platform failures on Windows
CRLF line endings from Jackson's DefaultPrettyPrinter and unescaped backslashes in Windows paths caused test assertions to mismatch. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 31d08f7 commit 05fe567

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

cayenne-mcp-server/src/test/java/org/apache/cayenne/mcp/tools/cgen/CgenRunMcpIT.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ public void projectNotFoundReturnsValidationError() throws Exception {
129129
public void generatesFilesOnFirstRun() throws Exception {
130130
send(callJson(4, projectFile, "PersonMap"));
131131

132-
String superPath = destDir.resolve("com/example/auto/_Person.java").toAbsolutePath().toString();
133-
String subPath = destDir.resolve("com/example/Person.java").toAbsolutePath().toString();
134-
String destPath = destDir.toAbsolutePath().toString();
132+
// JSON-escape backslashes so Windows paths round-trip correctly through Jackson serialization
133+
String superPath = destDir.resolve("com/example/auto/_Person.java").toAbsolutePath().toString().replace("\\", "\\\\");
134+
String subPath = destDir.resolve("com/example/Person.java").toAbsolutePath().toString().replace("\\", "\\\\");
135+
String destPath = destDir.toAbsolutePath().toString().replace("\\", "\\\\");
135136

136137
assertEquals("""
137138
{
@@ -171,7 +172,7 @@ public void upToDateOnSecondRun() throws Exception {
171172

172173
send(callJson(6, projectFile, "PersonMap"));
173174

174-
String destPath = destDir.toAbsolutePath().toString();
175+
String destPath = destDir.toAbsolutePath().toString().replace("\\", "\\\\");
175176

176177
assertEquals("""
177178
{
@@ -200,7 +201,10 @@ private String extractPayload(String mcpResponse) throws Exception {
200201
JsonNode root = MAPPER.readTree(mcpResponse);
201202
String text = root.at("/result/content/0/text").asText();
202203
JsonNode payload = MAPPER.readTree(text);
203-
return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(payload);
204+
// Normalize CRLF → LF: Jackson's DefaultPrettyPrinter uses System.lineSeparator()
205+
// which is \r\n on Windows, but Java text blocks always use \n.
206+
return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(payload)
207+
.replace("\r\n", "\n");
204208
}
205209

206210
private String callJson(int id, Path project, String dataMap) {

0 commit comments

Comments
 (0)