build: validate duplicate MCP tool names before packaging
All checks were successful
Deploy to OCIWP / deploy (push) Successful in 2m1s

This commit is contained in:
jade
2026-07-30 17:41:06 +09:00
parent 60055dd9ed
commit 1bf09705d1
3 changed files with 47 additions and 0 deletions

View File

@@ -49,3 +49,20 @@ subprojects {
useJUnitPlatform() useJUnitPlatform()
} }
} }
def toolCoreProject = project(':dap-tool-core')
tasks.register('validateMcpToolNames', JavaExec) {
group = 'verification'
description = 'Checks duplicate @McpFunction names across all Tool modules before packaging.'
dependsOn toolCoreProject.tasks.named('classes')
classpath = toolCoreProject.sourceSets.main.runtimeClasspath
mainClass.set('io.shinhanlife.dap.lib.validation.McpToolNameValidationRunner')
args rootProject.projectDir.absolutePath
}
subprojects {
tasks.matching { it.name == 'bootJar' }.configureEach {
dependsOn rootProject.tasks.named('validateMcpToolNames')
}
}

View File

@@ -0,0 +1,21 @@
package io.shinhanlife.dap.lib.validation;
import java.nio.file.Path;
/** Gradle entry point for validating unique MCP Tool names before packaging. */
public final class McpToolNameValidationRunner {
private McpToolNameValidationRunner() {
}
public static void main(String[] args) {
if (args.length != 1) {
throw new IllegalArgumentException("Usage: McpToolNameValidationRunner <project-root>");
}
validate(Path.of(args[0]));
}
static void validate(Path projectRoot) {
McpToolNameValidator.assertUnique(projectRoot);
}
}

View File

@@ -42,6 +42,15 @@ class McpToolNameValidatorTest {
assertTrue(exception.getMessage().contains("dap-tool-second")); assertTrue(exception.getMessage().contains("dap-tool-second"));
} }
@Test
void validationRunnerRejectsDuplicateMcpFunctionNamesBeforePackaging() throws IOException {
writeToolSource("dap-tool-first", "FirstTool.java", "first", "send_sms");
writeToolSource("dap-tool-second", "SecondTool.java", "second", "send_sms");
assertThrows(IllegalStateException.class,
() -> McpToolNameValidationRunner.validate(temporaryRoot));
}
@Test @Test
void acceptsCurrentProjectToolNames() { void acceptsCurrentProjectToolNames() {
assertDoesNotThrow(() -> McpToolNameValidator.assertUnique(findProjectRoot())); assertDoesNotThrow(() -> McpToolNameValidator.assertUnique(findProjectRoot()));