Skip to content

Commit 96caf59

Browse files
wehosclaude
andcommitted
fix(tests): 修复凭证 tab 数硬编码与音频证据落盘竞态两条 CI 红
两条互相独立、都不是产品缺陷,都是测试自身的问题: 1. test_credentials_tabs_are_wired_to_the_single_tab_panel 把 tab-btn 个数 锁死成 10。#2819 加了 QQ 音乐凭证源变成 11,main 自那以后每次 push 都红。 数量断言的真实作用只是防止正则失配测出 0 个假绿,改成和 switchTab 调用数 交叉比对:正则一失配立刻不等,新增凭证源不再误红。 2. test_audio_evidence_writes_local_wav_and_index_under_data 在 close() 返回后 立刻 iterdir。close() 只给写线程 50ms 确认窗口,本来就不是落盘保证, Windows runner 磁盘一抖就 FileNotFoundError。改成轮询等 index.jsonl 落地。 只动测试,不动生产的短超时语义(opt-in 调试功能,宁可丢证据也不卡关闭路径)。 变异验证:正则失配→红、漏 aria-controls→红、合规新增第 12 个源→绿; 把 ack 超时归零后带轮询→绿、撤掉轮询→红。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 6c5ad62 commit 96caf59

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

tests/unit/asr_client/endpointing/test_audio_evidence.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import hashlib
44
import json
5+
import time
56
import wave
67
from pathlib import Path
78

@@ -12,6 +13,23 @@
1213
)
1314

1415

16+
def _wait_for_written_run_dir(target: Path, timeout_s: float = 10.0) -> list[Path]:
17+
# 等落盘:close() 只给写线程一个很短的确认窗口,不是落盘保证。正常路径下写线程
18+
# 几毫秒就写完了,但 Windows CI 上磁盘会抖到超过那个窗口,close() 一返回就
19+
# iterdir 会撞上还没建出来的目录。
20+
deadline = time.monotonic() + timeout_s
21+
while True:
22+
try:
23+
run_dirs = list(target.iterdir())
24+
except FileNotFoundError:
25+
run_dirs = []
26+
if run_dirs and all((d / "index.jsonl").exists() for d in run_dirs):
27+
return run_dirs
28+
if time.monotonic() >= deadline:
29+
return run_dirs
30+
time.sleep(0.01)
31+
32+
1533
async def test_audio_evidence_is_off_without_explicit_opt_in(tmp_path: Path) -> None:
1634
target = tmp_path / "data" / "smart_turn" / "audio-evidence"
1735
recorder = create_smart_turn_audio_evidence_recorder(
@@ -54,7 +72,7 @@ async def test_audio_evidence_writes_local_wav_and_index_under_data(
5472
)
5573
await recorder.close()
5674

57-
run_dirs = list(target.iterdir())
75+
run_dirs = _wait_for_written_run_dir(target)
5876
assert recorder.enabled is True
5977
assert len(run_dirs) == 1
6078
run_dir = run_dirs[0]

tests/unit/test_window_pin_static_contracts.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,11 @@ def test_credentials_tabs_are_wired_to_the_single_tab_panel():
252252
template = read_text("templates/cookies_login.html")
253253

254254
tab_buttons = re.findall(r'<button class="tab-btn[^>]*>', template)
255-
assert len(tab_buttons) == 10
255+
# 凭证源会持续增删,锁死具体个数只会让每个新增源都红一次;真正要守的是每个按钮的
256+
# ARIA 接线。和 switchTab 调用数交叉比对,正则一旦失配就会立刻不等,避免测出 0 个假绿。
257+
switch_calls = template.count("switchTab('")
258+
assert switch_calls > 0
259+
assert len(tab_buttons) == switch_calls
256260
for button in tab_buttons:
257261
assert 'role="tab"' in button, button
258262
assert 'aria-controls="main-panel"' in button, button

0 commit comments

Comments
 (0)