|
18 | 18 |
|
19 | 19 | from __future__ import annotations |
20 | 20 |
|
| 21 | +import asyncio |
21 | 22 | import json |
22 | 23 | from pathlib import Path |
23 | 24 | from unittest.mock import AsyncMock, patch |
24 | 25 |
|
25 | 26 | from click.testing import CliRunner |
26 | 27 |
|
| 28 | +from openkb.agent import compiler |
27 | 29 | from openkb.cli import cli |
28 | 30 | from openkb.schema import AGENTS_MD |
29 | 31 |
|
@@ -312,3 +314,32 @@ def test_recompile_refresh_schema_noop_when_agents_missing(kb_dir): |
312 | 314 | assert result.exit_code == 0, result.output |
313 | 315 | assert not agents.exists() # not materialized |
314 | 316 | assert not (kb_dir / "wiki" / "AGENTS.md.bak").exists() |
| 317 | + |
| 318 | + |
| 319 | +# --------------------------------------------------------------------------- |
| 320 | +# compile_long_doc backfills type + description on recompile |
| 321 | +# --------------------------------------------------------------------------- |
| 322 | + |
| 323 | + |
| 324 | +def test_compile_long_doc_backfills_summary_frontmatter(tmp_path): |
| 325 | + wiki = tmp_path / "wiki" |
| 326 | + (wiki / "summaries").mkdir(parents=True) |
| 327 | + (wiki / "concepts").mkdir(parents=True) |
| 328 | + (tmp_path / ".openkb").mkdir() |
| 329 | + (tmp_path / ".openkb" / "config.yaml").write_text( |
| 330 | + "model: gpt-4o-mini\nlanguage: en\n", encoding="utf-8") |
| 331 | + summary_path = wiki / "summaries" / "long.md" |
| 332 | + summary_path.write_text( |
| 333 | + "---\ndoc_type: pageindex\nfull_text: sources/long.json\n---\n\n# Long\n", |
| 334 | + encoding="utf-8", |
| 335 | + ) |
| 336 | + with patch.object(compiler, "_llm_call", return_value="overview"), \ |
| 337 | + patch.object(compiler, "_compile_concepts", new=AsyncMock()), \ |
| 338 | + patch.object(compiler, "_close_async_llm_clients", new=AsyncMock()): |
| 339 | + asyncio.run(compiler.compile_long_doc( |
| 340 | + "long", summary_path, "doc-1", tmp_path, "gpt-4o-mini", |
| 341 | + doc_description="A long report.", |
| 342 | + )) |
| 343 | + text = summary_path.read_text(encoding="utf-8") |
| 344 | + assert 'type: "Summary"' in text |
| 345 | + assert 'description: "A long report."' in text |
0 commit comments