Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Test opt-in from the studio and MCP surfaces
Browse files- tests/test_surfaces.py +35 -0
tests/test_surfaces.py
CHANGED
|
@@ -85,6 +85,25 @@ def test_analyze_voice_separates_observed_from_inferred(tools):
|
|
| 85 |
assert f'"{banned}"' not in text
|
| 86 |
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
def test_rewrite_returns_structured_metadata_and_accepts_constraints(tools):
|
| 89 |
profile = json.dumps(tools['analyze_voice'](SAMPLE, model_reading=False)['voice_profile'])
|
| 90 |
text = 'I am writing to inform you that I think this could help. We utilize two tools.'
|
|
@@ -163,12 +182,28 @@ def test_manifest_and_mcp_schema_expose_exactly_the_six_tools(client):
|
|
| 163 |
schema = client.get('/gradio_api/mcp/schema').json()
|
| 164 |
names = {tool['name'] for tool in schema}
|
| 165 |
assert names == set(TOOLS), names
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
rewrite = next(tool for tool in schema if tool['name'] == 'rewrite_in_voice')
|
| 167 |
assert rewrite['description'].startswith('Use rewrite_in_voice when') and 'Returns:' in rewrite['description']
|
| 168 |
assert all(p['description'] for p in rewrite['inputSchema']['properties'].values())
|
| 169 |
assert {'voice_profile', 'intent', 'edit_strength', 'preserve', 'avoid', 'audience', 'length_target'} <= set(rewrite['inputSchema']['properties'])
|
| 170 |
|
| 171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
def test_tool_call_over_http_returns_structured_json(client):
|
| 173 |
started = client.post('/gradio_api/call/inspect_changes', json={'data': ['I think this could help.', 'This will help.', '', '']})
|
| 174 |
event = started.json()['event_id']
|
|
|
|
| 85 |
assert f'"{banned}"' not in text
|
| 86 |
|
| 87 |
|
| 88 |
+
def test_voice_measurement_calls_provider_only_on_explicit_opt_in(monkeypatch):
|
| 89 |
+
provider = FixtureProvider()
|
| 90 |
+
generate = provider.generate
|
| 91 |
+
calls = []
|
| 92 |
+
|
| 93 |
+
def record(request):
|
| 94 |
+
calls.append(request)
|
| 95 |
+
return generate(request)
|
| 96 |
+
|
| 97 |
+
monkeypatch.setattr(provider, 'generate', record)
|
| 98 |
+
analyze = build_tools(HumanTouch(provider))['analyze_voice']
|
| 99 |
+
for args in ({}, {'model_reading': False}):
|
| 100 |
+
report = analyze(SAMPLE, **args)
|
| 101 |
+
assert report['model_reading'] == 'not requested'
|
| 102 |
+
assert not calls
|
| 103 |
+
assert analyze(SAMPLE, model_reading=True)['model_reading'] == 'included'
|
| 104 |
+
assert len(calls) == 1
|
| 105 |
+
|
| 106 |
+
|
| 107 |
def test_rewrite_returns_structured_metadata_and_accepts_constraints(tools):
|
| 108 |
profile = json.dumps(tools['analyze_voice'](SAMPLE, model_reading=False)['voice_profile'])
|
| 109 |
text = 'I am writing to inform you that I think this could help. We utilize two tools.'
|
|
|
|
| 182 |
schema = client.get('/gradio_api/mcp/schema').json()
|
| 183 |
names = {tool['name'] for tool in schema}
|
| 184 |
assert names == set(TOOLS), names
|
| 185 |
+
voice = next(tool for tool in schema if tool['name'] == 'analyze_voice')
|
| 186 |
+
assert voice['inputSchema']['properties']['model_reading'].get('default', False) is False
|
| 187 |
+
assert 'Default false' in voice['inputSchema']['properties']['model_reading']['description']
|
| 188 |
+
listing = client.post('/gradio_api/mcp/', headers={'accept': 'application/json, text/event-stream'},
|
| 189 |
+
json={'jsonrpc': '2.0', 'id': 1, 'method': 'tools/list', 'params': {}})
|
| 190 |
+
data = json.loads(next(line[6:] for line in listing.text.splitlines() if line.startswith('data: ')))
|
| 191 |
+
mcp_voice = next(tool for tool in data['result']['tools'] if tool['name'] == 'analyze_voice')
|
| 192 |
+
assert mcp_voice['inputSchema']['properties']['model_reading']['default'] is False
|
| 193 |
+
assert 'model_reading' not in mcp_voice['inputSchema'].get('required', [])
|
| 194 |
+
assert mcp_voice['annotations']['openWorldHint'] is True
|
| 195 |
rewrite = next(tool for tool in schema if tool['name'] == 'rewrite_in_voice')
|
| 196 |
assert rewrite['description'].startswith('Use rewrite_in_voice when') and 'Returns:' in rewrite['description']
|
| 197 |
assert all(p['description'] for p in rewrite['inputSchema']['properties'].values())
|
| 198 |
assert {'voice_profile', 'intent', 'edit_strength', 'preserve', 'avoid', 'audience', 'length_target'} <= set(rewrite['inputSchema']['properties'])
|
| 199 |
|
| 200 |
|
| 201 |
+
def test_studio_voice_reading_is_unchecked_with_a_provider(client):
|
| 202 |
+
components = client.get('/config').json()['components']
|
| 203 |
+
checkbox = next(c for c in components if 'Also ask the model what it notices' in (c['props'].get('label') or ''))
|
| 204 |
+
assert checkbox['props']['value'] is False and checkbox['props']['interactive'] is True
|
| 205 |
+
|
| 206 |
+
|
| 207 |
def test_tool_call_over_http_returns_structured_json(client):
|
| 208 |
started = client.post('/gradio_api/call/inspect_changes', json={'data': ['I think this could help.', 'This will help.', '', '']})
|
| 209 |
event = started.json()['event_id']
|