earshot-cli 0.6.0__tar.gz → 0.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/PKG-INFO +2 -2
  2. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/README.md +1 -1
  3. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/pyproject.toml +1 -1
  4. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/src/earshot/deliver.py +132 -39
  5. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/tests/test_deliver.py +21 -0
  6. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/tests/test_deliver_api.py +103 -2
  7. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/uv.lock +1 -1
  8. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/.github/workflows/ci.yml +0 -0
  9. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/.github/workflows/publish.yml +0 -0
  10. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/.gitignore +0 -0
  11. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/LICENSE +0 -0
  12. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/scripts/download_models.sh +0 -0
  13. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/src/earshot/__init__.py +0 -0
  14. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/src/earshot/auth.py +0 -0
  15. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/src/earshot/capture.py +0 -0
  16. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/src/earshot/cli.py +0 -0
  17. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/src/earshot/compose.py +0 -0
  18. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/src/earshot/config.py +0 -0
  19. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/src/earshot/extract.py +0 -0
  20. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/src/earshot/hardsub.py +0 -0
  21. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/src/earshot/live.py +0 -0
  22. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/src/earshot/models.py +0 -0
  23. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/src/earshot/subtitle.py +0 -0
  24. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/src/earshot/transcribe.py +0 -0
  25. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/src/earshot/transcribe_cloud.py +0 -0
  26. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/tests/conftest.py +0 -0
  27. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/tests/test_auth.py +0 -0
  28. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/tests/test_compose.py +0 -0
  29. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/tests/test_config.py +0 -0
  30. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/tests/test_credential_lifecycle.py +0 -0
  31. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/tests/test_do_deliver.py +0 -0
  32. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/tests/test_extract.py +0 -0
  33. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/tests/test_hardsub.py +0 -0
  34. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/tests/test_live.py +0 -0
  35. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/tests/test_me.py +0 -0
  36. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/tests/test_subtitle.py +0 -0
  37. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/tests/test_ua.py +0 -0
  38. {earshot_cli-0.6.0 → earshot_cli-0.7.0}/tests/test_wizard.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: earshot-cli
3
- Version: 0.6.0
3
+ Version: 0.7.0
4
4
  Summary: 旁听剪藏:跨平台桌面端系统声录制 → 本地转写 → 投递知识库(默认 ExoMind,可插拔)
5
5
  Project-URL: Homepage, https://github.com/helloworldtang/earshot
6
6
  Project-URL: Repository, https://github.com/helloworldtang/earshot
@@ -162,7 +162,7 @@ uv tool upgrade earshot-cli
162
162
  源码安装请**锁版本 tag**,不要引滚动的 `main`(消费方 `uv sync`/`pip install` 会隐性升级到未审阅代码;升级应当是显式改版本号的决策):
163
163
 
164
164
  ```bash
165
- uv tool install "earshot-cli @ https://github.com/helloworldtang/earshot/archive/refs/tags/v0.3.1.tar.gz"
165
+ uv tool install "earshot-cli @ https://github.com/helloworldtang/earshot/archive/refs/tags/v0.7.0.tar.gz"
166
166
  ```
167
167
 
168
168
  - **零系统依赖**:ffmpeg 已随 Python wheel 内置([imageio-ffmpeg](https://pypi.org/project/imageio-ffmpeg),MoviePy 同款),无需 brew/apt。
@@ -127,7 +127,7 @@ uv tool upgrade earshot-cli
127
127
  源码安装请**锁版本 tag**,不要引滚动的 `main`(消费方 `uv sync`/`pip install` 会隐性升级到未审阅代码;升级应当是显式改版本号的决策):
128
128
 
129
129
  ```bash
130
- uv tool install "earshot-cli @ https://github.com/helloworldtang/earshot/archive/refs/tags/v0.3.1.tar.gz"
130
+ uv tool install "earshot-cli @ https://github.com/helloworldtang/earshot/archive/refs/tags/v0.7.0.tar.gz"
131
131
  ```
132
132
 
133
133
  - **零系统依赖**:ffmpeg 已随 Python wheel 内置([imageio-ffmpeg](https://pypi.org/project/imageio-ffmpeg),MoviePy 同款),无需 brew/apt。
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "earshot-cli"
3
- version = "0.6.0"
3
+ version = "0.7.0"
4
4
  description = "旁听剪藏:跨平台桌面端系统声录制 → 本地转写 → 投递知识库(默认 ExoMind,可插拔)"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -20,6 +20,9 @@ EXOMIND_PENDING_EXIT_CODE = 3 # exomind CLI 契约:3 = 已提交、后台仍在
20
20
  DELIVER_TIMEOUT_S = 600.0
21
21
  INGEST_POLL_INTERVAL_S = 2.0
22
22
  INGEST_POLL_BUDGET_S = 120.0
23
+ # 服务端 IngestRequest 上限 MAX_INGEST_CONTENT=30000 字符,超限 422「请拆成几次存入」;
24
+ # 客户端留 2K 余量按段落边界预分片,避免整篇转写被一次性拒收(2026-11-15,45K 录播课转写实证)。
25
+ INGEST_MAX_CONTENT_CHARS = 28000
23
26
 
24
27
 
25
28
  @dataclass(frozen=True, slots=True)
@@ -85,6 +88,27 @@ def deliver_exomind(
85
88
  return DeliveryResult("failed", detail)
86
89
 
87
90
 
91
+ def _raise_with_server_detail(resp: httpx.Response) -> None:
92
+ """is_error 响应抛 RuntimeError 并带上服务端 detail(失败信息与失败事实同源)。
93
+
94
+ 裸状态码(如「422」)用户无从下手;拒收原因(内容太长/标题超限等)只在
95
+ 响应体里。JSON 取 detail 字段,解析不了退回响应体前 200 字符。
96
+
97
+ Args:
98
+ resp: 已完成的 httpx 响应。
99
+
100
+ Raises:
101
+ RuntimeError: 携带 ``HTTP {status_code}: {detail}`` 格式的错误。
102
+ """
103
+ try:
104
+ body: Any = resp.json()
105
+ detail = body.get("detail") if isinstance(body, dict) else body
106
+ msg = str(detail) if detail else resp.text[:200]
107
+ except ValueError:
108
+ msg = resp.text[:200]
109
+ raise RuntimeError(f"HTTP {resp.status_code}: {msg}") from None
110
+
111
+
88
112
  def deliver_webhook(
89
113
  url: str,
90
114
  title: str,
@@ -109,7 +133,8 @@ def deliver_webhook(
109
133
 
110
134
  def _post(target: str, payload: dict[str, str | list[str]]) -> None:
111
135
  resp = httpx.post(target, json=payload, timeout=30.0)
112
- resp.raise_for_status()
136
+ if resp.is_error:
137
+ _raise_with_server_detail(resp)
113
138
 
114
139
  send = poster or _post
115
140
  payload: dict[str, str | list[str]] = {"origin": origin, "title": title, "content": content_md, "tags": tags}
@@ -134,6 +159,42 @@ def _as_count(value: Any) -> int:
134
159
  return 0
135
160
 
136
161
 
162
+ def split_for_ingest(content: str, limit: int = INGEST_MAX_CONTENT_CHARS) -> list[str]:
163
+ """按段落边界贪心分片,单段超限时再按字符硬切。
164
+
165
+ 服务端对 content 有 30000 字符硬上限(超限 422 拒收并提示拆分),
166
+ 长转写(1h 录播课 ~45K 字符)必须客户端预分片。
167
+
168
+ Args:
169
+ content: 完整正文。
170
+ limit: 单片字符上限。
171
+
172
+ Returns:
173
+ 分片列表;不超过 limit 时原样单元素返回。各片拼接内容与原文一致
174
+ (硬切场景仅多出切点处的字符分裂,不丢字)。
175
+ """
176
+ if len(content) <= limit:
177
+ return [content]
178
+ chunks: list[str] = []
179
+ buf = ""
180
+ for para in content.split("\n\n"):
181
+ while len(para) > limit:
182
+ if buf:
183
+ chunks.append(buf)
184
+ buf = ""
185
+ chunks.append(para[:limit])
186
+ para = para[limit:]
187
+ cand = f"{buf}\n\n{para}" if buf else para
188
+ if len(cand) > limit:
189
+ chunks.append(buf)
190
+ buf = para
191
+ else:
192
+ buf = cand
193
+ if buf:
194
+ chunks.append(buf)
195
+ return chunks
196
+
197
+
137
198
  def deliver_exomind_api(
138
199
  md_path: Path,
139
200
  title: str,
@@ -149,6 +210,9 @@ def deliver_exomind_api(
149
210
 
150
211
  走 POST /ingest/async + GET /ingest/status,与 CLI 同契约:
151
212
  秒回 job_id → 轮询至 done/failed;超预算视为 pending(内容已入库,抽取仍在跑)。
213
+ 正文超 INGEST_MAX_CONTENT_CHARS 时按段落边界自动分片逐片投递
214
+ (标题加「(i/n)」后缀,各片独立 client_key);任一片失败即 failed,
215
+ detail 注明已成功的片,未投的片不再发。
152
216
 
153
217
  Args:
154
218
  md_path: 笔记文件。
@@ -157,7 +221,7 @@ def deliver_exomind_api(
157
221
  settings: 含 base_url / api_key 的配置。
158
222
  poster: ``(url, payload, headers) -> 响应 dict``(测试注入)。
159
223
  getter: ``(url, params, headers) -> 响应 dict``(测试注入)。
160
- poll_interval_s / poll_budget_s: 轮询节奏与总预算。
224
+ poll_interval_s / poll_budget_s: 轮询节奏与总预算(单片)。
161
225
  source_url: 原文链接(video 路线);content+url 并存时服务端仅作出处留痕,不抓取。
162
226
 
163
227
  Returns:
@@ -168,7 +232,8 @@ def deliver_exomind_api(
168
232
 
169
233
  def _post(url: str, payload: dict[str, Any], headers: dict[str, str]) -> dict[str, Any]:
170
234
  resp = httpx.post(url, json=payload, headers=headers, timeout=60.0)
171
- resp.raise_for_status()
235
+ if resp.is_error:
236
+ _raise_with_server_detail(resp)
172
237
  return dict(resp.json())
173
238
 
174
239
  def _get(url: str, params: dict[str, str], headers: dict[str, str]) -> dict[str, Any]:
@@ -182,39 +247,67 @@ def deliver_exomind_api(
182
247
  headers = ua_headers(Authorization=f"Bearer {settings.exomind_api_key}")
183
248
 
184
249
  content = md_path.read_text(encoding="utf-8")
185
- payload: dict[str, Any] = {"content": content, "origin": EXOMIND_ORIGIN, "client_key": client_key_for(content)}
186
- if title:
187
- payload["title"] = title
188
- if tags:
189
- payload["tags"] = tags
190
- if source_url:
191
- payload["url"] = source_url
192
- try:
193
- resp = post(f"{base}/ingest/async", payload, headers)
194
- except Exception as e:
195
- return DeliveryResult("failed", f"提交 ingest 失败: {e}")
196
- job_id = resp.get("job_id")
197
- if not job_id:
198
- return DeliveryResult("failed", f"响应缺 job_id: {str(resp)[:200]}")
199
-
200
- deadline = time.monotonic() + poll_budget_s
201
- try:
202
- while time.monotonic() < deadline:
203
- try:
204
- st = get(f"{base}/ingest/status", {"job_id": str(job_id)}, headers)
205
- except Exception as e:
206
- return DeliveryResult("failed", f"查询回执失败(job_id={job_id}): {e}")
207
- status = st.get("status")
208
- if status == "done":
209
- n_entities = _as_count(st.get("entities"))
210
- n_pages = _as_count(st.get("created_pages"))
211
- n_updated = _as_count(st.get("updated_pages"))
212
- detail = f"已入库:实体 {n_entities} 个,页面 +{n_pages}/更{n_updated}(job_id={job_id})"
213
- return DeliveryResult("delivered", detail)
214
- if status == "failed":
215
- return DeliveryResult("failed", f"服务端抽取失败: {st.get('error', '未知')}(job_id={job_id})")
216
- time.sleep(poll_interval_s)
217
- except KeyboardInterrupt:
218
- # Ctrl-C = 不等回执了;内容已提交,服务端 job 会继续跑完
219
- return DeliveryResult("pending", f"已提交,不再等待回执(job_id={job_id})")
220
- return DeliveryResult("pending", f"已提交,后台抽取中(job_id={job_id})")
250
+ chunks = split_for_ingest(content)
251
+ total = len(chunks)
252
+
253
+ def _deliver_chunk(idx: int, chunk: str) -> DeliveryResult:
254
+ """投递单片:提交 → 轮询回执,与未分片路径完全同构。"""
255
+ chunk_title = title
256
+ if total > 1 and title:
257
+ # 服务端标题上限 200 字符,后缀前先截,拒收在客户端就挡住
258
+ chunk_title = f"{title[:190]}({idx}/{total})"
259
+ payload: dict[str, Any] = {"content": chunk, "origin": EXOMIND_ORIGIN, "client_key": client_key_for(chunk)}
260
+ if chunk_title:
261
+ payload["title"] = chunk_title
262
+ if tags:
263
+ payload["tags"] = tags
264
+ if source_url:
265
+ payload["url"] = source_url
266
+ try:
267
+ resp = post(f"{base}/ingest/async", payload, headers)
268
+ except Exception as e:
269
+ return DeliveryResult("failed", f"提交 ingest 失败: {e}")
270
+ job_id = resp.get("job_id")
271
+ if not job_id:
272
+ return DeliveryResult("failed", f"响应缺 job_id: {str(resp)[:200]}")
273
+
274
+ deadline = time.monotonic() + poll_budget_s
275
+ try:
276
+ while time.monotonic() < deadline:
277
+ try:
278
+ st = get(f"{base}/ingest/status", {"job_id": str(job_id)}, headers)
279
+ except Exception as e:
280
+ return DeliveryResult("failed", f"查询回执失败(job_id={job_id}): {e}")
281
+ status = st.get("status")
282
+ if status == "done":
283
+ n_entities = _as_count(st.get("entities"))
284
+ n_pages = _as_count(st.get("created_pages"))
285
+ n_updated = _as_count(st.get("updated_pages"))
286
+ detail = f"已入库:实体 {n_entities} 个,页面 +{n_pages}/更{n_updated}(job_id={job_id})"
287
+ return DeliveryResult("delivered", detail)
288
+ if status == "failed":
289
+ return DeliveryResult("failed", f"服务端抽取失败: {st.get('error', '未知')}(job_id={job_id})")
290
+ time.sleep(poll_interval_s)
291
+ except KeyboardInterrupt:
292
+ # Ctrl-C = 不等回执了;内容已提交,服务端 job 会继续跑完
293
+ return DeliveryResult("pending", f"已提交,不再等待回执(job_id={job_id})")
294
+ return DeliveryResult("pending", f"已提交,后台抽取中(job_id={job_id})")
295
+
296
+ results = [_deliver_chunk(i + 1, chunk) for i, chunk in enumerate(chunks)]
297
+ if total == 1:
298
+ return results[0]
299
+ prefix = f"分 {total} 片投递:"
300
+ statuses = {r.status for r in results}
301
+ if statuses == {"delivered"}:
302
+ summary = ";".join(f"片{i + 1} {r.detail}" for i, r in enumerate(results))
303
+ return DeliveryResult("delivered", f"{prefix}全部入库。{summary}")
304
+ if "failed" in statuses:
305
+ ok = sum(1 for r in results if r.status == "delivered")
306
+ failed_idx = next(i + 1 for i, r in enumerate(results) if r.status == "failed")
307
+ return DeliveryResult(
308
+ "failed",
309
+ f"{prefix}第 {failed_idx} 片失败({results[failed_idx - 1].detail}),已成功 {ok}/{total} 片;"
310
+ "已入库片重跑时会按 client_key 幂等去重",
311
+ )
312
+ summary = ";".join(f"片{i + 1} {r.status}:{r.detail}" for i, r in enumerate(results))
313
+ return DeliveryResult("pending", f"{prefix}部分片仍在抽取。{summary}")
@@ -1,6 +1,7 @@
1
1
  """deliver 模块单测:exomind 命令 wire 契约 + 退出码分类 + webhook。"""
2
2
 
3
3
  from pathlib import Path
4
+ from typing import Any
4
5
 
5
6
  from earshot.deliver import build_exomind_args, deliver_exomind, deliver_webhook
6
7
 
@@ -95,3 +96,23 @@ def test_deliver_webhook_failure() -> None:
95
96
  result = deliver_webhook("https://example.com/hook", "t", "c", [], poster=poster)
96
97
  assert result.status == "failed"
97
98
  assert "connection refused" in result.detail
99
+
100
+
101
+ def test_deliver_webhook_error_surfaces_server_detail(monkeypatch: Any) -> None:
102
+ """质量点:webhook 4xx/5xx 响应体里的 detail 必须进失败信息,不裸奔状态码。"""
103
+
104
+ class _FakeResp:
105
+ is_error = True
106
+ status_code = 400
107
+ text = '{"detail":"invalid signature"}'
108
+
109
+ def json(self) -> dict[str, str]:
110
+ return {"detail": "invalid signature"}
111
+
112
+ import earshot.deliver as deliver_mod
113
+
114
+ monkeypatch.setattr(deliver_mod.httpx, "post", lambda *a, **k: _FakeResp(), raising=True)
115
+ result = deliver_webhook("https://example.com/hook", "t", "c", [])
116
+ assert result.status == "failed"
117
+ assert "HTTP 400" in result.detail
118
+ assert "invalid signature" in result.detail
@@ -1,10 +1,15 @@
1
- """deliver_exomind_api 单测:直连 HTTP 投递(wire 契约 + 轮询状态机)。"""
1
+ """deliver_exomind_api 单测:直连 HTTP 投递(wire 契约 + 轮询状态机 + 超长分片)。"""
2
2
 
3
3
  from pathlib import Path
4
4
  from typing import Any
5
5
 
6
6
  from earshot.config import Settings
7
- from earshot.deliver import client_key_for, deliver_exomind_api
7
+ from earshot.deliver import (
8
+ INGEST_MAX_CONTENT_CHARS,
9
+ client_key_for,
10
+ deliver_exomind_api,
11
+ split_for_ingest,
12
+ )
8
13
 
9
14
 
10
15
  def _settings() -> Settings:
@@ -179,3 +184,99 @@ def test_deliver_api_ctrl_c_during_poll_is_pending(tmp_path: Path) -> None:
179
184
  assert result.status == "pending"
180
185
  assert "不再等待回执" in result.detail
181
186
  assert "j-int" in result.detail
187
+
188
+
189
+ def test_split_for_ingest_short_content_untouched() -> None:
190
+ assert split_for_ingest("短内容") == ["短内容"]
191
+ assert split_for_ingest("x" * INGEST_MAX_CONTENT_CHARS) == ["x" * INGEST_MAX_CONTENT_CHARS]
192
+
193
+
194
+ def test_split_for_ingest_paragraph_greedy_no_loss() -> None:
195
+ """质量点:各片均不超限,且不丢段、不重段、顺序不变。"""
196
+ paras = [f"第{i}段" + "字" * 9000 for i in range(10)] # 10 段×~9K = 90K → 4 片左右
197
+ content = "\n\n".join(paras)
198
+ chunks = split_for_ingest(content)
199
+ assert len(chunks) > 1
200
+ assert all(len(c) <= INGEST_MAX_CONTENT_CHARS for c in chunks)
201
+ rejoined = [c for chunk in chunks for c in chunk.split("\n\n")]
202
+ assert rejoined == paras
203
+
204
+
205
+ def test_split_for_ingest_single_giant_paragraph_hard_cut() -> None:
206
+ """无段落边界(整篇一段)时按字符硬切,不丢字。"""
207
+ content = "字" * (INGEST_MAX_CONTENT_CHARS + 5000)
208
+ chunks = split_for_ingest(content)
209
+ assert all(len(c) <= INGEST_MAX_CONTENT_CHARS for c in chunks)
210
+ assert "".join(chunks) == content
211
+
212
+
213
+ def test_deliver_api_splits_long_content(tmp_path: Path) -> None:
214
+ """质量点:超长转写自动分片逐片投递,标题带 (i/n),各片独立 client_key。"""
215
+ content = "\n\n".join(f"第{i}段" + "字" * 9000 for i in range(6)) # ~54K → 2 片
216
+ md = tmp_path / "note.md"
217
+ md.write_text(content, encoding="utf-8")
218
+ posts: list[dict[str, Any]] = []
219
+
220
+ def poster(_u: str, payload: dict[str, Any], _h: dict[str, str]) -> dict[str, Any]:
221
+ posts.append(payload)
222
+ return {"job_id": f"j-{len(posts)}"}
223
+
224
+ def getter(_u: str, _p: dict[str, str], _h: dict[str, str]) -> dict[str, Any]:
225
+ return {"status": "done", "entities": 2}
226
+
227
+ result = deliver_exomind_api(md, "长转写", [], _settings(), poster=poster, getter=getter, poll_interval_s=0)
228
+ assert result.status == "delivered"
229
+ assert len(posts) == 2
230
+ assert [p["title"] for p in posts] == ["长转写(1/2)", "长转写(2/2)"]
231
+ assert len({p["client_key"] for p in posts}) == 2
232
+ assert posts[0]["client_key"] == client_key_for(posts[0]["content"])
233
+ assert sum(len(p["content"]) for p in posts) >= len(content) - 10 # 分隔符损耗
234
+ assert "分 2 片" in result.detail
235
+
236
+
237
+ def test_deliver_api_chunk_failure_reports_partial(tmp_path: Path) -> None:
238
+ """质量点:某片失败 → failed 并注明已成功片数,已入库片幂等可重跑。"""
239
+ content = "\n\n".join(f"第{i}段" + "字" * 9000 for i in range(6))
240
+ md = tmp_path / "note.md"
241
+ md.write_text(content, encoding="utf-8")
242
+ posts: list[dict[str, Any]] = []
243
+
244
+ def poster(_u: str, payload: dict[str, Any], _h: dict[str, str]) -> dict[str, Any]:
245
+ posts.append(payload)
246
+ if len(posts) == 2:
247
+ raise RuntimeError("HTTP 422: 内容太长")
248
+ return {"job_id": f"j-{len(posts)}"}
249
+
250
+ def getter(_u: str, _p: dict[str, str], _h: dict[str, str]) -> dict[str, Any]:
251
+ return {"status": "done", "entities": 1}
252
+
253
+ result = deliver_exomind_api(md, "t", [], _settings(), poster=poster, getter=getter, poll_interval_s=0)
254
+ assert result.status == "failed"
255
+ assert "已成功 1/2 片" in result.detail
256
+ assert "HTTP 422" in result.detail # 服务端 detail 必须透出,不吞成裸状态码
257
+
258
+
259
+ def test_deliver_api_post_error_surfaces_server_detail(tmp_path: Path, monkeypatch: Any) -> None:
260
+ """质量点:4xx 响应体里的服务端 detail(如「内容太长」)必须进失败信息。"""
261
+
262
+ class _FakeResp:
263
+ is_error = True
264
+ status_code = 422
265
+ text = '{"detail":"内容太长"}'
266
+
267
+ def json(self) -> dict[str, Any]:
268
+ return {"detail": "内容太长(45570 字符),单次最多 30000 字符"}
269
+
270
+ import earshot.deliver as deliver_mod
271
+
272
+ monkeypatch.setattr(deliver_mod.httpx, "post", lambda *a, **k: _FakeResp(), raising=True)
273
+ md = tmp_path / "note.md"
274
+ md.write_text("内容", encoding="utf-8")
275
+
276
+ def getter(_u: str, _p: dict[str, str], _h: dict[str, str]) -> dict[str, Any]:
277
+ return {"status": "done"}
278
+
279
+ result = deliver_exomind_api(md, "t", [], _settings(), getter=getter, poll_interval_s=0)
280
+ assert result.status == "failed"
281
+ assert "HTTP 422" in result.detail
282
+ assert "45570" in result.detail
@@ -331,7 +331,7 @@ wheels = [
331
331
 
332
332
  [[package]]
333
333
  name = "earshot-cli"
334
- version = "0.6.0"
334
+ version = "0.7.0"
335
335
  source = { editable = "." }
336
336
  dependencies = [
337
337
  { name = "httpx" },
File without changes
File without changes