66
77import fastmcp_autodoc
88import pytest
9+ from docutils import nodes
910
1011# ---------------------------------------------------------------------------
1112# _parse_numpy_params
@@ -455,25 +456,31 @@ def test_section_badge_map_headings() -> None:
455456 assert m ["Destroy" ] == "destructive"
456457
457458
458- def test_add_section_badges_appends_badge_to_title () -> None :
459- """_add_section_badges appends a safety badge to matching titles."""
459+ def _make_doc_with_section (
460+ section_id : str , title_text : str
461+ ) -> tuple [nodes .document , nodes .section , nodes .title ]:
462+ """Build a minimal doctree with one section."""
460463 from docutils import nodes
461464 from docutils .frontend import OptionParser
462465 from docutils .utils import new_document
463466
464467 settings = OptionParser (components = ()).get_default_values ()
465468 doc = new_document ("test" , settings )
466-
467- section = nodes .section (ids = ["inspect" ])
468- title = nodes .title ("" , "Inspect" )
469+ section = nodes .section (ids = [section_id ])
470+ title = nodes .title ("" , title_text )
469471 section += title
470472 doc += section
473+ return doc , section , title
474+
475+
476+ def test_add_section_badges_appends_badge_on_tools_index () -> None :
477+ """_add_section_badges appends badge when fromdocname is tools/index."""
478+ from docutils import nodes
471479
472- # Simulate the handler — it expects (app, doctree, fromdocname )
473- # but only uses doctree, so pass None for the others.
474- fastmcp_autodoc ._add_section_badges (None , doc , "" )
480+ doc , _section , title = _make_doc_with_section ( "inspect" , "Inspect" )
481+
482+ fastmcp_autodoc ._add_section_badges (None , doc , "tools/index " )
475483
476- # Title should now have 3 children: Text("Inspect"), Text(" "), inline(badge)
477484 assert len (title .children ) == 3
478485 badge = title .children [2 ]
479486 assert isinstance (badge , nodes .inline )
@@ -483,39 +490,29 @@ def test_add_section_badges_appends_badge_to_title() -> None:
483490
484491def test_add_section_badges_preserves_section_id () -> None :
485492 """_add_section_badges does not change the section ID."""
486- from docutils import nodes
487- from docutils .frontend import OptionParser
488- from docutils .utils import new_document
493+ doc , section , _title = _make_doc_with_section ("inspect" , "Inspect" )
489494
490- settings = OptionParser (components = ()).get_default_values ()
491- doc = new_document ("test" , settings )
495+ fastmcp_autodoc ._add_section_badges (None , doc , "tools/index" )
492496
493- section = nodes .section (ids = ["inspect" ])
494- section += nodes .title ("" , "Inspect" )
495- doc += section
497+ assert section ["ids" ] == ["inspect" ]
496498
497- fastmcp_autodoc ._add_section_badges (None , doc , "" )
498499
499- assert section ["ids" ] == ["inspect" ]
500+ def test_add_section_badges_skips_non_index_pages () -> None :
501+ """_add_section_badges skips individual tool pages (redundant)."""
502+ doc , _section , title = _make_doc_with_section ("inspect" , "Inspect" )
500503
504+ fastmcp_autodoc ._add_section_badges (None , doc , "tools/sessions" )
501505
502- def test_add_section_badges_ignores_non_matching () -> None :
503- """_add_section_badges leaves non-matching headings untouched."""
504- from docutils import nodes
505- from docutils .frontend import OptionParser
506- from docutils .utils import new_document
506+ assert len (title .children ) == 1
507+ assert title .astext () == "Inspect"
507508
508- settings = OptionParser (components = ()).get_default_values ()
509- doc = new_document ("test" , settings )
510509
511- section = nodes .section (ids = ["overview" ])
512- title = nodes .title ("" , "Overview" )
513- section += title
514- doc += section
510+ def test_add_section_badges_ignores_non_matching () -> None :
511+ """_add_section_badges leaves non-matching headings untouched."""
512+ doc , _section , title = _make_doc_with_section ("overview" , "Overview" )
515513
516- fastmcp_autodoc ._add_section_badges (None , doc , "" )
514+ fastmcp_autodoc ._add_section_badges (None , doc , "tools/index " )
517515
518- # Title should still have only the original text child
519516 assert len (title .children ) == 1
520517 assert title .astext () == "Overview"
521518
0 commit comments