feat: 增强 HomeScreen 录音交互与 ChatBloc 状态管理
- 新增录音启动延迟处理,解决权限未就绪时的竞态问题 - 实现历史分页滚动位置保持,提升加载体验 - 添加文本输入框点击键盘显示与焦点管理 - 优化 ChatBloc provider 到 MultiBlocProvider 支持 - 修复 ApiException 429 错误详情解析(支持 JSON 字符串 body) - 改进 LocalNotificationService 精确闹钟权限请求 - 优化 UiSchemaRenderer GridView children 生成 - 支持导航 action 的 replace 参数 - 移除 Agent router 速率限制逻辑(_allow_run_request, _allow_transcribe_request) - 补充相关单元测试与集成测试
This commit is contained in:
@@ -118,13 +118,6 @@ class _FailingStreamAgentService(_FakeAgentService):
|
||||
def test_run_requires_auth_and_returns_202_task_id() -> None:
|
||||
app.dependency_overrides[get_agent_service] = lambda: _FakeAgentService()
|
||||
client = TestClient(app)
|
||||
original_allow_run = agent_router._allow_run_request
|
||||
|
||||
async def _allow_run(*, user_id: str) -> bool:
|
||||
del user_id
|
||||
return True
|
||||
|
||||
agent_router._allow_run_request = _allow_run # type: ignore[assignment]
|
||||
|
||||
try:
|
||||
unauthorized = client.post(
|
||||
@@ -162,7 +155,6 @@ def test_run_requires_auth_and_returns_202_task_id() -> None:
|
||||
assert authorized.json()["runId"] == "run-1"
|
||||
assert authorized.json()["created"] is False
|
||||
finally:
|
||||
agent_router._allow_run_request = original_allow_run # type: ignore[assignment]
|
||||
app.dependency_overrides = {}
|
||||
|
||||
|
||||
@@ -410,12 +402,6 @@ def test_asr_transcribe_returns_sync_transcript(monkeypatch) -> None:
|
||||
id=uuid4(), email="user@example.com"
|
||||
)
|
||||
|
||||
async def _allow_transcribe(*, user_id: str) -> bool:
|
||||
del user_id
|
||||
return True
|
||||
|
||||
monkeypatch.setattr(agent_router, "_allow_transcribe_request", _allow_transcribe)
|
||||
|
||||
async def mock_transcribe_file(file_path: str, filename: str) -> str:
|
||||
assert file_path.endswith(".wav")
|
||||
assert filename == "test.wav"
|
||||
@@ -453,12 +439,6 @@ def test_asr_transcribe_rejects_oversized_audio(monkeypatch) -> None:
|
||||
|
||||
monkeypatch.setattr(agent_router, "_MAX_TRANSCRIBE_AUDIO_BYTES", 4)
|
||||
|
||||
async def _allow_transcribe(*, user_id: str) -> bool:
|
||||
del user_id
|
||||
return True
|
||||
|
||||
monkeypatch.setattr(agent_router, "_allow_transcribe_request", _allow_transcribe)
|
||||
|
||||
client = TestClient(app)
|
||||
oversized = BytesIO(b"12345")
|
||||
oversized.name = "test.wav"
|
||||
@@ -480,12 +460,6 @@ def test_asr_transcribe_rejects_non_wav_audio(monkeypatch) -> None:
|
||||
id=uuid4(), email="user@example.com"
|
||||
)
|
||||
|
||||
async def _allow_transcribe(*, user_id: str) -> bool:
|
||||
del user_id
|
||||
return True
|
||||
|
||||
monkeypatch.setattr(agent_router, "_allow_transcribe_request", _allow_transcribe)
|
||||
|
||||
client = TestClient(app)
|
||||
fake_mp3 = BytesIO(b"fake-mp3")
|
||||
fake_mp3.name = "test.mp3"
|
||||
@@ -507,12 +481,6 @@ def test_asr_transcribe_rejects_invalid_wav_payload(monkeypatch) -> None:
|
||||
id=uuid4(), email="user@example.com"
|
||||
)
|
||||
|
||||
async def _allow_transcribe(*, user_id: str) -> bool:
|
||||
del user_id
|
||||
return True
|
||||
|
||||
monkeypatch.setattr(agent_router, "_allow_transcribe_request", _allow_transcribe)
|
||||
|
||||
client = TestClient(app)
|
||||
fake_payload = BytesIO(b"not-a-wav")
|
||||
fake_payload.name = "test.wav"
|
||||
@@ -527,33 +495,3 @@ def test_asr_transcribe_rejects_invalid_wav_payload(monkeypatch) -> None:
|
||||
assert response.json()["detail"] == "Unsupported audio format"
|
||||
finally:
|
||||
app.dependency_overrides = {}
|
||||
|
||||
|
||||
def test_asr_transcribe_rejects_when_rate_limited_for_current_user(monkeypatch) -> None:
|
||||
known_user = CurrentUser(id=uuid4(), email="user@example.com")
|
||||
app.dependency_overrides[get_current_user] = lambda: known_user
|
||||
|
||||
captured_user_ids: list[str] = []
|
||||
|
||||
async def _deny_transcribe(*, user_id: str) -> bool:
|
||||
captured_user_ids.append(user_id)
|
||||
return False
|
||||
|
||||
monkeypatch.setattr(agent_router, "_allow_transcribe_request", _deny_transcribe)
|
||||
|
||||
client = TestClient(app)
|
||||
wav_content = b"RIFF\x24\x80\x00\x00WAVEfmt "
|
||||
wav_file = BytesIO(wav_content)
|
||||
wav_file.name = "test.wav"
|
||||
|
||||
try:
|
||||
response = client.post(
|
||||
"/api/v1/agent/transcribe",
|
||||
files={"audio": ("test.wav", wav_file, "audio/wav")},
|
||||
)
|
||||
|
||||
assert response.status_code == 429
|
||||
assert response.json()["detail"] == "Too many transcribe requests"
|
||||
assert captured_user_ids == [str(known_user.id)]
|
||||
finally:
|
||||
app.dependency_overrides = {}
|
||||
|
||||
Reference in New Issue
Block a user