Community sync: fix comment, identity and refusal bugs; add per-record sync ledger

Fixes found by investigating the live lobste.rs run:
- Comments came back 0: the learner probed the external article, not the
  discussion page. A comments_url field (RSS <comments>, JSON key, or an HTML
  "comments" anchor) now drives comment learning; the article is still used
  for the post body.
- HTML id selectors collapsed every story into one identity (constant /login
  vote link). Id/url selectors must now be distinct; no distinct selector
  rejects the feed.
- Over-long posts were rejected; title, post and comment are truncated to the
  sync limits and reported as a warning.
- A failed article fetch is a warning, not a run error.
- A gate refusal (sync disabled, origin not allowed, aliasing off) ends the run
  as skipped and no longer counts toward the failure floor.
- The same story from two feeds becomes one post, comments attached to it.
- HTML comments follow rel=next up to max_comment_pages.
- A dry run now predicts an unknown-record tombstone as unchanged, like a live
  run.
- /nodes is exempt from the happy-404 decoy so a missing download is a real 404.

Sync log (admin): every run stores a verdict, exact per-outcome counts and one
row per record needing an explanation, with the reason in plain words, at
/admin/communities/{slug}/ledger (HTML, JSON, Devii tool, docs entry).
Bounded: 2000 routine + 2000 problem rows per run, 50 per page, detail kept for
the 10 newest runs, four indexes matching every ORDER BY (asserted by an
EXPLAIN QUERY PLAN test). Measured worst case 37 ms at the 40000-row ceiling.

Also: privacy disclosure for imported community content, status colour channel
tokens, and tests/unit/cli/nodes.py renamed to fix a duplicate-basename
collection error.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-16 09:26:08 +02:00
co-authored by Claude Sonnet 5.5
parent 6f80a820da
commit 8d18994c2e
35 changed files with 1987 additions and 69 deletions
+15 -1
View File
@@ -7,7 +7,7 @@ import pytest
from devplacepy.database import get_setting, get_table, init_db, set_setting
from devplacepy.services.community.runner import CommunityRunner
from devplacepy.services.community.service import DRY_RUN_KEY, CommunityService
from devplacepy.services.community.spec import STATUS_FAILING, STATUS_READY
from devplacepy.services.community.spec import LIMITS, RUN_SKIPPED, STATUS_FAILING, STATUS_READY
from devplacepy.services.community.store import store
from tests.unit.services.community.fakes import FakeFetcher, json_community, no_sleep
@@ -79,3 +79,17 @@ def test_run_history_is_bounded(world):
for _ in range(35):
run_async(runner.run(store.get("forum-test"), dry_run=True, trigger="test"))
assert len(store.runs(row["uid"], limit=100)) == 30
def test_gate_refusal_skips_the_run_without_counting_a_failure(world):
_, runner = world
row = seed(runner)
set_setting("sync_enabled", "0")
for _ in range(LIMITS.max_failures + 1):
report = run_async(runner.run(store.get("forum-test"), dry_run=False, trigger="test"))
assert report.status == RUN_SKIPPED
final = store.get("forum-test")
assert final["status"] == STATUS_READY and final["enabled"]
assert final["failure_count"] == 0 and final["last_status"] == RUN_SKIPPED
assert final["next_run_at"] and get_table("sync_links").count(origin="forum.test") == 0
assert store.runs(row["uid"])[0]["status"] == RUN_SKIPPED