mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-09-09 05:28:50 +00:00
fix: don't flag outline as truncated at exactly MAX_OUTLINE_ENTRIES headings (#3856)
extract_outline appended the {truncated: True} sentinel as soon as len(outline) >= MAX_OUTLINE_ENTRIES, i.e. right after the 50th heading, before knowing whether a 51st exists. A document with exactly 50 headings was therefore reported as truncated, and uploads_middleware injected a misleading 'showing first 50 headings' hint into the agent's context. Use a lookahead: only mark truncated once a heading beyond the limit is actually seen, then drop that extra entry. Adds an exact-boundary regression test.
This commit is contained in:
parent
4fcb4bc366
commit
d9305989f3
@ -279,7 +279,11 @@ def extract_outline(md_path: Path) -> list[dict]:
|
|||||||
if title:
|
if title:
|
||||||
outline.append({"title": title, "line": lineno})
|
outline.append({"title": title, "line": lineno})
|
||||||
|
|
||||||
if len(outline) >= MAX_OUTLINE_ENTRIES:
|
if len(outline) > MAX_OUTLINE_ENTRIES:
|
||||||
|
# We collected one heading beyond the limit, which proves the
|
||||||
|
# document genuinely has more than MAX_OUTLINE_ENTRIES headings.
|
||||||
|
# Drop that extra entry and append the truncation sentinel.
|
||||||
|
outline.pop()
|
||||||
outline.append({"truncated": True})
|
outline.append({"truncated": True})
|
||||||
break
|
break
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
@ -422,6 +422,15 @@ class TestExtractOutline:
|
|||||||
assert len(outline) == 5
|
assert len(outline) == 5
|
||||||
assert not any(e.get("truncated") for e in outline)
|
assert not any(e.get("truncated") for e in outline)
|
||||||
|
|
||||||
|
def test_no_truncation_sentinel_at_exact_limit(self, tmp_path):
|
||||||
|
"""A document with exactly MAX_OUTLINE_ENTRIES headings is not truncated."""
|
||||||
|
lines = [f"# Heading {i}" for i in range(MAX_OUTLINE_ENTRIES)]
|
||||||
|
md = tmp_path / "exact.md"
|
||||||
|
md.write_text("\n".join(lines), encoding="utf-8")
|
||||||
|
outline = extract_outline(md)
|
||||||
|
assert len(outline) == MAX_OUTLINE_ENTRIES
|
||||||
|
assert not any(e.get("truncated") for e in outline)
|
||||||
|
|
||||||
def test_blank_lines_and_whitespace_ignored(self, tmp_path):
|
def test_blank_lines_and_whitespace_ignored(self, tmp_path):
|
||||||
"""Blank lines between headings do not produce empty entries."""
|
"""Blank lines between headings do not produce empty entries."""
|
||||||
md = tmp_path / "spaced.md"
|
md = tmp_path / "spaced.md"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user