Skip to content
Draft
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 @@ -8,7 +8,6 @@
using Azure.Mcp.Core.Options;
using Azure.Mcp.Core.Services.Azure;
using Azure.Mcp.Core.Services.Azure.Tenant;
using Azure.Mcp.Core.Services.Http;
using Azure.Mcp.Tools.Speech.Models.FastTranscription;
using Microsoft.Extensions.Logging;

Expand All @@ -19,12 +18,12 @@ namespace Azure.Mcp.Tools.Speech.Services.Recognizers;
/// </summary>
public class FastTranscriptionRecognizer(
ITenantService tenantService,
IHttpClientService httpClientService,
IHttpClientFactory httpClientFactory,
ILogger<FastTranscriptionRecognizer> logger)
: BaseAzureService(tenantService), IFastTranscriptionRecognizer
{
private readonly ILogger<FastTranscriptionRecognizer> _logger = logger;
private readonly IHttpClientService _httpClientService = httpClientService;
private readonly IHttpClientFactory _httpClientFactory = httpClientFactory;

/// <inheritdoc/>
public async Task<FastTranscriptionResult> RecognizeAsync(
Expand Down Expand Up @@ -124,8 +123,9 @@ public async Task<FastTranscriptionResult> RecognizeAsync(
Headers = { Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Token) }
};

// Make the request using HttpClient from service
var response = await _httpClientService.DefaultClient.SendAsync(requestMessage, cancellationToken);
// Make the request using HttpClient from factory
using var httpClient = _httpClientFactory.CreateClient();
var response = await httpClient.SendAsync(requestMessage, cancellationToken);
var responseContent = await response.Content.ReadAsStringAsync(cancellationToken);

if (!response.IsSuccessStatusCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,50 @@
using System.Text.Json;
using Azure.Mcp.Tests;
using Azure.Mcp.Tests.Client;
using Azure.Mcp.Tests.Client.Helpers;
using Azure.Mcp.Tests.Generated.Models;
using Azure.Mcp.Tools.Speech.Models;
using Azure.Mcp.Tools.Speech.Models.Realtime;
using Xunit;

namespace Azure.Mcp.Tools.Speech.LiveTests;

public class SpeechCommandTests(ITestOutputHelper output) : CommandTestsBase(output)
public class SpeechCommandTests(ITestOutputHelper output, TestProxyFixture fixture) : RecordedCommandTestsBase(output, fixture)
{
// Sanitize subscription IDs in URIs
public override List<UriRegexSanitizer> UriRegexSanitizers => new()
{
new UriRegexSanitizer(new UriRegexSanitizerBody
{
Regex = "/subscriptions/(?<sub>[^/]+)/",
GroupForReplace = "sub",
Value = "00000000-0000-0000-0000-000000000000"
})
};

// Sanitize authorization tokens in headers
public override List<HeaderRegexSanitizer> HeaderRegexSanitizers => new()
{
new HeaderRegexSanitizer(new HeaderRegexSanitizerBody("Authorization")
{
Regex = "Bearer (?<token>.+)",
GroupForReplace = "token",
Value = "Sanitized"
})
};

// Sanitize cognitive services hostnames in body content
public override List<BodyRegexSanitizer> BodyRegexSanitizers => new()
{
// Sanitizes all hostnames in URLs to remove actual cognitive services endpoint names
new BodyRegexSanitizer(new BodyRegexSanitizerBody
{
Regex = "(?<=http://|https://)(?<host>[^/?\\.]+)\\.cognitiveservices\\.azure\\.com",
GroupForReplace = "host",
Value = "sanitized"
})
};

#region SpeechToText Tests

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "",
"TagPrefix": "Azure.Mcp.Tools.Speech.LiveTests",
"Tag": ""
}
Loading