Skip to content

Commit 70fd59a

Browse files
authored
Add playback coverage for telephony live tests (#50546)
1 parent afefa99 commit 70fd59a

4 files changed

Lines changed: 202 additions & 67 deletions

File tree

‎sdk/ai/azure-ai-agents/assets.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "java",
44
"TagPrefix": "java/ai/azure-ai-agents",
5-
"Tag": "java/ai/azure-ai-agents_6ddbbdb9ab"
5+
"Tag": "java/ai/azure-ai-agents_e35b6629e1"
66
}

‎sdk/ai/azure-ai-agents/src/test/java/com/azure/ai/agents/ClientTestBase.java‎

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,31 @@
2121

2222
import java.util.ArrayList;
2323
import java.util.Arrays;
24+
import java.util.Collections;
25+
import java.util.List;
2426

2527
public class ClientTestBase extends TestProxyTestBase {
2628

2729
private boolean sanitizersRemoved = false;
2830

2931
protected AgentsClientBuilder getClientBuilder(HttpClient httpClient, AgentsServiceVersion agentsServiceVersion) {
32+
return getClientBuilder(httpClient, agentsServiceVersion, false);
33+
}
34+
35+
protected AgentsClientBuilder getClientBuilder(HttpClient httpClient, AgentsServiceVersion agentsServiceVersion,
36+
boolean allowPreview) {
3037
AgentsClientBuilder builder = new AgentsClientBuilder()
3138
.httpClient(interceptorManager.isPlaybackMode() ? interceptorManager.getPlaybackClient() : httpClient);
3239
TestMode testMode = getTestMode();
3340
if (testMode != TestMode.LIVE) {
3441
addCustomMatchers();
3542
addTestRecordCustomSanitizers();
36-
// Disable "$..id"=AZSDK3430, "Set-Cookie"=AZSDK2015 for both azure and non-azure clients from the list of common sanitizers.
43+
// Disable "$..id"=AZSDK3430 and "Set-Cookie"=AZSDK2015 for both Azure and non-Azure clients from the
44+
// list of common sanitizers.
3745
if (!sanitizersRemoved) {
38-
interceptorManager.removeSanitizers("AZSDK3430", "AZSDK3493", "AZSDK2015");
46+
List<String> sanitizersToRemove = new ArrayList<>(Arrays.asList("AZSDK3430", "AZSDK3493", "AZSDK2015"));
47+
sanitizersToRemove.addAll(getAdditionalTestProxySanitizersToRemove());
48+
interceptorManager.removeSanitizers(sanitizersToRemove.toArray(new String[0]));
3949
sanitizersRemoved = true;
4050
}
4151
}
@@ -56,13 +66,21 @@ protected AgentsClientBuilder getClientBuilder(HttpClient httpClient, AgentsServ
5666
AgentsServiceVersion serviceVersion
5767
= version == null ? agentsServiceVersion : AgentsServiceVersion.valueOf(version);
5868
builder.serviceVersion(serviceVersion);
69+
if (allowPreview) {
70+
builder.allowPreview(true);
71+
}
5972
return builder;
6073
}
6174

6275
protected AgentsClient getAgentsSyncClient(HttpClient httpClient, AgentsServiceVersion agentsServiceVersion) {
6376
return getClientBuilder(httpClient, agentsServiceVersion).buildAgentsClient();
6477
}
6578

79+
protected AgentsClient getPreviewAgentsSyncClient(HttpClient httpClient,
80+
AgentsServiceVersion agentsServiceVersion) {
81+
return getClientBuilder(httpClient, agentsServiceVersion, true).buildAgentsClient();
82+
}
83+
6684
protected AgentsAsyncClient getAgentsAsyncClient(HttpClient httpClient, AgentsServiceVersion agentsServiceVersion) {
6785
return getClientBuilder(httpClient, agentsServiceVersion).buildAgentsAsyncClient();
6886
}
@@ -106,6 +124,11 @@ protected BetaMemoryStoresAsyncClient getMemoryStoresAsyncClient(HttpClient http
106124
return getClientBuilder(httpClient, agentsServiceVersion).beta().buildBetaMemoryStoresAsyncClient();
107125
}
108126

127+
protected BetaVoiceAgentsTelephonyClient getVoiceAgentsTelephonySyncClient(HttpClient httpClient,
128+
AgentsServiceVersion agentsServiceVersion) {
129+
return getClientBuilder(httpClient, agentsServiceVersion, true).beta().buildBetaVoiceAgentsTelephonyClient();
130+
}
131+
109132
private void addTestRecordCustomSanitizers() {
110133

111134
ArrayList<TestProxySanitizer> sanitizers = new ArrayList<>();
@@ -120,10 +143,30 @@ private void addTestRecordCustomSanitizers() {
120143
}
121144

122145
private void addCustomMatchers() {
123-
interceptorManager.addMatchers(new CustomMatcher()
124-
.setExcludedHeaders(Arrays.asList("Cookie", "Set-Cookie", "Accept", "X-Stainless-Arch", "X-Stainless-Lang",
146+
List<String> excludedHeaders
147+
= new ArrayList<>(Arrays.asList("Cookie", "Set-Cookie", "Accept", "X-Stainless-Arch", "X-Stainless-Lang",
125148
"X-Stainless-OS", "X-Stainless-OS-Version", "X-Stainless-Package-Version", "X-Stainless-Runtime",
126-
"X-Stainless-Runtime-Version", "X-Stainless-Kotlin-Version", "X-Stainless-Retry-Count")));
149+
"X-Stainless-Runtime-Version", "X-Stainless-Kotlin-Version", "X-Stainless-Retry-Count"));
150+
excludedHeaders.addAll(getAdditionalTestProxyExcludedHeaders());
151+
interceptorManager.addMatchers(new CustomMatcher().setExcludedHeaders(excludedHeaders));
152+
}
153+
154+
/**
155+
* Returns request headers that a derived test class needs the test proxy to exclude from playback matching.
156+
*
157+
* @return Additional request header names to exclude.
158+
*/
159+
protected List<String> getAdditionalTestProxyExcludedHeaders() {
160+
return Collections.emptyList();
161+
}
162+
163+
/**
164+
* Returns common sanitizer IDs that a derived test class needs to replace with test-specific sanitizers.
165+
*
166+
* @return Additional common sanitizer IDs to remove.
167+
*/
168+
protected List<String> getAdditionalTestProxySanitizersToRemove() {
169+
return Collections.emptyList();
127170
}
128171

129172
protected void sleep(long millis) {

0 commit comments

Comments
 (0)