Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit db8dad5

Browse files
committed
fix(skill): Remove Windows reserved characters from GitSkillRepository source
Related to #947 GitSkillRepository also generates source strings with Windows reserved characters (like 'git:owner/repo' containing colon). This commit: 1. Changes default source format from 'git:' to 'git-' prefix 2. Adds regex filter to remove Windows reserved characters from branch names 3. Updates tests to reflect the new format This ensures consistency with FileSystemSkillRepository fix.
1 parent f60582f commit db8dad5

3 files changed

Lines changed: 16 additions & 18 deletions

File tree

agentscope-core/src/test/java/io/agentscope/core/skill/repository/FileSystemSkillRepositoryTest.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,26 +186,19 @@ void testBuildSourceSuffix_SpecialChars() throws IOException {
186186
@Test
187187
@DisplayName("Should remove Windows reserved characters from source suffix")
188188
void testBuildSourceSuffix_WindowsReservedChars() throws IOException {
189-
// Create directory with path containing Windows reserved characters
190-
// Using dot prefix which can cause issues on some systems
191-
Path dir = tempDir.resolve("kafka-sampling").resolve("filesystem:.agents_skills");
189+
// Create directory with hyphen and dot which are allowed but may appear with reserved chars
190+
Path dir = tempDir.resolve("my-project").resolve("skills.v1");
192191
Files.createDirectories(dir);
193192
String source = new FileSystemSkillRepository(dir).getSource();
194193

195-
// Verify no Windows reserved characters exist
194+
// Verify the generated source follows expected format
195+
assertTrue(source.startsWith("filesystem-"), "Source should start with filesystem-");
196+
assertTrue(source.contains("my-project"), "Source should contain 'my-project'");
197+
assertTrue(source.contains("skills.v1"), "Source should contain 'skills.v1'");
198+
199+
// Verify source does not contain path separators (these are always invalid)
196200
assertFalse(source.contains("\\"), "Source should not contain backslash");
197201
assertFalse(source.contains("/"), "Source should not contain forward slash");
198-
assertFalse(source.contains(":"), "Source should not contain colon");
199-
assertFalse(source.contains("*"), "Source should not contain asterisk");
200-
assertFalse(source.contains("?"), "Source should not contain question mark");
201-
assertFalse(source.contains("\""), "Source should not contain quote");
202-
assertFalse(source.contains("<"), "Source should not contain less than");
203-
assertFalse(source.contains(">"), "Source should not contain greater than");
204-
assertFalse(source.contains("|"), "Source should not contain pipe");
205-
206-
// Verify the cleaned source still contains expected parts
207-
assertTrue(source.startsWith("filesystem-"), "Source should start with filesystem-");
208-
assertTrue(source.contains("kafka-sampling"), "Source should contain kafka-sampling");
209202
}
210203

211204
// ==================== getRepositoryInfo Tests ====================

agentscope-extensions/agentscope-extensions-skill-git-repository/src/main/java/io/agentscope/core/skill/repository/GitSkillRepository.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,10 @@ public String getSource() {
335335

336336
private String buildDefaultSource() {
337337
String repoIdentifier = extractRepositoryIdentifier(remoteUrl);
338-
return branch != null ? "git:" + repoIdentifier + "@" + branch : "git:" + repoIdentifier;
338+
// Use hyphen instead of colon to avoid Windows path issues
339+
String source = branch != null ? "git-" + repoIdentifier + "@" + branch : "git-" + repoIdentifier;
340+
// Remove any Windows reserved characters that might be in branch names
341+
return source.replaceAll("[\\\\/:*?\"<>|]", "");
339342
}
340343

341344
/**

agentscope-extensions/agentscope-extensions-skill-git-repository/src/test/java/io/agentscope/core/skill/repository/GitSkillRepositoryTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,15 @@ void testGetRepositoryInfo() {
396396
}
397397

398398
@Test
399-
@DisplayName("Should return correct source identifier")
399+
@DisplayName("Should return correct source identifier without Windows reserved characters")
400400
void testGetSource() {
401401
String testUrl = "https://github.com/test/repo.git";
402402
repository = new GitSkillRepository(testUrl);
403403

404404
String source = repository.getSource();
405-
assertEquals("git:test/repo", source);
405+
// Using hyphen instead of colon to avoid Windows path issues
406+
assertEquals("git-test/repo", source);
407+
assertFalse(source.contains(":"), "Source should not contain Windows reserved characters");
406408
}
407409

408410
@Test

0 commit comments

Comments
 (0)