fix(blog): acquitter les GUID apres livraison XMPP
This commit is contained in:
@@ -1040,6 +1040,110 @@ def test_runner_blog_success_delivers_articles_into_xmpp_message_external_info(
|
||||
assert xmpp_message.external_info.blog_articles[0].title == "Test Article"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("channel_kind", "dry_run", "should_acknowledge"),
|
||||
[
|
||||
("success", False, True),
|
||||
("false", False, False),
|
||||
("exception", False, False),
|
||||
("none", False, False),
|
||||
("success", True, False),
|
||||
],
|
||||
)
|
||||
def test_runner_acknowledges_blog_only_after_confirmed_xmpp_delivery(
|
||||
pipeline_inputs: tuple[Lesson, Homework],
|
||||
tmp_path: Any,
|
||||
channel_kind: str,
|
||||
dry_run: bool,
|
||||
should_acknowledge: bool,
|
||||
) -> None:
|
||||
"""Les GUID RSS restent rejouables tant que XMPP n'a pas confirmé l'envoi.
|
||||
|
||||
:param pipeline_inputs: Données Pronote de test.
|
||||
:param tmp_path: Répertoire temporaire pour l'état RSS.
|
||||
:param channel_kind: Comportement du canal XMPP simulé.
|
||||
:param dry_run: Active ou non le mode simulation.
|
||||
:param should_acknowledge: Indique si l'état RSS doit être acquitté.
|
||||
"""
|
||||
lesson, homework = pipeline_inputs
|
||||
calls: list[str] = []
|
||||
state_file = tmp_path / "blog-state.json"
|
||||
|
||||
class SuccessfulBlogClient:
|
||||
"""Client RSS renvoyant un article non encore livré."""
|
||||
|
||||
def fetch_and_parse(
|
||||
self,
|
||||
*,
|
||||
known_guids: frozenset[str] | None = None,
|
||||
etag: str | None = None,
|
||||
last_modified: str | None = None,
|
||||
) -> BlogRSSFetchResult:
|
||||
"""Retourne un article et des en-têtes de cache déterministes.
|
||||
|
||||
:param known_guids: GUID déjà connus, ignorés dans ce faux client.
|
||||
:param etag: ETag mémorisé, ignoré dans ce faux client.
|
||||
:param last_modified: Date HTTP mémorisée, ignorée dans ce faux client.
|
||||
:return: Résultat RSS avec un article à livrer.
|
||||
:rtype: BlogRSSFetchResult
|
||||
"""
|
||||
del known_guids, etag, last_modified
|
||||
return BlogRSSFetchResult(
|
||||
articles=(
|
||||
BlogArticle(
|
||||
id="article-to-deliver",
|
||||
title="Article à livrer",
|
||||
url="https://example.com/article-to-deliver",
|
||||
published_at=datetime(2026, 9, 8, 12, 0),
|
||||
updated_at=None,
|
||||
category=None,
|
||||
author=None,
|
||||
content_html="<p>Contenu</p>",
|
||||
content_text="Contenu",
|
||||
),
|
||||
),
|
||||
etag="etag-after-delivery",
|
||||
last_modified="Tue, 08 Sep 2026 12:00:00 GMT",
|
||||
)
|
||||
|
||||
channel: Any
|
||||
if channel_kind == "success":
|
||||
channel = StubChannel(calls)
|
||||
elif channel_kind == "false":
|
||||
channel = FailingChannel()
|
||||
elif channel_kind == "exception":
|
||||
channel = ExceptionalChannel()
|
||||
else:
|
||||
channel = None
|
||||
|
||||
runner = PipelineRunner(
|
||||
settings=Settings(blog=Settings().blog.model_copy(update={"enabled": True})),
|
||||
pronote_fetcher=StubFetcher(calls, lesson, homework),
|
||||
caldav_synchronizer=lambda data, settings: successful_sync_result(),
|
||||
agenda_comparator=cast("AgendaComparator | None", StubComparator(calls)),
|
||||
blog_client=cast("BlogRSSClient | None", SuccessfulBlogClient()),
|
||||
blog_state=BlogRSSState(state_file),
|
||||
channel=channel,
|
||||
dry_run=dry_run,
|
||||
now_provider=lambda: datetime(2026, 9, 8, 7, 0),
|
||||
)
|
||||
|
||||
data, errors = runner.run()
|
||||
|
||||
assert data is not None
|
||||
if should_acknowledge:
|
||||
acknowledged_state = BlogRSSState(state_file)
|
||||
assert acknowledged_state.get_known_guids() == frozenset({"article-to-deliver"})
|
||||
assert acknowledged_state.get_cache_headers() == (
|
||||
"etag-after-delivery",
|
||||
"Tue, 08 Sep 2026 12:00:00 GMT",
|
||||
)
|
||||
else:
|
||||
assert not state_file.exists()
|
||||
if channel_kind in {"false", "exception"}:
|
||||
assert any(error.step == "send" for error in errors)
|
||||
|
||||
|
||||
def test_runner_secret_redaction_in_pipeline_errors(
|
||||
pipeline_inputs: tuple[Lesson, Homework],
|
||||
) -> None:
|
||||
|
||||
@@ -14,11 +14,14 @@ Tous les tests utilisent des fichiers temporaires via la fixture ``tmp_path``.
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from pronote_sync.models.blog import BlogArticle
|
||||
from pronote_sync.sources.blog.result import BlogRSSFetchResult
|
||||
from pronote_sync.sources.blog.state import BlogRSSState
|
||||
|
||||
|
||||
@@ -116,6 +119,38 @@ def test_add_guids_empty_noop(tmp_path: Path) -> None:
|
||||
assert state_file.read_text(encoding="utf-8") == original_content
|
||||
|
||||
|
||||
def test_acknowledge_persists_guids_and_cache_headers_together(tmp_path: Path) -> None:
|
||||
"""Vérifie l'acquittement atomique après une livraison confirmée.
|
||||
|
||||
:param tmp_path: Fixture pytest pour un répertoire temporaire.
|
||||
:return: None
|
||||
"""
|
||||
state_file = tmp_path / "state.json"
|
||||
state = BlogRSSState(state_file)
|
||||
article = BlogArticle(
|
||||
id="guid-1",
|
||||
title="Article",
|
||||
url="https://example.com/article",
|
||||
published_at=datetime(2026, 9, 12, 8, 0, tzinfo=UTC),
|
||||
updated_at=None,
|
||||
category=None,
|
||||
author=None,
|
||||
content_html="<p>Contenu</p>",
|
||||
content_text="Contenu",
|
||||
)
|
||||
|
||||
state.acknowledge(
|
||||
BlogRSSFetchResult(
|
||||
articles=(article,),
|
||||
etag="etag-1",
|
||||
last_modified="Sat, 12 Sep 2026 08:00:00 GMT",
|
||||
)
|
||||
)
|
||||
|
||||
assert state.get_known_guids() == frozenset({"guid-1"})
|
||||
assert state.get_cache_headers() == ("etag-1", "Sat, 12 Sep 2026 08:00:00 GMT")
|
||||
|
||||
|
||||
def test_state_load_persisted_guids(tmp_path: Path) -> None:
|
||||
"""Vérifie que les GUID persistés sont rechargés dans une nouvelle instance.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user