195 lines
6.5 KiB
Python
Raw Normal View History

# retoor <retoor@molodetz.nl>
import time
import requests
from tests.conftest import BASE_URL
from devplacepy.database import get_table, refresh_snapshot
_counter_isslop = [0]
def _json_headers():
return {"Accept": "application/json"}
def _unique(prefix="sl"):
_counter_isslop[0] += 1
return f"{prefix}{int(time.time() * 1000)}{_counter_isslop[0]}"
def _clear_isslop_data():
refresh_snapshot()
jobs = get_table("jobs")
for row in list(jobs.find(kind="isslop")):
jobs.delete(uid=row["uid"])
analyses = get_table("isslop_analyses")
for row in list(analyses.find()):
analyses.delete(uid=row["uid"])
def test_isslop_page_renders(app_server):
r = requests.get(f"{BASE_URL}/tools/isslop")
assert r.status_code == 200
assert "AI Usage Analyzer" in r.text
assert "<dp-isslop>" in r.text
assert "devii_guest" in r.headers.get("set-cookie", "")
def test_run_enqueues_and_creates_analysis(app_server):
session = requests.Session()
try:
r = session.post(
f"{BASE_URL}/tools/isslop/run",
headers=_json_headers(),
data={"url": "https://github.com/owner/repository"},
)
assert r.status_code == 200, r.text
body = r.json()
uid = body["uid"]
assert body["status_url"] == f"/tools/isslop/{uid}"
assert body["events_url"] == f"/tools/isslop/{uid}/events"
assert body["report_url"] == f"/tools/isslop/{uid}/report"
assert body["topic"] == f"public.isslop.{uid}"
refresh_snapshot()
job = get_table("jobs").find_one(uid=uid)
assert job is not None
assert job["kind"] == "isslop"
assert job["status"] == "pending"
analysis = get_table("isslop_analyses").find_one(uid=uid)
assert analysis is not None
assert analysis["status"] == "pending"
assert analysis["owner_kind"] == "guest"
assert analysis["source_url"] == "https://github.com/owner/repository"
assert analysis["deleted_at"] is None
status = session.get(f"{BASE_URL}/tools/isslop/{uid}", headers=_json_headers())
assert status.status_code == 200
assert status.json()["status"] == "pending"
assert status.json()["source_url"] == "https://github.com/owner/repository"
events = session.get(f"{BASE_URL}/tools/isslop/{uid}/events", headers=_json_headers())
assert events.status_code == 200
assert events.json()["events"] == []
badge = session.get(f"{BASE_URL}/tools/isslop/{uid}/badge.svg")
assert badge.status_code == 200
assert badge.headers["content-type"].startswith("image/svg+xml")
assert "analyzing" in badge.text
listing = session.get(f"{BASE_URL}/tools/isslop/list", headers=_json_headers())
assert listing.status_code == 200
uids = [row["uid"] for row in listing.json()["analyses"]]
assert uid in uids
finally:
_clear_isslop_data()
def test_second_active_run_is_denied(app_server):
session = requests.Session()
try:
first = session.post(
f"{BASE_URL}/tools/isslop/run",
headers=_json_headers(),
data={"url": "https://github.com/owner/repository"},
)
assert first.status_code == 200
second = session.post(
f"{BASE_URL}/tools/isslop/run",
headers=_json_headers(),
data={"url": "https://github.com/owner/other"},
)
assert second.status_code == 429
assert second.json()["error"]["uid"] == first.json()["uid"]
finally:
_clear_isslop_data()
def test_invalid_url_is_rejected(app_server):
session = requests.Session()
try:
r = session.post(
f"{BASE_URL}/tools/isslop/run",
headers=_json_headers(),
data={"url": "ftp://example.com/archive"},
allow_redirects=False,
)
assert r.status_code != 200
refresh_snapshot()
assert get_table("jobs").find_one(kind="isslop") is None
finally:
_clear_isslop_data()
def test_status_unknown_uid_404(app_server):
r = requests.get(f"{BASE_URL}/tools/isslop/does-not-exist", headers=_json_headers())
assert r.status_code == 404
def test_report_json_while_pending(app_server):
session = requests.Session()
try:
run = session.post(
f"{BASE_URL}/tools/isslop/run",
headers=_json_headers(),
data={"url": "https://github.com/owner/repository"},
)
uid = run.json()["uid"]
report = session.get(f"{BASE_URL}/tools/isslop/{uid}/report", headers=_json_headers())
assert report.status_code == 200
body = report.json()
assert body["status"] == "pending"
assert body["markdown"] == ""
assert body["badge"]["badge_url"].endswith(f"/tools/isslop/{uid}/badge.svg")
html = session.get(f"{BASE_URL}/tools/isslop/{uid}/report")
assert html.status_code == 200
assert "dp-isslop-run" in html.text
assert 'class="breadcrumb"' in html.text
assert "sidebar-card" in html.text
download = session.get(f"{BASE_URL}/tools/isslop/{uid}/report.md")
assert download.status_code == 404
finally:
_clear_isslop_data()
def test_guest_history_claimed_on_signup(app_server):
session = requests.Session()
try:
run = session.post(
f"{BASE_URL}/tools/isslop/run",
headers=_json_headers(),
data={"url": "https://github.com/owner/repository"},
)
uid = run.json()["uid"]
name = _unique("slopuser")
session.post(
f"{BASE_URL}/auth/signup",
data={
"username": name,
"email": f"{name}@t.dev",
"password": "secret123",
"confirm_password": "secret123",
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
"birth_date": "1990-01-01",
"accept_terms": "1",
},
allow_redirects=True,
)
listing = session.get(f"{BASE_URL}/tools/isslop/list", headers=_json_headers())
assert listing.status_code == 200
rows = [row for row in listing.json()["analyses"] if row["uid"] == uid]
assert len(rows) == 1
refresh_snapshot()
analysis = get_table("isslop_analyses").find_one(uid=uid)
user = get_table("users").find_one(username=name)
assert analysis["owner_kind"] == "user"
assert analysis["owner_id"] == user["uid"]
assert get_table("isslop_analyses").count(uid=uid) == 1
finally:
_clear_isslop_data()