fix(wiki): pass chunks explicitly to compile_concept (single retrieve)
compile_concept now accepts chunks as a positional parameter; compile_all retrieves chunks once and passes them directly, avoiding double-retrieve. Also separates all_concepts (full list) from compile_concepts (filtered), so cross-ref injection always uses the complete concept list regardless of --concept filter (Fix 6 + Fix 8). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -259,7 +259,9 @@ def test_compile_concept_returns_concept_page(
|
||||
) -> None:
|
||||
"""compile_concept returns a ConceptPage with non-empty markdown."""
|
||||
llm = MockLLM(GROUNDED_LLM_OUTPUT)
|
||||
page = compile_concept(FIXTURE_CONCEPT, top_k=6, llm=llm, wiki_dir=mock_settings)
|
||||
page = compile_concept(
|
||||
FIXTURE_CONCEPT, FIXTURE_CHUNKS, top_k=6, llm=llm, wiki_dir=mock_settings
|
||||
)
|
||||
assert isinstance(page, ConceptPage)
|
||||
assert page.concept.slug == "lobachevsky-function"
|
||||
assert len(page.markdown) > 0
|
||||
@@ -272,7 +274,9 @@ def test_compile_concept_has_chunk_hash(
|
||||
) -> None:
|
||||
"""Compiled page has a non-empty chunk_hash."""
|
||||
llm = MockLLM(GROUNDED_LLM_OUTPUT)
|
||||
page = compile_concept(FIXTURE_CONCEPT, top_k=6, llm=llm, wiki_dir=mock_settings)
|
||||
page = compile_concept(
|
||||
FIXTURE_CONCEPT, FIXTURE_CHUNKS, top_k=6, llm=llm, wiki_dir=mock_settings
|
||||
)
|
||||
assert len(page.chunk_hash) == 64 # SHA-256 hex
|
||||
|
||||
|
||||
@@ -283,7 +287,9 @@ def test_compile_concept_grounded_claim_not_flagged(
|
||||
) -> None:
|
||||
"""A grounded claim does NOT receive the ⚠ marker in the output markdown."""
|
||||
llm = MockLLM(GROUNDED_LLM_OUTPUT)
|
||||
page = compile_concept(FIXTURE_CONCEPT, top_k=6, llm=llm, wiki_dir=mock_settings)
|
||||
page = compile_concept(
|
||||
FIXTURE_CONCEPT, FIXTURE_CHUNKS, top_k=6, llm=llm, wiki_dir=mock_settings
|
||||
)
|
||||
# When all claims are grounded, no ⚠ in markdown
|
||||
# (may still have 0 ⚠ if claims found; just check no false positive for grounded)
|
||||
grounded = [c for c in page.claims if c.grounded]
|
||||
@@ -298,7 +304,9 @@ def test_compile_concept_ungrounded_claim_marked(
|
||||
) -> None:
|
||||
"""An ungrounded claim is marked ⚠ in the page markdown."""
|
||||
llm = MockLLM(UNGROUNDED_LLM_OUTPUT)
|
||||
page = compile_concept(FIXTURE_CONCEPT, top_k=6, llm=llm, wiki_dir=mock_settings)
|
||||
page = compile_concept(
|
||||
FIXTURE_CONCEPT, FIXTURE_CHUNKS, top_k=6, llm=llm, wiki_dir=mock_settings
|
||||
)
|
||||
ungrounded = [c for c in page.claims if not c.grounded]
|
||||
if ungrounded:
|
||||
assert "⚠" in page.markdown
|
||||
@@ -311,7 +319,9 @@ def test_compile_concept_header_present(
|
||||
) -> None:
|
||||
"""Page markdown starts with an H1 header for the concept title."""
|
||||
llm = MockLLM(GROUNDED_LLM_OUTPUT)
|
||||
page = compile_concept(FIXTURE_CONCEPT, top_k=6, llm=llm, wiki_dir=mock_settings)
|
||||
page = compile_concept(
|
||||
FIXTURE_CONCEPT, FIXTURE_CHUNKS, top_k=6, llm=llm, wiki_dir=mock_settings
|
||||
)
|
||||
assert page.markdown.startswith("# Lobachevsky Function")
|
||||
|
||||
|
||||
@@ -434,10 +444,12 @@ def test_idempotent_no_rewrite_when_unchanged(
|
||||
call_count = 0
|
||||
original_compile = compile_concept
|
||||
|
||||
def counting_compile(concept: Concept, **kwargs: Any) -> ConceptPage:
|
||||
def counting_compile(
|
||||
concept: Concept, chunks: list[Any], **kwargs: Any
|
||||
) -> ConceptPage:
|
||||
nonlocal call_count
|
||||
call_count += 1
|
||||
return original_compile(concept, **kwargs)
|
||||
return original_compile(concept, chunks, **kwargs)
|
||||
|
||||
monkeypatch.setattr("codex.wiki.compile_concept", counting_compile)
|
||||
|
||||
@@ -478,10 +490,12 @@ def test_force_all_recompiles_even_when_unchanged(
|
||||
call_count = 0
|
||||
original_compile = compile_concept
|
||||
|
||||
def counting_compile(concept: Concept, **kwargs: Any) -> ConceptPage:
|
||||
def counting_compile(
|
||||
concept: Concept, chunks: list[Any], **kwargs: Any
|
||||
) -> ConceptPage:
|
||||
nonlocal call_count
|
||||
call_count += 1
|
||||
return original_compile(concept, **kwargs)
|
||||
return original_compile(concept, chunks, **kwargs)
|
||||
|
||||
monkeypatch.setattr("codex.wiki.compile_concept", counting_compile)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user