Files
DeepTutor/tests/book/test_visual_block_prompts.py
Bingxi Zhao (Frank) 96d6df9eb1 release: v1.5.13
Book is the bulk of this one. Compilation outlives the request that
started it, so a bus owned by that request dropped every background event
and "watch your book being written" degraded into a frozen page; the
stream is now owned per book by the process and survives a refresh or a
reconnect. Reading progress is finally recorded — `visited_page_ids` and
`bookmarked_page_ids` had been declared but never written for the life of
the feature — and rolls up into a completion score and weak chapters. A
book can also leave the app now, as one self-contained Markdown document,
with non-ASCII titles surviving the download.

Two scheduling defects that were invisible in production are fixed: the
same page compiled twice concurrently (billed twice, one result
discarded), and a book grinding on through a provider outage until every
chapter was half-generated. The source sweep is bounded and allocated
round-robin rather than spent on the first few knowledge bases, and
retrieval now tells indexed bases from connected pointers, so an Obsidian
vault or a remote IMA library no longer contributes zero while looking
like a source with nothing relevant. Confirming a spine shows a live
per-chapter estimate derived from the Section Architect's own templates.

Also here: three home starter suggestions built from memory recall,
mastery-path handoff moved into one module that changes lease, session
preference, and live turn together, and account-level Tencent IMA
credentials with the per-KB pair still winning.

Notes: assets/releases/ver1-5-13.md

This commit also carries the README prose sync, the eleven translated
READMEs, the release-notes archive sweep, and the version bump. Two gate
fixes ride along: the `Stamped` protocol is declared read-only so the
frozen `EntityStamp` satisfies it, and six GraphRAG adapter tests that
reached a deep `graphrag` import without guarding it now skip like their
four neighbours instead of failing where the extra is not installed.
2026-08-17 11:22:26 +08:00

64 lines
2.6 KiB
Python

"""The visual blocks must take their brief from YAML, like every other block.
figure / interactive / animation used to build their prompt in Python with
English f-strings, so a Chinese book asked the shared visualize pipeline for a
figure in English — the one part of the book whose prompt ignored the book's
language. These check both that the prompts exist for every block/language pair
and that they interpolate without spacing artefacts in either direction.
"""
from __future__ import annotations
import pytest
from deeptutor.book.blocks._prompts import get_book_prompt, load_book_prompts
VISUAL_BLOCKS = ("figure", "interactive", "animation")
LANGUAGES = ("en", "zh")
# Every placeholder any of the three briefs might use.
FILLERS = {
"chapter_title": "Matrix factorisation",
"variant": "schematic",
"interaction": "explorable",
}
@pytest.mark.parametrize("block", VISUAL_BLOCKS)
@pytest.mark.parametrize("language", LANGUAGES)
def test_every_visual_block_has_a_brief_in_every_language(block: str, language: str) -> None:
prompts = load_book_prompts(block, language)
for key in ("brief", "focus_clause", "context_summary", "context_objectives"):
assert get_book_prompt(prompts, key).strip(), f"{block}/{language} missing {key}"
@pytest.mark.parametrize("block", VISUAL_BLOCKS)
@pytest.mark.parametrize("language", LANGUAGES)
def test_the_brief_renders_with_and_without_a_focus(block: str, language: str) -> None:
prompts = load_book_prompts(block, language)
brief = get_book_prompt(prompts, "brief").strip()
focused = brief.format(
**FILLERS,
focus_clause=get_book_prompt(prompts, "focus_clause").rstrip().format(focus="SVD"),
)
assert "SVD" in focused
assert "{" not in focused, "an unfilled placeholder survived"
assert " " not in focused, "double space — the focus clause spacing is off"
unfocused = brief.format(**FILLERS, focus_clause="")
assert "{" not in unfocused
assert " " not in unfocused, "empty focus clause left a dangling space"
def test_the_english_focus_clause_keeps_its_leading_space() -> None:
"""A YAML block scalar would strip it; the file uses a quoted scalar."""
clause = get_book_prompt(load_book_prompts("figure", "en"), "focus_clause")
assert clause.startswith(" "), "English clause must separate itself from the title"
def test_a_chinese_book_gets_a_chinese_brief() -> None:
zh = get_book_prompt(load_book_prompts("figure", "zh"), "brief")
assert any("一" <= ch <= "鿿" for ch in zh), "expected Chinese text"
assert "figure for the chapter" not in zh