Skip to content

refactor(synapse): extract embed-expansion strategy (OCP) from monolithic loop #70

Description

@MarcoPorcellato

Problem

_expand_macros_and_embeds_impl is a single while True loop handling block embeds, page embeds, cycle detection, and graph lookups. Each new embed type (macro, query, PDF) requires editing the core loop — Open/Closed Principle violation noted in docs/BUG_HUNT_REPORT.md §6.

Clean Architecture lens

Aspect Assessment
Ring Interface Adapter (synapse.py)
SOLID OCP + SRP — one class/function per embed kind
Dependency rule Strategies depend on LogseqGraph port, not KINETIC/CLI

Proposed Solution (incremental)

  1. Define a small EmbedExpander protocol: match(text) -> span | None, expand(...) -> str
  2. Implement BlockEmbedExpander, PageEmbedExpander with shared cycle context object
  3. Keep _expand_macros_and_embeds as façade delegating to ordered strategies
  4. Fix cycle duplication (#65) inside page strategy

Mentor scope

~4–6 hours. Good follow-up after #65 tests land.

Definition of Done

  • No behavior regression (tests/test_synapse.py)
  • make all passes

Metadata

Metadata

Assignees

No one assigned

    Labels

    architectureLayer boundaries, dependency rule, structural refactorclean-codeClean Architecture / SOLID slice — Uncle Bob contractenhancementNew feature or requesthelp wantedExtra attention or skill is welcome

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions