Skip to content
Open
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 @@ -89,7 +89,7 @@ public override async Task<CommandResponse> ExecuteAsync(CommandContext context,
if (subgroup is not null)
{
List<CommandInfo> foundCommands = [];
searchCommandInCommandGroup("", subgroup, foundCommands);
SearchCommandInCommandGroup("", subgroup, foundCommands);
namespaceCommands.AddRange(foundCommands);
}
}
Expand Down Expand Up @@ -188,14 +188,15 @@ private static CommandInfo CreateCommand(string tokenizedName, IBaseCommand comm
}

public record ToolNamesResult(List<string> Names);
private void searchCommandInCommandGroup(string commandPrefix, CommandGroup searchedGroup, List<CommandInfo> foundCommands)

private void SearchCommandInCommandGroup(string commandPrefix, CommandGroup searchedGroup, List<CommandInfo> foundCommands)
{
var commands = CommandFactory.GetVisibleCommands(searchedGroup.Commands).Select(kvp =>
{
var command = kvp.Value.GetCommand();
return new CommandInfo
{
Name = $"{commandPrefix.Replace(" ", "_")}{searchedGroup.Name}_{command.Name}",
Name = $"{commandPrefix.Replace(' ', CommandFactory.Separator)}{searchedGroup.Name}{CommandFactory.Separator}{command.Name}",
Description = command.Description ?? string.Empty,
Command = $"{(!string.IsNullOrEmpty(commandPrefix) ? commandPrefix : "")}{searchedGroup.Name} {command.Name}"
// Omit Options and Subcommands for surfaced commands as well.
Expand All @@ -204,7 +205,7 @@ private void searchCommandInCommandGroup(string commandPrefix, CommandGroup sear
foundCommands.AddRange(commands);
foreach (CommandGroup nextLevelSubGroup in searchedGroup.SubGroup)
{
searchCommandInCommandGroup($"{commandPrefix}{searchedGroup.Name} ", nextLevelSubGroup, foundCommands);
SearchCommandInCommandGroup($"{commandPrefix}{searchedGroup.Name} ", nextLevelSubGroup, foundCommands);
}
}
}
9 changes: 9 additions & 0 deletions eng/scripts/Analyze-Code.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ try {
Write-Host "✅ Tool description evaluation did not detect any issues."
}

# Run tool prompt validation
& "$PSScriptRoot/Test-ToolSelectionPrompts.ps1"

Comment on lines +64 to +66
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ E2E tool prompt validation failed."
} else {
Write-Host "✅ E2E tool prompt validation did not detect any issues."
}
Comment on lines +67 to +71

# Run tool name length validation
$toolNameResult = & "$PSScriptRoot/Test-ToolNameLength.ps1"

Expand Down
1 change: 0 additions & 1 deletion eng/scripts/Test-ToolId.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ $ErrorActionPreference = 'Stop'
$RepoRoot = $RepoRoot.Path.Replace('\', '/')

$ToolsDirectory = Join-Path $RepoRoot "tools"
$ServersDirectory = Join-Path $RepoRoot "servers"

$CommandFiles = Get-ChildItem -Path $ToolsDirectory -Recurse -Filter *Command.cs

Expand Down
43 changes: 30 additions & 13 deletions eng/scripts/Test-ToolNameLength.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,19 @@ foreach ($serverInfo in $serversToTest) {
# Try to get tools - some servers may not support 'tools list'
Write-Host "Loading tools from $currentServerName"
try {
$toolsJson = & $executablePath tools list 2>&1 | Out-String

# Example response from 'tools list --name-only' command:
# {
# "status": 200,
# "message": "Success",
# "results": {
# "names": [
# "acr_registry_list",
# "acr_registry_repository_list",
# ]
# }
# }
$toolsJson = & $executablePath tools list --name-only 2>&1 | Out-String

if ($LASTEXITCODE -ne 0) {
Write-Warning "$currentServerName 'tools list' command failed with exit code $LASTEXITCODE (may have no tools) - skipping"
Expand All @@ -123,7 +135,7 @@ foreach ($serverInfo in $serversToTest) {
}

if ([string]::IsNullOrWhiteSpace($toolsJson)) {
Write-Warning "No output received from '$currentServerName tools list' - skipping"
Write-Warning "No output received from '$currentServerName tools list --name-only' - skipping"
$skippedServers++
Write-Host ""
continue
Expand All @@ -132,23 +144,29 @@ foreach ($serverInfo in $serversToTest) {
$toolsResult = $toolsJson | ConvertFrom-Json
$tools = $toolsResult.results

if ($null -eq $tools -or $tools.Count -eq 0) {
Write-Warning "No tools found in $currentServerName - skipping"
if ($null -eq $tools) {
Write-Warning "Server [$currentServerName] 'tools list' command did not return any tools - skipping"
$skippedServers++
continue
} elseif ($null -eq $tools.names) {
Write-Warning "Server [$currentServerName] No 'names' property found in response - skipping. Response: `n$toolsJson`n"
$skippedServers++
continue
} elseif ($tools.names.Count -eq 0) {
Write-Warning "Server [$currentServerName] No tool names found - skipping"
$skippedServers++
Write-Host ""
continue
}

Write-Host "Loaded $($tools.Count) tools"
Write-Host "Loaded $($tools.names.Count) tools"
$testedServers++

# Validate tool name lengths
$violations = @()
$maxToolNameLength = 0

foreach ($tool in $tools) {
$toolName = $tool.command -replace ' ', '_'
$fullLength = $toolName.Length
foreach ($tool in $tools.names) {
$fullLength = $tool.Length

if ($fullLength -gt $maxToolNameLength) {
$maxToolNameLength = $fullLength
Expand All @@ -157,8 +175,8 @@ foreach ($serverInfo in $serversToTest) {
if ($fullLength -gt $MaxLength) {
$violations += [PSCustomObject]@{
Server = $currentServerName
ToolName = $toolName
Command = $tool.command
ToolName = $tool
Command = ""
Length = $fullLength
Excess = $fullLength - $MaxLength
}
Expand All @@ -168,7 +186,7 @@ foreach ($serverInfo in $serversToTest) {
Write-Host "Longest tool name: $maxToolNameLength characters"

if ($violations.Count -eq 0) {
Write-Host "All $($tools.Count) tool names are within the $MaxLength character limit!" -ForegroundColor Green
Write-Host "All $($tools.names.Count) tool names are within the $MaxLength character limit!" -ForegroundColor Green
}
else {
Write-Host "Found $($violations.Count) violation(s):" -ForegroundColor Red
Expand Down Expand Up @@ -204,7 +222,6 @@ if ($overallViolations.Count -gt 0) {
$overallViolations | Sort-Object -Property Length -Descending | ForEach-Object {
Write-Host " Server: $($_.Server)"
Write-Host " Tool: $($_.ToolName)"
Write-Host " Command: $($_.Command)"
Write-Host " Length: $($_.Length) characters (exceeds by $($_.Excess))"
Write-Host ""
}
Expand Down
Loading
Loading