Files
devplacepy/tests/api/sitemapxml.py
T
retoorandClaude Sonnet 5 572e022584 Add thread notifications, SEO topic pages, and fix quiz auto-advance
Notifications: a new "thread" type notifies every other commenter on a
post whenever anyone comments on it, disregarding reply hierarchy -
excluding the actor and whoever already got a comment/reply
notification for that same event, so no one is double-notified.
Implemented via a background-deferred fan-out mirroring the existing
mention-notification pattern.

SEO: discussion_forum_posting() now embeds up to 20 of a post's
comments as nested schema.org Comment entities (not just an aggregate
count), and a new /topics hub plus /topics/{topic} pages give the
feed's topic filter real, independently crawlable/indexable URLs -
/feed?topic=X was never indexable since its canonical strips the
query string back to bare /feed. Both are wired end to end (schemas,
Devii actions, docs API, sitemap, locustfile load-test coverage).

Quiz player: the auto-advance to the next question used to hide the
just-answered slide in the same tick as rendering the grade, so on
any multi-question quiz the Correct/Not correct feedback was never
actually visible before the view moved on. Delayed via setTimeout,
with the pending timer cleared on manual navigation and on
disconnect so it can't race or fire on a removed component.

Also includes other local changes already in progress in this
working tree before this session (messaging, push delivery,
deepsearch jobs, game economy, quiz builder) - verified by the full
suite passing (3467 tests) but not authored or individually reviewed
in this session.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VL9Xn57W5UR3HZbbuuzxdK
2026-09-03 08:47:57 +02:00

307 lines
10 KiB
Python

# retoor <retoor@molodetz.nl>
import time
import pytest
import requests
from tests.conftest import BASE_URL
from devplacepy.database import get_table
from devplacepy.utils import clear_user_cache
from devplacepy import project_files
from devplacepy.project_files import ProjectFileError
from devplacepy.services.devii.actions.dispatcher import (
confirmation_error,
_is_confirmed,
)
_counter_project_visibility = [0]
def _signup_project_visibility():
_counter_project_visibility[0] += 1
name = f"pv{int(time.time() * 1000)}{_counter_project_visibility[0]}"
session = requests.Session()
session.post(
f"{BASE_URL}/auth/signup",
data={
"username": name,
"email": f"{name}@t.dev",
"password": "secret123",
"confirm_password": "secret123",
"birth_date": "1990-01-01",
"accept_terms": "1",
},
allow_redirects=True,
)
row = get_table("users").find_one(username=name)
return name, row["uid"], row["api_key"]
def _make_admin_project_visibility():
name, uid, key = _signup_project_visibility()
get_table("users").update({"uid": uid, "role": "Admin"}, ["uid"])
clear_user_cache(uid)
return name, uid, key
def _h_project_visibility(key=None):
headers = {"Accept": "application/json"}
if key:
headers["X-API-KEY"] = key
return headers
def _create_project_project_visibility(key, title, is_private=False):
data = {
"title": title,
"description": "visibility test",
"project_type": "software",
"status": "In Development",
}
if is_private:
data["is_private"] = "on"
r = requests.post(f"{BASE_URL}/projects/create", headers=_h_project_visibility(key), data=data)
assert r.status_code == 200, r.text
return r.json()["data"]
def _project_uid(slug):
return get_table("projects").find_one(slug=slug)["uid"]
def _write_project_visibility(key, slug, path, content):
return requests.post(
f"{BASE_URL}/projects/{slug}/files/write",
headers=_h_project_visibility(key),
data={"path": path, "content": content},
allow_redirects=False,
)
def _set_private(key, slug, value):
return requests.post(
f"{BASE_URL}/projects/{slug}/private",
headers=_h_project_visibility(key),
data={"value": 1 if value else 0},
allow_redirects=False,
)
def _set_readonly(key, slug, value):
return requests.post(
f"{BASE_URL}/projects/{slug}/readonly",
headers=_h_project_visibility(key),
data={"value": 1 if value else 0},
allow_redirects=False,
)
def _list_slugs(key=None, user_uid=None):
params = {"user_uid": user_uid} if user_uid else None
r = requests.get(f"{BASE_URL}/projects", headers=_h_project_visibility(key), params=params)
return [p["slug"] for p in r.json()["projects"]]
def _seed_news_seo():
from datetime import datetime, timezone
from devplacepy.database import get_table
from devplacepy.utils import generate_uid, make_combined_slug
uid = generate_uid()
title = f"SEO Test News Article {uid.split('-')[-1]}"
slug = make_combined_slug(title, uid)
get_table("news").insert(
{
"deleted_at": None,
"deleted_by": None,
"uid": uid,
"slug": slug,
"title": title,
"description": "A seeded news article for SEO tests.",
"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": 0,
"grade": 8,
}
)
return slug, uid
def _seed_owner():
from datetime import datetime, timezone
from uuid import uuid4
from devplacepy.database import get_table
uid = str(uuid4())
get_table("users").insert(
{
"uid": uid,
"username": f"seo_{uid[:8]}",
"terms_version": "1",
"email": f"{uid[:8]}@seo.test",
"password_hash": "x",
"role": "Member",
"is_active": True,
"created_at": datetime.now(timezone.utc).isoformat(),
}
)
return uid
def _seed_post_seo(image=None):
from datetime import datetime, timezone
from uuid import uuid4
from devplacepy.database import get_table
from devplacepy.utils import make_combined_slug
owner = _seed_owner()
uid = str(uuid4())
slug = make_combined_slug("SEO Detail Post", uid)
get_table("posts").insert(
{
"deleted_at": None,
"deleted_by": None,
"uid": uid,
"user_uid": owner,
"slug": slug,
"title": "SEO Detail Post",
"content": "Body text for the SEO detail post.",
"topic": "general",
"project_uid": None,
"image": image,
"stars": 0,
"created_at": datetime.now(timezone.utc).isoformat(),
}
)
return slug, uid
def _seed_gist():
from datetime import datetime, timezone
from uuid import uuid4
from devplacepy.database import get_table
from devplacepy.utils import make_combined_slug
owner = _seed_owner()
uid = str(uuid4())
slug = make_combined_slug("SEO Detail Gist", uid)
get_table("gists").insert(
{
"deleted_at": None,
"deleted_by": None,
"uid": uid,
"user_uid": owner,
"slug": slug,
"title": "SEO Detail Gist",
"description": "Gist description for SEO tests.",
"source_code": "print('seo')",
"language": "python",
"stars": 0,
"created_at": datetime.now(timezone.utc).isoformat(),
}
)
return slug, uid
def _seed_project():
from datetime import datetime, timezone
from uuid import uuid4
from devplacepy.database import get_table
from devplacepy.utils import make_combined_slug
owner = _seed_owner()
uid = str(uuid4())
slug = make_combined_slug("SEO Detail Project", uid)
get_table("projects").insert(
{
"deleted_at": None,
"deleted_by": None,
"uid": uid,
"user_uid": owner,
"slug": slug,
"title": "SEO Detail Project",
"description": "Project description for SEO tests.",
"project_type": "software",
"platforms": "Linux",
"status": "Released",
"stars": 0,
"created_at": datetime.now(timezone.utc).isoformat(),
}
)
return slug, uid
def _seed_news_image(news_uid):
from devplacepy.database import get_table
get_table("news_images").insert(
{
"deleted_at": None,
"deleted_by": None,
"news_uid": news_uid,
"url": "https://example.com/seo-news-image.jpg",
}
)
def _seed_feed_posts(count):
from datetime import datetime, timezone, timedelta
from uuid import uuid4
from devplacepy.database import get_table
from devplacepy.utils import make_combined_slug
owner = _seed_owner()
topic = f"seopag{owner[:8]}"
base = datetime(2026, 1, 1, tzinfo=timezone.utc)
posts = get_table("posts")
for i in range(count):
uid = str(uuid4())
posts.insert(
{
"deleted_at": None,
"deleted_by": None,
"uid": uid,
"user_uid": owner,
"slug": make_combined_slug(f"seo pag {i}", uid),
"title": None,
"content": f"seo pag post {i}",
"topic": topic,
"project_uid": None,
"image": None,
"stars": 0,
"created_at": (base - timedelta(seconds=i)).isoformat(),
}
)
return topic
def test_private_project_excluded_from_sitemap(app_server):
_, _, key = _signup_project_visibility()
public_slug = _create_project_project_visibility(key, "Sitemap Public")["slug"]
private_slug = _create_project_project_visibility(key, "Sitemap Private", is_private=True)["slug"]
xml = requests.get(f"{BASE_URL}/sitemap.xml").text
assert f"/projects/{public_slug}" in xml
assert f"/projects/{private_slug}" not in xml
def test_sitemap_xml_exists(app_server):
r = requests.get(f"{BASE_URL}/sitemap.xml")
assert r.status_code == 200
assert "<urlset" in r.text
assert "<loc>" in r.text
def test_sitemap_headers_and_static_entries(app_server):
r = requests.get(f"{BASE_URL}/sitemap.xml")
assert r.headers["content-type"].startswith("application/xml")
assert "cache-control" in {k.lower() for k in r.headers}
assert f"{BASE_URL}/gists" in r.text
def test_sitemap_lists_the_topics_hub_and_every_topic(app_server):
r = requests.get(f"{BASE_URL}/sitemap.xml")
assert f"{BASE_URL}/topics</loc>" in r.text
for topic in ("devlog", "showcase", "question", "rant", "fun", "random", "politics"):
assert f"{BASE_URL}/topics/{topic}</loc>" in r.text
def test_sitemap_lists_the_public_moderation_surfaces(app_server):
xml = requests.get(f"{BASE_URL}/sitemap.xml").text
assert f"<loc>{BASE_URL}/reports/reasons</loc>" in xml
assert f"<loc>{BASE_URL}/workspaces/index</loc>" in xml
assert f"{BASE_URL}/reports/mine" not in xml
def test_sitemap_lists_each_legal_document_exactly_once(app_server):
from devplacepy.seo import LEGAL_DOC_SLUGS
xml = requests.get(f"{BASE_URL}/sitemap.xml").text
for slug in LEGAL_DOC_SLUGS:
loc = f"<loc>{BASE_URL}/docs/{slug}.html</loc>"
assert xml.count(loc) == 1, f"{slug} listed {xml.count(loc)} times"
def test_sitemap_never_repeats_a_documentation_url(app_server):
import re
xml = requests.get(f"{BASE_URL}/sitemap.xml").text
locs = [loc for loc in re.findall(r"<loc>(.*?)</loc>", xml) if "/docs/" in loc]
assert locs, "the sitemap lists no documentation pages"
duplicates = sorted({loc for loc in locs if locs.count(loc) > 1})
assert duplicates == [], duplicates
def test_sitemap_includes_published_news(app_server):
slug, _ = _seed_news_seo()
r = requests.get(f"{BASE_URL}/sitemap.xml")
assert f"/news/{slug}" in r.text