Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -32,7 +33,11 @@ public void buildPromptRendersFileNameAndSource() {
@Test
public void buildPromptUsesFullPathWhenFileNameNull() {
AiPromptSupport support = new AiPromptSupport(Collections.singletonList(def("summary", "[%s] %s")));
assertThat(support.buildPrompt("summary", Paths.get("/"), "x"), is("[/] x"));
// A root path has a null getFileName() on every OS, so buildPrompt falls back to the full
// path string. Derive the expected separator from the same Path so the assertion holds on
// Windows too (the root renders with the platform separator: "/" on POSIX, "\" on Windows).
Path root = Paths.get("/");
assertThat(support.buildPrompt("summary", root, "x"), is("[" + root + "] x"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.hamcrest.MatcherAssert.assertThat;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import net.ladenthin.maven.llamacpp.aiindex.document.AiGenerationRequest;
import net.ladenthin.maven.llamacpp.aiindex.document.AiMdHeader;
Expand All @@ -30,9 +31,12 @@ public void generateUsesFileNameOnly() throws IOException {

@Test
public void generateFallsBackToFullPathWhenFileNameNull() throws IOException {
// A root path has a null getFileName(); the provider must use file.toString().
AiGenerationRequest request = new AiGenerationRequest("summary", Paths.get("/"), "src", HEADER);
assertThat(provider.generate(request), is("Mock summary for /"));
// A root path has a null getFileName(); the provider must use file.toString(). Derive the
// expected separator from the same Path so the assertion holds on Windows too (the root
// renders with the platform separator: "/" on POSIX, "\" on Windows).
Path root = Paths.get("/");
AiGenerationRequest request = new AiGenerationRequest("summary", root, "src", HEADER);
assertThat(provider.generate(request), is("Mock summary for " + root));
}

@Test
Expand Down
Loading