2026-06-19 00:09:34 +02:00
|
|
|
# retoor <retoor@molodetz.nl>
|
|
|
|
|
|
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
|
from uuid import uuid4
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
from starlette.testclient import TestClient
|
|
|
|
|
|
|
|
|
|
import devplacepy.main as m
|
|
|
|
|
from devplacepy.database import get_table, init_db, set_setting
|
|
|
|
|
from devplacepy.services.gitea import runtime, store
|
|
|
|
|
from devplacepy.services.gitea.fake import FakeGiteaClient
|
|
|
|
|
from devplacepy.utils import create_session, make_combined_slug
|
|
|
|
|
from tests.conftest import run_async
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
|
def _init_db_components_title():
|
|
|
|
|
init_db()
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _client():
|
|
|
|
|
return TestClient(m.app)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _owner():
|
|
|
|
|
uid = f"dptitle-{uuid4().hex[:10]}"
|
|
|
|
|
get_table("users").insert(
|
|
|
|
|
{
|
|
|
|
|
"uid": uid,
|
|
|
|
|
"username": f"dpt_{uid[-6:]}",
|
Add the trust and safety subsystem and the App Store compliance work
Implements the moderation and consent obligations a social platform carries,
so the web version and any client that speaks to it enforce the same rules.
Moderation core (services/moderation/, database/moderation.py): a reportable
target registry, the content filter and its choke points, the report queue with
atomic resolution, enforcement actions, consent tracking, maturity gating, and
account deletion with a grace window.
Surfaces: POST /reports plus the member report list, /admin/moderation and the
per-report admin view, /workspaces, terms acceptance at /auth/terms, consent and
account deletion under /profile, the report button and dialog partials, the
maturity gate, and the moderation stylesheet and ReportDialog client.
Every user-generated surface stays reportable by construction: new content tables
are registered in REPORTABLE_TARGETS or listed in UNREPORTABLE_TABLES with a
reason, and the registry test fails the suite on anything left unclassified.
Docs: community guidelines, content moderation, intellectual property, privacy,
terms, contact, and the admin-only moderation operations page, plus the
moderation API group and the Devii moderation actions.
Compliance record: applecomp.md is the requirement register, applechanges.md the
gap analysis against this codebase, and appleimpl.md the implementation design
they resolve to.
Tests cover the report flow, admin moderation, consent, account deletion, terms
acceptance, workspaces, and the registry invariant across the unit, api, and e2e
tiers.
2026-08-09 00:18:20 +02:00
|
|
|
"terms_version": "1",
|
2026-06-19 00:09:34 +02:00
|
|
|
"email": f"{uid[-6:]}@title.test",
|
|
|
|
|
"password_hash": "x",
|
|
|
|
|
"role": "Member",
|
|
|
|
|
"is_active": True,
|
|
|
|
|
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
return uid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _seed_post(title):
|
|
|
|
|
owner = _owner()
|
|
|
|
|
uid = str(uuid4())
|
|
|
|
|
slug = make_combined_slug(title, uid)
|
|
|
|
|
get_table("posts").insert(
|
|
|
|
|
{
|
|
|
|
|
"deleted_at": None,
|
|
|
|
|
"deleted_by": None,
|
|
|
|
|
"uid": uid,
|
|
|
|
|
"user_uid": owner,
|
|
|
|
|
"slug": slug,
|
|
|
|
|
"title": title,
|
|
|
|
|
"content": "Body text for the dp-title post.",
|
|
|
|
|
"topic": "general",
|
|
|
|
|
"project_uid": None,
|
|
|
|
|
"image": None,
|
|
|
|
|
"stars": 0,
|
|
|
|
|
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
return slug
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _seed_project(title):
|
|
|
|
|
owner = _owner()
|
|
|
|
|
uid = str(uuid4())
|
|
|
|
|
slug = make_combined_slug(title, uid)
|
|
|
|
|
get_table("projects").insert(
|
|
|
|
|
{
|
|
|
|
|
"deleted_at": None,
|
|
|
|
|
"deleted_by": None,
|
|
|
|
|
"uid": uid,
|
|
|
|
|
"user_uid": owner,
|
|
|
|
|
"slug": slug,
|
|
|
|
|
"title": title,
|
|
|
|
|
"description": "Project description for the dp-title test.",
|
|
|
|
|
"project_type": "software",
|
|
|
|
|
"platforms": "Linux",
|
|
|
|
|
"status": "Released",
|
|
|
|
|
"stars": 0,
|
|
|
|
|
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
return slug
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _seed_gist(title):
|
|
|
|
|
owner = _owner()
|
|
|
|
|
uid = str(uuid4())
|
|
|
|
|
slug = make_combined_slug(title, uid)
|
|
|
|
|
get_table("gists").insert(
|
|
|
|
|
{
|
|
|
|
|
"deleted_at": None,
|
|
|
|
|
"deleted_by": None,
|
|
|
|
|
"uid": uid,
|
|
|
|
|
"user_uid": owner,
|
|
|
|
|
"slug": slug,
|
|
|
|
|
"title": title,
|
|
|
|
|
"description": "Gist description for the dp-title test.",
|
|
|
|
|
"source_code": "print('title')",
|
|
|
|
|
"language": "python",
|
|
|
|
|
"stars": 0,
|
|
|
|
|
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
return slug
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _seed_news(title):
|
|
|
|
|
uid = str(uuid4())
|
|
|
|
|
slug = make_combined_slug(title, uid)
|
|
|
|
|
get_table("news").insert(
|
|
|
|
|
{
|
|
|
|
|
"deleted_at": None,
|
|
|
|
|
"deleted_by": None,
|
|
|
|
|
"uid": uid,
|
|
|
|
|
"slug": slug,
|
|
|
|
|
"title": title,
|
|
|
|
|
"description": "News description for the dp-title test.",
|
|
|
|
|
"content": "Body content for the seeded article.",
|
|
|
|
|
"url": "https://example.com/article",
|
|
|
|
|
"source_name": "ExampleSource",
|
|
|
|
|
"status": "published",
|
|
|
|
|
"synced_at": datetime.now(timezone.utc).isoformat(),
|
|
|
|
|
"show_on_landing": 1,
|
|
|
|
|
"grade": 8,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
return slug
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_post_detail_renders_title_backend():
|
|
|
|
|
title = "DpTitle Post Alpha"
|
|
|
|
|
slug = _seed_post(title)
|
|
|
|
|
html = _client().get(f"/posts/{slug}").text
|
|
|
|
|
assert f'<h1 class="post-detail-title">{title}</h1>' in html
|
|
|
|
|
assert "<dp-title" not in html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_project_detail_and_listing_render_title_backend():
|
|
|
|
|
title = "DpTitle Project Beta"
|
|
|
|
|
slug = _seed_project(title)
|
|
|
|
|
client = _client()
|
|
|
|
|
detail = client.get(f"/projects/{slug}").text
|
|
|
|
|
assert f'<h1 class="project-detail-title">{title}</h1>' in detail
|
|
|
|
|
listing = client.get("/projects").text
|
|
|
|
|
assert f'<h3 class="project-card-title">{title}</h3>' in listing
|
|
|
|
|
assert "<dp-title" not in detail and "<dp-title" not in listing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_gist_detail_and_listing_render_title_backend():
|
|
|
|
|
title = "DpTitle Gist Gamma"
|
|
|
|
|
slug = _seed_gist(title)
|
|
|
|
|
client = _client()
|
|
|
|
|
detail = client.get(f"/gists/{slug}").text
|
|
|
|
|
assert f'<h1 class="gist-detail-title">{title}</h1>' in detail
|
|
|
|
|
listing = client.get("/gists").text
|
|
|
|
|
assert f'<h3 class="gist-card-title">{title}</h3>' in listing
|
|
|
|
|
assert "<dp-title" not in detail and "<dp-title" not in listing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_news_detail_and_listing_render_title_backend():
|
|
|
|
|
title = "DpTitle News Delta"
|
|
|
|
|
slug = _seed_news(title)
|
|
|
|
|
client = _client()
|
|
|
|
|
detail = client.get(f"/news/{slug}").text
|
|
|
|
|
assert f'<h1 class="news-detail-title">{title}</h1>' in detail
|
|
|
|
|
listing = client.get("/news").text
|
|
|
|
|
assert "<dp-title" not in detail and "<dp-title" not in listing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_feed_listing_renders_post_title_backend():
|
|
|
|
|
title = "DpTitle Feed Epsilon"
|
|
|
|
|
_seed_post(title)
|
|
|
|
|
html = _client().get("/feed").text
|
|
|
|
|
assert f'<h3 class="post-title">{title}</h3>' in html
|
|
|
|
|
assert "<dp-title" not in html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _gitea_on():
|
|
|
|
|
runtime.set_client(FakeGiteaClient())
|
|
|
|
|
set_setting("gitea_base_url", "https://gitea.test")
|
|
|
|
|
set_setting("gitea_owner", "retoor")
|
|
|
|
|
set_setting("gitea_repo", "pydevplace")
|
|
|
|
|
set_setting("gitea_token", "test-token")
|
|
|
|
|
set_setting("issue_ai_enhance", "0")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _gitea_off():
|
|
|
|
|
runtime.set_client(None)
|
|
|
|
|
for key in ("gitea_base_url", "gitea_owner", "gitea_repo", "gitea_token"):
|
|
|
|
|
set_setting(key, "")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_issue_detail_and_listing_render_title_backend():
|
|
|
|
|
_gitea_on()
|
|
|
|
|
try:
|
|
|
|
|
fake = runtime.get_client()
|
|
|
|
|
title = "DpTitle Issue Zeta"
|
|
|
|
|
owner = _owner()
|
|
|
|
|
issue = run_async(fake.create_issue(title, "issue details for the title test"))
|
|
|
|
|
number = int(issue["number"])
|
|
|
|
|
store.record_ticket(
|
|
|
|
|
number=number,
|
|
|
|
|
author_uid=owner,
|
|
|
|
|
original_title=title,
|
|
|
|
|
original_description="issue details for the title test",
|
|
|
|
|
enhanced_title=title,
|
|
|
|
|
html_url=issue.get("html_url", ""),
|
|
|
|
|
status="open",
|
|
|
|
|
)
|
|
|
|
|
client = _client()
|
|
|
|
|
client.cookies.set("session", create_session(owner))
|
|
|
|
|
detail = client.get(f"/issues/{number}").text
|
|
|
|
|
assert f'<h1 class="issue-detail-title">{title}</h1>' in detail
|
|
|
|
|
listing = client.get("/issues").text
|
|
|
|
|
assert "<dp-title" not in detail and "<dp-title" not in listing
|
|
|
|
|
finally:
|
|
|
|
|
_gitea_off()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_post_content_rendered_backend_with_media():
|
|
|
|
|
owner = _owner()
|
|
|
|
|
from uuid import uuid4
|
|
|
|
|
from devplacepy.database import get_table as _gt
|
|
|
|
|
uid = str(uuid4())
|
|
|
|
|
slug = make_combined_slug("Content Render Check", uid)
|
|
|
|
|
body = "be **bold** :rocket: watch https://youtu.be/dQw4w9WgXcQ"
|
|
|
|
|
_gt("posts").insert(
|
|
|
|
|
{
|
|
|
|
|
"deleted_at": None, "deleted_by": None, "uid": uid, "user_uid": owner,
|
|
|
|
|
"slug": slug, "title": "Content Render Check", "content": body,
|
|
|
|
|
"topic": "general", "project_uid": None, "image": None, "stars": 0,
|
|
|
|
|
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
html = _client().get(f"/posts/{slug}").text
|
|
|
|
|
assert "<strong>bold</strong>" in html
|
|
|
|
|
assert "\U0001F680" in html
|
|
|
|
|
assert 'class="embed-youtube"' in html
|
|
|
|
|
assert "data-render" not in html.split('class="post-detail-content')[1][:200]
|