From d8abc20da430d3cfb228d47cea2d9b1e24b83523 Mon Sep 17 00:00:00 2001 From: swaploard Date: Sat, 4 Jul 2026 07:10:19 +0000 Subject: [PATCH 1/2] test: add edge case tests for embed expansion functionality --- tests/test_synapse.py | 100 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/tests/test_synapse.py b/tests/test_synapse.py index d54f83b..c57963a 100644 --- a/tests/test_synapse.py +++ b/tests/test_synapse.py @@ -370,8 +370,106 @@ def test_expand_missing_block_embed_completes_without_hang(tmp_path: Path) -> No assert "{{embed" not in expanded -# ── _strip_markdown_for_embedding tests (issue #44) ───────────────────── +class TestEmbedExpansionEdgeCases: + """Table-driven tests for embed expansion edge cases (cycles, missing targets, happy path).""" + + @pytest.fixture(scope="class") + def graph(self, tmp_path_factory: pytest.TempPathFactory) -> LogseqGraph: + vault = tmp_path_factory.mktemp("embed_edge_vault") + pages = vault / "pages" + pages.mkdir(parents=True) + + # Happy path page embed: A → B + (pages / "B.md").write_text("- Content from page B\n", encoding="utf-8") + (pages / "AEmbedsB.md").write_text( + "- Before {{embed [[B]]}} after\n", encoding="utf-8" + ) + + # Cycle detection: A ↔ B + (pages / "CycleA.md").write_text( + "- before {{embed [[CycleB]]}} after\n", encoding="utf-8" + ) + (pages / "CycleB.md").write_text( + "- inner {{embed [[CycleA]]}}\n", encoding="utf-8" + ) + + # Missing page target + (pages / "MissingPage.md").write_text( + "- x {{embed [[NoSuchPage]]}}\n", encoding="utf-8" + ) + + # Missing block target + missing_uuid = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" + (pages / "MissingBlock.md").write_text( + f"- {{{{embed (({missing_uuid}))}}}}\n", encoding="utf-8" + ) + + # Happy path block embed + block_uuid = "bbbbbbbb-cccc-cccc-cccc-dddddddddddd" + (pages / "BlockTarget.md").write_text( + f"- Secret transcluded line\n id:: {block_uuid}\n", encoding="utf-8" + ) + (pages / "BlockHost.md").write_text( + f"- Before {{{{embed (({block_uuid}))}}}} after\n", encoding="utf-8" + ) + + return LogseqGraph.load_directory(vault) + + @pytest.mark.parametrize( + ("page_title", "embed_page_chain", "expected", "unexpected"), + [ + ( + "AEmbedsB", + frozenset(), + ["Content from page B"], + ["{{embed [[B]]}}"], + ), + ( + "CycleA", + frozenset({"CycleA"}), + ["before inner after"], + ["before inner before"], + ), + ( + "MissingPage", + frozenset(), + ["x"], + ["{{embed [[NoSuchPage]]}}"], + ), + ( + "MissingBlock", + frozenset(), + [], + ["{{embed"], + ), + ( + "BlockHost", + frozenset(), + ["Secret transcluded line", "Before", "after"], + ["{{embed (("], + ), + ], + ) + def test_expand_macros_and_embeds_edge_cases( + self, + graph: LogseqGraph, + page_title: str, + embed_page_chain: frozenset[str], + expected: list[str], + unexpected: list[str], + ) -> None: + from logseq_matryca_parser.synapse import _expand_macros_and_embeds + + page = graph.pages[page_title] + text = page.root_nodes[0].content + expanded = _expand_macros_and_embeds( + text, graph, set(), embed_page_chain=embed_page_chain + ) + for sub in expected: + assert sub in expanded, f"Expected {sub!r} in {expanded!r}" + for sub in unexpected: + assert sub not in expanded, f"Found unexpected {sub!r} in {expanded!r}" class TestStripMarkdownForEmbedding: """Table-driven tests for ``_strip_markdown_for_embedding()`` cleaner.""" From 6d244baee0a138c2aafd46a111b3fe7369692152 Mon Sep 17 00:00:00 2001 From: swaploard Date: Sat, 4 Jul 2026 07:23:12 +0000 Subject: [PATCH 2/2] docs: update CHANGELOG.md with Synapse RAG example and embed expansion edge-case tests --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12237d8..f3400ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- **Synapse RAG example** — [`examples/run_synapse_rag.py`](examples/run_synapse_rag.py) demonstrates all four `SynapseAdapter` methods (`to_langchain_documents`, `to_llamaindex_nodes`, `to_context_enriched_chunks`, `_expand_macros_and_embeds`) plus table-driven embed expansion edge cases. +- **Embed expansion edge-case tests** — `TestEmbedExpansionEdgeCases` in [`tests/test_synapse.py`](tests/test_synapse.py) covers cycles, missing targets, and happy-path for both `{{embed [[Page]]}}` and `{{embed ((uuid))}}` (closes [#71](https://github.com/MarcoPorcellato/logseq-matryca-parser/issues/71)). + ### Changed - **Ghost Tooling** — removed remaining vendor indexer blocks from `AGENTS.md` / `CLAUDE.md`; maintainer guidance now uses **audit code** terminology only.