dzen.nstarikov.ru/docs/superpowers/plans/2026-08-11-rss-title-deduplication.md
nstarikov f3a557cf17
Some checks failed
Deploy Dzen assistant / deploy (push) Failing after 22s
chore: make dzen assistant repository root
2026-08-15 14:21:59 +03:00

4.1 KiB

RSS Title Deduplication Implementation Plan

For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (- [ ]) syntax for tracking.

Goal: Keep each Dzen article title in the RSS <title> metadata while removing the feed-generated duplicate <h1> from content:encoded.

Architecture: Keep the existing render_article_html(..., rss_safe=True) pipeline as the sole producer of the RSS article body. Add one focused integration-style unit test using an in-memory SQLite database to exercise the real feed query and inspect the generated XML.

Tech Stack: Python 3, SQLAlchemy, unittest, xml.etree.ElementTree


Task 1: Remove the generated RSS body heading

Files:

  • Create: tests/test_rss.py

  • Modify: app/rss.py:204

  • Step 1: Write the failing regression test

Create tests/test_rss.py:

import unittest
from datetime import datetime, timedelta, timezone
from xml.etree import ElementTree

from sqlalchemy import create_engine
from sqlalchemy.orm import Session

from app.config import Settings
from app.database import Base
from app.models import Article
from app.rss import build_feed_xml


class RssFeedTest(unittest.TestCase):
    def test_article_title_is_metadata_only_not_generated_body_heading(self):
        engine = create_engine("sqlite:///:memory:")
        Base.metadata.create_all(engine)
        article = Article(
            slug="test-article",
            title="Тестовый заголовок",
            lead="<p>Тестовый лид.</p>",
            body_html="<p>Основной текст.</p>",
            cta_html="",
            feature_image_url="",
            status="published",
            rss_guid="test-guid",
            published_at=datetime.now(timezone.utc) - timedelta(minutes=1),
        )

        with Session(engine) as session:
            session.add(article)
            session.commit()
            xml = build_feed_xml(session, Settings(public_base_url="https://example.test"))

        root = ElementTree.fromstring(xml)
        item = root.find("./channel/item")
        self.assertIsNotNone(item)
        self.assertEqual(item.findtext("title"), "Тестовый заголовок")
        content = item.findtext("{http://purl.org/rss/1.0/modules/content/}encoded") or ""
        self.assertNotIn("<h1>Тестовый заголовок</h1>", content)
        self.assertIn("<p>Тестовый лид.</p>", content)
        self.assertIn("<p>Основной текст.</p>", content)


if __name__ == "__main__":
    unittest.main()
  • Step 2: Run the focused test and verify the current behavior fails

Run:

docker run --rm \
  -e PYTHONPYCACHEPREFIX=/tmp/pycache \
  -v "$PWD:/workspace:ro" \
  -w /workspace \
  dzen-assistant-test:local \
  python -m unittest tests.test_rss -v

Expected: one failure because content:encoded contains <h1>Тестовый заголовок</h1>.

  • Step 3: Use the existing renderer as the complete RSS body

In app/rss.py, replace the body construction inside build_feed_xml with:

content = render_article_html(article, rss_safe=True)

Do not change the item <title>, cover caption, description, or article page renderer.

  • Step 4: Run the focused test and verify it passes

Run the command from Step 2.

Expected: Ran 1 test followed by OK.

  • Step 5: Run the backend regression suite and compilation

Run:

docker run --rm \
  -e PYTHONPYCACHEPREFIX=/tmp/pycache \
  -v "$PWD:/workspace:ro" \
  -w /workspace \
  dzen-assistant-test:local \
  python -m unittest discover -s tests -v

docker run --rm \
  -e PYTHONPYCACHEPREFIX=/tmp/pycache \
  -v "$PWD:/workspace:ro" \
  -w /workspace \
  dzen-assistant-test:local \
  python -m compileall -q app tests

Expected: all tests pass and compilation exits with status 0.

  • Step 6: Commit the implementation
git add app/rss.py tests/test_rss.py
git commit -m "fix: avoid duplicate article titles in RSS bodies"