Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Azure.Sdk.Tools.Cli.Models;
using Azure.Sdk.Tools.Cli.Models.Responses;

namespace Azure.Sdk.Tools.Mock.Handlers.APIView;

/// <summary>
/// Mock handler for azsdk_apiview_get_comments. Returns a small fixed comment payload so
/// callers can exercise the "consume APIView feedback" path deterministically.
/// </summary>
public class ApiViewGetCommentsHandler : IMockToolHandler
{
public string ToolName => "azsdk_apiview_get_comments";

public CommandResponse Handle(Dictionary<string, object?>? arguments) => new APIViewResponse
{
Message = "Retrieved APIView comments",
Language = arguments?.GetValueOrDefault("language")?.ToString() ?? ".NET",
PackageName = arguments?.GetValueOrDefault("packageName")?.ToString() ?? "Azure.Template.Contoso",
Result = new[]
{
new
{
id = "comment-1",
line = 42,
text = "Consider renaming this property for clarity.",
author = "reviewer@microsoft.com",
resolved = false
}
}
};
}

/// <summary>
/// Mock handler for azsdk_apiview_get_review_url. Returns a deterministic review URL for the
/// requested package + language.
/// </summary>
public class ApiViewGetReviewUrlHandler : IMockToolHandler
{
public string ToolName => "azsdk_apiview_get_review_url";

public CommandResponse Handle(Dictionary<string, object?>? arguments)
{
var language = arguments?.GetValueOrDefault("language")?.ToString() ?? "dotnet";
var package = arguments?.GetValueOrDefault("packageName")?.ToString() ?? "Azure.Template.Contoso";
return new APIViewResponse
{
Message = "APIView URL resolved",
Language = language,
PackageName = package,
Result = $"https://apiview.dev/Assemblies/Review/mock-{language}-{package}".ToLowerInvariant()
};
}
}

/// <summary>
/// Mock handler for azsdk_apiview_request_copilot_review. Returns a deterministic job ID
/// callers can poll with azsdk_apiview_get_copilot_review.
/// </summary>
public class ApiViewRequestCopilotReviewHandler : IMockToolHandler
{
public string ToolName => "azsdk_apiview_request_copilot_review";

public CommandResponse Handle(Dictionary<string, object?>? arguments) => new APIViewResponse
{
Message = "Copilot review submitted",
Language = arguments?.GetValueOrDefault("language")?.ToString() ?? ".NET",
PackageName = arguments?.GetValueOrDefault("packageName")?.ToString() ?? "Azure.Template.Contoso",
Result = "mock-copilot-job-00000001"
};
}

/// <summary>
/// Mock handler for azsdk_apiview_get_copilot_review. Returns a "completed" review with a
/// single sample comment.
/// </summary>
public class ApiViewGetCopilotReviewHandler : IMockToolHandler
{
public string ToolName => "azsdk_apiview_get_copilot_review";

public CommandResponse Handle(Dictionary<string, object?>? arguments) => new APIViewResponse
{
Message = "Copilot review complete",
Result = new
{
jobId = arguments?.GetValueOrDefault("jobId")?.ToString() ?? "mock-copilot-job-00000001",
status = "Completed",
comments = new[]
{
new { line = 24, severity = "info", text = "Mock Copilot suggestion: tighten the parameter type." }
}
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Azure.Sdk.Tools.Cli.Models;
using Azure.Sdk.Tools.Cli.Models.Responses;
using Azure.Sdk.Tools.Cli.Models.Responses.Codeowners;

namespace Azure.Sdk.Tools.Mock.Handlers.Config;

/// <summary>Mock handler for azsdk_check_service_label.</summary>
public class CheckServiceLabelHandler : IMockToolHandler
{
public string ToolName => "azsdk_check_service_label";
public CommandResponse Handle(Dictionary<string, object?>? arguments) => new ServiceLabelResponse
{
Label = arguments?.GetValueOrDefault("label")?.ToString() ?? "Contoso.WidgetManager",
Status = "Exists"
};
}

/// <summary>Mock handler for azsdk_create_service_label.</summary>
public class CreateServiceLabelHandler : IMockToolHandler
{
public string ToolName => "azsdk_create_service_label";
public CommandResponse Handle(Dictionary<string, object?>? arguments)
{
var label = arguments?.GetValueOrDefault("label")?.ToString() ?? "Contoso.WidgetManager";
return new ServiceLabelResponse
{
Label = label,
Status = "Created",
PullRequestUrl = $"https://github.com/Azure/azure-sdk-tools/pull/99001"
};
}
}

/// <summary>Mock handler for azsdk_engsys_codeowner_view.</summary>
public class CodeownerViewHandler : IMockToolHandler
{
public string ToolName => "azsdk_engsys_codeowner_view";
public CommandResponse Handle(Dictionary<string, object?>? arguments) => new CodeownersViewResponse
{
Packages =
[
new PackageResponse
{
WorkItemId = 70001,
PackageName = "Azure.Template.Contoso",
Language = ".NET",
PackageType = "client",
Owners =
[
new OwnerResponse { GitHubAlias = "contoso-owner-1" },
new OwnerResponse { GitHubAlias = "contoso-owner-2" }
],
Labels = ["Contoso.WidgetManager"]
}
]
};
}

/// <summary>Mock handler for azsdk_engsys_codeowner_check_package.</summary>
public class CodeownerCheckPackageHandler : IMockToolHandler
{
public string ToolName => "azsdk_engsys_codeowner_check_package";
public CommandResponse Handle(Dictionary<string, object?>? arguments) => new CheckPackageResponse
{
DirectoryPath = arguments?.GetValueOrDefault("directoryPath")?.ToString() ?? "sdk/contoso/Azure.Template.Contoso",
Owners = ["contoso-owner-1", "contoso-owner-2"],
PRLabels = ["Contoso.WidgetManager"],
ServiceOwners = ["service-team-lead"],
ServiceLabels = ["Service Attention", "Contoso.WidgetManager"]
};
}

internal static class CodeownersModifyMockResponses
{
public static CodeownersModifyResponse OkWithMessage() => new()
{
View = new CodeownersViewResponse
{
Packages =
[
new PackageResponse
{
WorkItemId = 70001,
PackageName = "Azure.Template.Contoso",
Language = ".NET",
PackageType = "client",
Owners = [new OwnerResponse { GitHubAlias = "contoso-owner-1" }],
Labels = ["Contoso.WidgetManager"]
}
]
}
};
}

/// <summary>Mock handler for azsdk_engsys_codeowner_add_package_owner.</summary>
public class CodeownerAddPackageOwnerHandler : IMockToolHandler
{
public string ToolName => "azsdk_engsys_codeowner_add_package_owner";
public CommandResponse Handle(Dictionary<string, object?>? arguments) => CodeownersModifyMockResponses.OkWithMessage();
}

/// <summary>Mock handler for azsdk_engsys_codeowner_add_package_label.</summary>
public class CodeownerAddPackageLabelHandler : IMockToolHandler
{
public string ToolName => "azsdk_engsys_codeowner_add_package_label";
public CommandResponse Handle(Dictionary<string, object?>? arguments) => CodeownersModifyMockResponses.OkWithMessage();
}

/// <summary>Mock handler for azsdk_engsys_codeowner_add_label_owner.</summary>
public class CodeownerAddLabelOwnerHandler : IMockToolHandler
{
public string ToolName => "azsdk_engsys_codeowner_add_label_owner";
public CommandResponse Handle(Dictionary<string, object?>? arguments) => CodeownersModifyMockResponses.OkWithMessage();
}

/// <summary>Mock handler for azsdk_engsys_codeowner_remove_package_owner.</summary>
public class CodeownerRemovePackageOwnerHandler : IMockToolHandler
{
public string ToolName => "azsdk_engsys_codeowner_remove_package_owner";
public CommandResponse Handle(Dictionary<string, object?>? arguments) => CodeownersModifyMockResponses.OkWithMessage();
}

/// <summary>Mock handler for azsdk_engsys_codeowner_remove_package_label.</summary>
public class CodeownerRemovePackageLabelHandler : IMockToolHandler
{
public string ToolName => "azsdk_engsys_codeowner_remove_package_label";
public CommandResponse Handle(Dictionary<string, object?>? arguments) => CodeownersModifyMockResponses.OkWithMessage();
}

/// <summary>Mock handler for azsdk_engsys_codeowner_remove_label_owner.</summary>
public class CodeownerRemoveLabelOwnerHandler : IMockToolHandler
{
public string ToolName => "azsdk_engsys_codeowner_remove_label_owner";
public CommandResponse Handle(Dictionary<string, object?>? arguments) => CodeownersModifyMockResponses.OkWithMessage();
}

/// <summary>Mock handler for azsdk_engsys_codeowner_update_cache.</summary>
public class CodeownerUpdateCacheHandler : IMockToolHandler
{
public string ToolName => "azsdk_engsys_codeowner_update_cache";
public CommandResponse Handle(Dictionary<string, object?>? arguments) => new DefaultCommandResponse
{
Message = "CODEOWNERS cache refreshed (mock)",
Result = new { packagesRefreshed = 1, labelOwnersRefreshed = 1 }
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Azure.Sdk.Tools.Cli.Models;

namespace Azure.Sdk.Tools.Mock.Handlers.Core;

/// <summary>
/// Mock handler for azsdk_upgrade. Always reports the current "mock" version is up to date so
/// callers exercising the upgrade flow don't trigger a real download.
/// </summary>
public class UpgradeHandler : IMockToolHandler
{
public string ToolName => "azsdk_upgrade";

public CommandResponse Handle(Dictionary<string, object?>? arguments) => new UpgradeResponse
{
OldVersion = "0.0.0-mock",
NewVersion = "0.0.0-mock",
Message = "azsdk is already up to date (mock).",
RestartRequired = false
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Azure.Sdk.Tools.Cli.Models;
using Azure.Sdk.Tools.Cli.Models.Responses;

namespace Azure.Sdk.Tools.Mock.Handlers.EngSys;

/// <summary>Mock handler for azsdk_analyze_log_file. Returns a single fake build error.</summary>
public class AnalyzeLogFileHandler : IMockToolHandler
{
public string ToolName => "azsdk_analyze_log_file";
public CommandResponse Handle(Dictionary<string, object?>? arguments) => new LogAnalysisResponse
{
Summary = "Detected one CS0246 compile error in the build log.",
SuggestedFix = "Add a `using Azure.Core;` directive at the top of the file.",
Errors =
[
new LogEntry
{
File = "src/Contoso.Widgets/Generated/WidgetsClient.cs",
Line = 42,
Message = "error CS0246: The type or namespace name 'WidgetOptions' could not be found"
}
]
};
}

/// <summary>Mock handler for azsdk_get_failed_test_cases.</summary>
public class GetFailedTestCasesHandler : IMockToolHandler
{
public string ToolName => "azsdk_get_failed_test_cases";
public CommandResponse Handle(Dictionary<string, object?>? arguments) => new FailedTestRunListResponse
{
Items =
[
new FailedTestRunResponse
{
RunId = 100001,
TestCaseTitle = "Contoso.Widgets.Tests.WidgetClientLiveTests.GetWidget",
Outcome = "Failed",
ErrorMessage = "Expected status 200, got 404.",
StackTrace = "at Contoso.Widgets.Tests.WidgetClientLiveTests.GetWidget()"
}
]
};
}

/// <summary>Mock handler for azsdk_get_failed_test_case_data.</summary>
public class GetFailedTestCaseDataHandler : IMockToolHandler
{
public string ToolName => "azsdk_get_failed_test_case_data";
public CommandResponse Handle(Dictionary<string, object?>? arguments) => new FailedTestRunResponse
{
RunId = 100001,
TestCaseTitle = arguments?.GetValueOrDefault("testCaseTitle")?.ToString()
?? "Contoso.Widgets.Tests.WidgetClientLiveTests.GetWidget",
Outcome = "Failed",
ErrorMessage = "Expected status 200, got 404.",
StackTrace = "at Contoso.Widgets.Tests.WidgetClientLiveTests.GetWidget()",
Uri = "https://dev.azure.com/azure-sdk/internal/_test/cases?id=100001"
};
}

/// <summary>Mock handler for azsdk_get_failed_test_run_data.</summary>
public class GetFailedTestRunDataHandler : IMockToolHandler
{
public string ToolName => "azsdk_get_failed_test_run_data";
public CommandResponse Handle(Dictionary<string, object?>? arguments) => new FailedTestRunListResponse
{
Items =
[
new FailedTestRunResponse
{
RunId = int.TryParse(arguments?.GetValueOrDefault("runId")?.ToString(), out var id) ? id : 100001,
TestCaseTitle = "Contoso.Widgets.Tests.WidgetClientLiveTests.GetWidget",
Outcome = "Failed",
ErrorMessage = "Expected status 200, got 404.",
StackTrace = "at Contoso.Widgets.Tests.WidgetClientLiveTests.GetWidget()"
}
]
};
}

/// <summary>Mock handler for azsdk_cleanup_ai_agents.</summary>
public class CleanupAiAgentsHandler : IMockToolHandler
{
public string ToolName => "azsdk_cleanup_ai_agents";
public CommandResponse Handle(Dictionary<string, object?>? arguments) => new DefaultCommandResponse
{
Message = "AI agents cleaned up (mock)",
Result = new { agentsDeleted = 3, threadsDeleted = 5 }
};
}
Loading