luigidemasi commented on code in PR #214:
URL: https://github.com/apache/camel-kit/pull/214#discussion_r4770575245
##########
knowledge/indexer/src/test/java/org/apache/camel/kit/knowledge/indexer/domain/GenericDocumentDomainTest.java:
##########
@@ -0,0 +1,224 @@
+package org.apache.camel.kit.knowledge.indexer.domain;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.camel.kit.knowledge.indexer.GitRepoFetcher;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.lib.PersonIdent;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * Regression tests for GenericDocumentDomain to prevent: - Tag/branch
checkout collisions - Duplicate citation IDs -
+ * Incorrect file type filtering
+ */
+@Timeout(30)
+class GenericDocumentDomainTest {
+
+ private static final PersonIdent IDENTITY = new PersonIdent("Test
fixture", "[email protected]");
+
+ @TempDir
+ Path tempDir;
+
+ private GitRepoFetcher fetcher;
+
+ @BeforeEach
+ void setup() throws Exception {
+ fetcher = new GitRepoFetcher(tempDir.resolve("cache"));
+ }
+
+ /**
+ * Regression test for file type filtering. *.md must match guide.md but
NOT build.cmd
+ */
+ @Test
+ void fileFilteringExcludesCommandFiles() throws Exception {
+ // Create test directory with mixed file types
+ Path testRepo = tempDir.resolve("test-repo");
+ Files.createDirectories(testRepo.resolve("docs/nested"));
+ Files.createDirectories(testRepo.resolve("ops"));
+ Files.createDirectories(testRepo.resolve("scripts"));
+
+ Files.writeString(testRepo.resolve("docs/guide.md"), "# Guide");
+ Files.writeString(testRepo.resolve("docs/nested/tutorial.md"), "#
Tutorial");
+ Files.writeString(testRepo.resolve("ops/build.cmd"), "@echo off");
+ Files.writeString(testRepo.resolve("scripts/deploy.cmd"), "deploy");
+ Files.writeString(testRepo.resolve("README.md"), "# README");
+
+ // Test listFilesRecursive - should match .md but not .cmd
+ List<Path> mdFiles = fetcher.listFilesRecursive(testRepo, "*.md");
+ assertEquals(3, mdFiles.size(), "Should find exactly 3 .md files");
+ assertTrue(mdFiles.stream().allMatch(p ->
p.toString().endsWith(".md")),
+ "All results should end with .md");
+ assertTrue(mdFiles.stream().noneMatch(p ->
p.toString().endsWith(".cmd")),
+ "No .cmd files should be matched");
+ }
+
+ /**
+ * Regression test for tag → branch → tag collision. Tests that production
directory naming with ref kind prevents
+ * collisions when tag and branch have the same name. Uses
GenericDocumentDomain.buildChunks() to exercise the
+ * production cache decision.
+ */
+ @Test
+ void tagAndBranchCheckoutsAreSeparate() throws Exception {
+ // Create upstream repository with tag and branch named "release"
containing different content
+ Path upstreamPath = tempDir.resolve("test-upstream-repo");
+ Git upstream = Git.init().setDirectory(upstreamPath.toFile())
+ .setInitialBranch("main").call();
+ try {
+ Path workTree = upstream.getRepository().getWorkTree().toPath();
+
+ // Create release branch with one content
+ Files.writeString(workTree.resolve("guide.md"), "# Branch\nBranch
content");
+ upstream.add().addFilepattern(".").call();
+
upstream.commit().setMessage("branch").setAuthor(IDENTITY).setCommitter(IDENTITY)
+ .setSign(false).setNoVerify(true).call();
+ upstream.branchCreate().setName("release").call();
+
+ // Switch back to main and create tag with different content
+ Files.writeString(workTree.resolve("guide.md"), "# Tag\nTag
content");
+ upstream.add().addFilepattern(".").call();
+
upstream.commit().setMessage("tag").setAuthor(IDENTITY).setCommitter(IDENTITY)
+ .setSign(false).setNoVerify(true).call();
+
upstream.tag().setName("release").setAnnotated(true).setMessage("release")
+ .setTagger(IDENTITY).setSigned(false).call();
+
+ // Set up test-local Git URL rewrite to redirect GitHub URL to
local fixture
+ String repoUrl = upstreamPath.toUri().toString();
+ String githubUrl =
"https://github.com/test-fixture-collision/test-repo";
+
+ // Configure git to rewrite the test URL to the local fixture
+ Process configSet = new ProcessBuilder(
+ "git", "config", "--global",
Review Comment:
**Keep the URL rewrite inside the fixture.** `git config --global` writes to
the account running Maven. With a readable Git config in a read-only directory,
this command exited 255 and the test failed before it exercised the checkout.
The `finally` block also depends on the test process surviving long enough to
remove the rewrite.
Please give JGit a config under `@TempDir`. I verified that a
`FileBasedConfig` supplied through a scoped `SystemReader.Delegate` worked with
the global config read-only and still failed on the third read when tag and
branch shared a checkout. Marking the JUnit class `@Isolated` and restoring the
previous reader in `finally` keeps the JVM-wide substitution scoped. This also
removes both native `git` subprocesses.
_AI-generated by Codex on behalf of @luigidemasi._
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]