spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

ContentFormatterTests failed on Windows

Open alexcheng1982 opened this issue 4 months ago • 0 comments

Bug description ContentFormatterTests failed on Windows. This is a Windows specific issue.

org.opentest4j.AssertionFailedError: 
expected: 
  "llmKey2: value4
embedKey1: value1
embedKey2: value2
embedKey3: value3

The World is Big and Salvation Lurks Around the Corner"
 but was: 
  "llmKey2: value4
  embedKey1: value1
  embedKey2: value2
  embedKey3: value3

The World is Big and Salvation Lurks Around the Corner"

Environment Spring AI 0.8.1 Java 17 Windows

Steps to reproduce Just mvn test to run the tests

Expected behavior ContentFormatterTests should pass

Minimal Complete Reproducible example Just the main repo

I did some investigation and found out the issue was with the DEFAULT_METADATA_SEPARATOR. On Windows, the default metadata separator System.lineSeparator() is \r\n, not \n.

private static final String DEFAULT_METADATA_SEPARATOR = System.lineSeparator();

The test uses a text block as the expected result, which always uses \n. So on Windows the assertion failed, as the formatted content has an extra \r in it.

The customTextFormatter test can be fixed by overriding the default metadata separator using withMetadataSeparator("\n"). However, the defaultConfigTextFormatter test cannot be fixed in this way, as there is no way to configure the default DefaultContentFormatter.

Another option is to set the DEFAULT_METADATA_SEPARATOR to \n. Not sure about the impact of changing the default metadata separator.

alexcheng1982 avatar Apr 17 '24 06:04 alexcheng1982