2026-06-13 16:32:33 +02:00
|
|
|
# retoor <retoor@molodetz.nl>
|
|
|
|
|
|
2026-06-06 16:31:42 +02:00
|
|
|
import time
|
|
|
|
|
from datetime import datetime, timedelta, timezone
|
|
|
|
|
import requests
|
|
|
|
|
from tests.conftest import BASE_URL
|
2026-06-09 18:48:08 +02:00
|
|
|
from devplacepy.database import (
|
|
|
|
|
get_table,
|
|
|
|
|
get_activity_calendar,
|
|
|
|
|
get_streaks,
|
|
|
|
|
get_activity_heatmap,
|
|
|
|
|
get_activity_months,
|
|
|
|
|
)
|
2026-06-06 16:31:42 +02:00
|
|
|
from devplacepy.utils import generate_uid, check_milestone_badges
|
2026-06-13 16:32:33 +02:00
|
|
|
_counter_streaks = [0]
|
|
|
|
|
def _make_user_streaks():
|
|
|
|
|
_counter_streaks[0] += 1
|
2026-06-06 16:31:42 +02:00
|
|
|
uid = generate_uid()
|
2026-06-13 16:32:33 +02:00
|
|
|
name = f"stk{int(time.time() * 1000)}{_counter_streaks[0]}"
|
2026-06-09 18:48:08 +02:00
|
|
|
get_table("users").insert(
|
|
|
|
|
{
|
|
|
|
|
"uid": uid,
|
|
|
|
|
"username": name,
|
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-09 18:48:08 +02:00
|
|
|
"email": f"{name}@t.dev",
|
|
|
|
|
"role": "Member",
|
|
|
|
|
"is_active": True,
|
|
|
|
|
"xp": 0,
|
|
|
|
|
"level": 1,
|
|
|
|
|
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
|
|
|
}
|
|
|
|
|
)
|
2026-06-06 16:31:42 +02:00
|
|
|
return uid
|
|
|
|
|
def _insert_post(user_uid, dt):
|
|
|
|
|
uid = generate_uid()
|
2026-06-09 18:48:08 +02:00
|
|
|
get_table("posts").insert(
|
|
|
|
|
{
|
2026-06-14 16:46:36 +02:00
|
|
|
"deleted_at": None,
|
|
|
|
|
"deleted_by": None,
|
2026-06-09 18:48:08 +02:00
|
|
|
"uid": uid,
|
|
|
|
|
"user_uid": user_uid,
|
|
|
|
|
"slug": f"{uid[:8]}-streak",
|
|
|
|
|
"title": None,
|
|
|
|
|
"content": "streak activity",
|
|
|
|
|
"topic": "random",
|
|
|
|
|
"project_uid": None,
|
|
|
|
|
"image": None,
|
|
|
|
|
"stars": 0,
|
|
|
|
|
"created_at": dt.isoformat(),
|
|
|
|
|
}
|
|
|
|
|
)
|
2026-06-06 16:31:42 +02:00
|
|
|
return uid
|
|
|
|
|
def _insert_comment(user_uid, post_uid, dt):
|
|
|
|
|
uid = generate_uid()
|
2026-06-09 18:48:08 +02:00
|
|
|
get_table("comments").insert(
|
|
|
|
|
{
|
2026-06-14 16:46:36 +02:00
|
|
|
"deleted_at": None,
|
|
|
|
|
"deleted_by": None,
|
2026-06-09 18:48:08 +02:00
|
|
|
"uid": uid,
|
|
|
|
|
"target_type": "post",
|
|
|
|
|
"target_uid": post_uid,
|
|
|
|
|
"post_uid": post_uid,
|
|
|
|
|
"user_uid": user_uid,
|
|
|
|
|
"content": "streak comment",
|
|
|
|
|
"parent_uid": None,
|
|
|
|
|
"created_at": dt.isoformat(),
|
|
|
|
|
}
|
|
|
|
|
)
|
2026-06-06 16:31:42 +02:00
|
|
|
return uid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_consecutive_days_build_streak(app_server):
|
2026-06-13 16:32:33 +02:00
|
|
|
uid = _make_user_streaks()
|
2026-06-06 16:31:42 +02:00
|
|
|
today = datetime.now(timezone.utc)
|
|
|
|
|
for offset in (0, 1, 2):
|
|
|
|
|
_insert_post(uid, today - timedelta(days=offset))
|
|
|
|
|
streaks = get_streaks(uid)
|
|
|
|
|
assert streaks["current"] == 3
|
|
|
|
|
assert streaks["longest"] >= 3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_gap_resets_current_streak(app_server):
|
2026-06-13 16:32:33 +02:00
|
|
|
uid = _make_user_streaks()
|
2026-06-06 16:31:42 +02:00
|
|
|
today = datetime.now(timezone.utc)
|
|
|
|
|
_insert_post(uid, today)
|
|
|
|
|
_insert_post(uid, today - timedelta(days=3))
|
|
|
|
|
streaks = get_streaks(uid)
|
|
|
|
|
assert streaks["current"] == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_yesterday_only_counts_as_current(app_server):
|
2026-06-13 16:32:33 +02:00
|
|
|
uid = _make_user_streaks()
|
2026-06-06 16:31:42 +02:00
|
|
|
yesterday = datetime.now(timezone.utc) - timedelta(days=1)
|
|
|
|
|
_insert_post(uid, yesterday)
|
|
|
|
|
assert get_streaks(uid)["current"] == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_calendar_sums_across_sources(app_server):
|
2026-06-13 16:32:33 +02:00
|
|
|
uid = _make_user_streaks()
|
2026-06-06 16:31:42 +02:00
|
|
|
today = datetime.now(timezone.utc)
|
|
|
|
|
post_uid = _insert_post(uid, today)
|
|
|
|
|
_insert_comment(uid, post_uid, today)
|
|
|
|
|
calendar = get_activity_calendar(uid)
|
|
|
|
|
assert calendar.get(today.date().isoformat()) == 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_heatmap_shape(app_server):
|
2026-06-13 16:32:33 +02:00
|
|
|
uid = _make_user_streaks()
|
2026-06-06 16:31:42 +02:00
|
|
|
weeks = get_activity_heatmap(uid)
|
feat: add api key auth, devii agent, openai gateway, and admin service management
This commit introduces a comprehensive set of new features including API key authentication with CLI management commands (get, reset, backfill), a Devii agentic assistant with WebSocket terminal and session bootstrap, an OpenAI-compatible LLM gateway service, and an admin service management panel. It also adds Playwright browser automation for bot support, configures internal gateway URLs, refactors content editing/deletion to support JSON API responses, and updates documentation across AGENTS.md, README.md, and the developer docs site.
2026-06-08 17:38:33 +02:00
|
|
|
assert len(weeks) == 53
|
|
|
|
|
assert all(len(week) == 7 for week in weeks)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_heatmap_anchors_at_first_contribution(app_server):
|
2026-06-13 16:32:33 +02:00
|
|
|
uid = _make_user_streaks()
|
feat: add api key auth, devii agent, openai gateway, and admin service management
This commit introduces a comprehensive set of new features including API key authentication with CLI management commands (get, reset, backfill), a Devii agentic assistant with WebSocket terminal and session bootstrap, an OpenAI-compatible LLM gateway service, and an admin service management panel. It also adds Playwright browser automation for bot support, configures internal gateway URLs, refactors content editing/deletion to support JSON API responses, and updates documentation across AGENTS.md, README.md, and the developer docs site.
2026-06-08 17:38:33 +02:00
|
|
|
first = datetime.now(timezone.utc) - timedelta(days=30)
|
|
|
|
|
_insert_post(uid, first)
|
|
|
|
|
weeks = get_activity_heatmap(uid)
|
|
|
|
|
expected = (first.date() - timedelta(days=first.date().weekday())).isoformat()
|
|
|
|
|
assert weeks[0][0]["date"] == expected
|
|
|
|
|
assert len(weeks) == 53
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_activity_months_returns_six_labels(app_server):
|
2026-06-13 16:32:33 +02:00
|
|
|
uid = _make_user_streaks()
|
feat: add api key auth, devii agent, openai gateway, and admin service management
This commit introduces a comprehensive set of new features including API key authentication with CLI management commands (get, reset, backfill), a Devii agentic assistant with WebSocket terminal and session bootstrap, an OpenAI-compatible LLM gateway service, and an admin service management panel. It also adds Playwright browser automation for bot support, configures internal gateway URLs, refactors content editing/deletion to support JSON API responses, and updates documentation across AGENTS.md, README.md, and the developer docs site.
2026-06-08 17:38:33 +02:00
|
|
|
months = get_activity_months(get_activity_heatmap(uid))
|
|
|
|
|
assert len(months) == 6
|
|
|
|
|
assert all(len(label) == 3 for label in months)
|
2026-06-06 16:31:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_seven_day_streak_awards_on_fire_badge(app_server):
|
2026-06-13 16:32:33 +02:00
|
|
|
uid = _make_user_streaks()
|
2026-06-06 16:31:42 +02:00
|
|
|
today = datetime.now(timezone.utc)
|
|
|
|
|
for offset in range(7):
|
|
|
|
|
_insert_post(uid, today - timedelta(days=offset))
|
|
|
|
|
check_milestone_badges(uid)
|
|
|
|
|
assert get_table("badges").count(user_uid=uid, badge_name="On Fire") == 1
|