Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

test(doclib): cover default-budget continuation and clarify cursor contract

myhlolif19a1c296905
diff --git a/docs/next/cli/mineru-read.md b/docs/next/cli/mineru-read.md
index 4c9ca04d..fb089efb 100644
--- a/docs/next/cli/mineru-read.md
+++ b/docs/next/cli/mineru-read.md
@@ -187,6 +187,8 @@ locator-first 读取时:
继续。当前页读完后,仍按单点阅读规则建议下一页。页级 `after` 游标表示该页
已经读完,从下一页开始。它不会重新解析文档,也不会扩大直接单块读取的范围。
+以上页或文档续读语义适用于 `context=0`。块或字符定位的 `context>0` 上下文窗口在截断续读时存在重复与遗漏,属于待单独修复的已知限制。
+
范围读取的续读保留原选择,并以实际页码的块/字符游标推进。例如:
```text
diff --git a/docs/next/decisions/0014-mineru-read-command.md b/docs/next/decisions/0014-mineru-read-command.md
index 3f7cde64..57c4775c 100644
--- a/docs/next/decisions/0014-mineru-read-command.md
+++ b/docs/next/decisions/0014-mineru-read-command.md
@@ -176,6 +176,10 @@ class DocContentResponse(DoclibModel):
- 范围 read 读完后 `next_request=null`,续读不会进入未选择的页面;已有单点 read 的续读行为保持不变。
- image 输出时 `content=""`,asset 信息写入 `asset`,不把图片路径塞进 `content`。
+> 2026-11-11 续读修正。本节单点读取的续读字段约定已调整,`context=0` 的文档或单点页定位在页内截断时,
+> `next_request` 同时携带文档 `locator` 和已消费位置 `after`,当前页完成后继续建议下一页。
+> 现行行为及客户端示例见 [CLI 续读说明](../cli/mineru-read.md#8-continuation) 和 [Doclib SDK](../sdk/doclib-client.md#parse-doc)。
+
parse read 返回示例:
```json
diff --git a/docs/next/sdk/doclib-client.md b/docs/next/sdk/doclib-client.md
index 1ff776b8..7fb2ffef 100644
--- a/docs/next/sdk/doclib-client.md
+++ b/docs/next/sdk/doclib-client.md
@@ -178,6 +178,16 @@ Markdown 响应中的 visual block 图片使用 `doc:.../page:.../block:...` loc
请求定位器的 `page:` 复用输入页范围语法:数字、`rN`、`1-5`、`r3-r1`、`1,3,r1`、`all`。`r1` 表示最后一页,`rN` 和 `all` 需要文档总页数;返回定位器及块引用使用实际页码。带 block/char、图片读取和非零 context 都要求选中单页。
+Markdown 文档定位或单点页定位在 `context=0` 时,页内截断的 `next_request` 同时携带文档 `locator` 和已消费位置 `after`。
+调用方应将这两个字段一起传给下一次 `read_content()`,从未完成的当前页继续读取。当前页完成后,服务继续建议下一页。
+块级 `after` 表示该块已完成,字符级 `after` 从对应偏移继续,页级 `after` 从下一页开始。
+
+```python
+result = client.read_content("doc:ab12cd3/tier:flash/page:1", limit=1000)
+if result.next_request is not None:
+ result = client.read_content(result.next_request.locator, after=result.next_request.after, limit=1000)
+```
+
范围读取结束后 `next_request=null`。范围内截断时,同时返回规范化 `locator` 和实际页码 `after`;两者可直接传给下一次 `read_content()`,不会读入未选择的页面:
```python
diff --git a/tests/unittest/test_doclib_read_continuation.py b/tests/unittest/test_doclib_read_continuation.py
index f07347ad..14d39481 100644
--- a/tests/unittest/test_doclib_read_continuation.py
+++ b/tests/unittest/test_doclib_read_continuation.py
@@ -29,12 +29,12 @@ async def _follow(
locator: str,
*,
limit: int,
+ after: str | None = None,
no_marker: bool = True,
cli_markers: bool = False,
) -> list[DocContentResponse]:
"""只使用服务返回的请求推进,不自行推测下一个块或下一页。"""
results: list[DocContentResponse] = []
- after = None
visited: set[tuple[str, str | None]] = set()
for _ in range(100):
state = (locator, after)
@@ -70,6 +70,7 @@ def test_locator_continuation_preserves_all_blocks(tmp_path: Path, suffix: str,
"""字符内、块间及页间截断后,原样续读必须不重、不漏地到达下一页。"""
async def run() -> None:
+ """通过真实缓存和服务核对当前场景的续读结果。"""
db, server = await _cached_library(
tmp_path, page_count=2, pages=[_page(0, "ALPHA", "BRAVO", "CHARLIE"), _page(1, "DELTA")]
)
@@ -82,6 +83,44 @@ def test_locator_continuation_preserves_all_blocks(tmp_path: Path, suffix: str,
asyncio.run(run())
+def test_default_budget_continuation_preserves_all_blocks(tmp_path: Path) -> None:
+ """默认三万字符预算截断长页面后,续读必须按顺序消费所有块且没有重复。"""
+
+ async def run() -> None:
+ """省略首个请求的 limit,原样回传其文档定位符和消费游标。"""
+ first_block = "A" * 12000
+ second_block = "B" * 12000
+ third_block = "C" * 12000
+ last_page = "D" * 10
+ db, server = await _cached_library(
+ tmp_path,
+ page_count=2,
+ pages=[_page(0, first_block, second_block, third_block), _page(1, last_page)],
+ )
+ try:
+ first = await server.read_content(f"{_DOC_REF}/page:1", no_marker=True)
+ assert first.request_scope.limit == 30000
+ assert first.truncated
+ assert first.next_request is not None
+ assert first.next_request.locator == _DOC_REF
+ assert first.next_request.after == f"{_DOC_REF}/page:1/block:2"
+ remaining = await _follow(
+ server,
+ first.next_request.locator,
+ after=first.next_request.after,
+ limit=30000,
+ )
+ assert [_body(result.content) for result in [first, *remaining]] == [
+ first_block + second_block,
+ third_block,
+ last_page,
+ ]
+ finally:
+ await db.close()
+
+ asyncio.run(run())
+
+
@pytest.mark.parametrize(
"suffix,expected",
[
@@ -97,6 +136,7 @@ def test_direct_block_continuation_does_not_expand_to_neighbours(
"""直接选择一个块时保留块内字符续读,不把同页相邻块纳入读取范围。"""
async def run() -> None:
+ """通过真实缓存和服务核对当前场景的续读结果。"""
db, server = await _cached_library(
tmp_path, page_count=2, pages=[_page(0, "ALPHA", "BRAVO", "CHARLIE"), _page(1, "DELTA")]
)
@@ -121,6 +161,7 @@ def test_document_after_preserves_page_turning(tmp_path: Path, suffix: str, expe
"""文档续读恢复游标所在页;页游标表示已完成该页,读完后保留下一页建议。"""
async def run() -> None:
+ """通过真实缓存和服务核对当前场景的续读结果。"""
db, server = await _cached_library(
tmp_path,
page_count=3,
@@ -149,6 +190,7 @@ def test_document_after_rejects_other_documents_and_tiers(tmp_path: Path, after:
"""文档级续读仍必须拒绝跨文档和跨档位游标。"""
async def run() -> None:
+ """通过真实缓存和服务核对当前场景的续读结果。"""
db, server = await _cached_library(tmp_path)
try:
with pytest.raises(InvalidRequestError) as error:
@@ -164,6 +206,7 @@ def test_locator_continuation_skips_empty_blocks_and_index_gaps(tmp_path: Path)
"""使用实际消费游标,不假定块号连续或每个块都可渲染。"""
async def run() -> None:
+ """通过空块和不连续块号检查实际消费游标。"""
page = _page(0, "ALPHA", " ", "CHARLIE")
page.blocks[-1].index = 7
db, server = await _cached_library(tmp_path, page_count=2, pages=[page, _page(1, "DELTA")])
@@ -181,6 +224,7 @@ def test_document_continuation_reaches_pages_after_default_window(tmp_path: Path
"""默认十页窗口之后仍能读到后续页面,且每页只出现一次。"""
async def run() -> None:
+ """通过真实缓存和服务核对当前场景的续读结果。"""
db, server = await _cached_library(tmp_path)
try:
results = await _follow(server, _DOC_REF, limit=limit)
@@ -197,6 +241,7 @@ def test_following_cli_markers_with_default_budget_preserves_content(tmp_path: P
"""CLI 续读命令不携带 --limit;恢复默认预算后仍不能遗漏同页剩余块。"""
async def run() -> None:
+ """通过真实缓存和服务核对当前场景的续读结果。"""
db, server = await _cached_library(
tmp_path, page_count=2, pages=[_page(0, "ALPHA", "BRAVO", "CHARLIE"), _page(1, "DELTA")]
)
@@ -213,6 +258,7 @@ def test_locator_continuation_http_round_trip(tmp_path: Path) -> None:
"""真实路由返回的续读请求可直接回传,不依赖调用者推测正确起点。"""
async def run() -> None:
+ """通过真实缓存和服务核对当前场景的续读结果。"""
db, server = await _cached_library(
tmp_path, page_count=2, pages=[_page(0, "ALPHA", "BRAVO", "CHARLIE"), _page(1, "DELTA")]
)