2026-06-13 16:32:33 +02:00
|
|
|
# retoor <retoor@molodetz.nl>
|
|
|
|
|
|
2026-06-05 20:34:03 +02:00
|
|
|
import argparse
|
2026-06-09 20:02:50 +02:00
|
|
|
from datetime import datetime, timezone
|
2026-06-05 20:34:03 +02:00
|
|
|
import pytest
|
|
|
|
|
from devplacepy import cli
|
|
|
|
|
from devplacepy.database import get_table
|
|
|
|
|
from devplacepy.utils import generate_uid
|
2026-06-13 16:32:33 +02:00
|
|
|
def _make_user_cli(role="Member"):
|
2026-06-05 20:34:03 +02:00
|
|
|
username = f"cli_{generate_uid()[:8]}"
|
2026-06-09 18:48:08 +02:00
|
|
|
get_table("users").insert(
|
|
|
|
|
{
|
|
|
|
|
"uid": generate_uid(),
|
|
|
|
|
"username": username,
|
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"{username}@t.dev",
|
|
|
|
|
"role": role,
|
|
|
|
|
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
|
|
|
}
|
|
|
|
|
)
|
2026-06-05 20:34:03 +02:00
|
|
|
return username
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_role_get_prints_lowercased_role(local_db, capsys):
|
2026-06-13 16:32:33 +02:00
|
|
|
username = _make_user_cli(role="Admin")
|
2026-06-05 20:34:03 +02:00
|
|
|
cli.cmd_role_get(argparse.Namespace(username=username))
|
|
|
|
|
assert capsys.readouterr().out.strip() == "admin"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_role_get_missing_user_exits(local_db):
|
|
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
|
cli.cmd_role_get(argparse.Namespace(username="cli_absent_xyz"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_role_set_updates_role(local_db):
|
2026-06-13 16:32:33 +02:00
|
|
|
username = _make_user_cli(role="Member")
|
2026-06-05 20:34:03 +02:00
|
|
|
cli.cmd_role_set(argparse.Namespace(username=username, role="admin"))
|
|
|
|
|
user = get_table("users").find_one(username=username)
|
|
|
|
|
assert user["role"] == "Admin"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_role_set_invalid_role_exits(local_db):
|
2026-06-13 16:32:33 +02:00
|
|
|
username = _make_user_cli()
|
2026-06-05 20:34:03 +02:00
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
|
cli.cmd_role_set(argparse.Namespace(username=username, role="superuser"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_role_set_missing_user_exits(local_db):
|
|
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
|
cli.cmd_role_set(argparse.Namespace(username="cli_absent_xyz", role="admin"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_news_clear_deletes_all_tables(local_db, capsys):
|
|
|
|
|
for table in ("news", "news_images", "news_sync"):
|
|
|
|
|
get_table(table).insert({"uid": generate_uid(), "marker": "cli"})
|
|
|
|
|
cli.cmd_news_clear(argparse.Namespace())
|
|
|
|
|
for table in ("news", "news_images", "news_sync"):
|
|
|
|
|
assert get_table(table).count() == 0
|
|
|
|
|
assert "News data cleared" in capsys.readouterr().out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_news_sanitize_strips_html(local_db, capsys):
|
|
|
|
|
uid = generate_uid()
|
2026-06-09 18:48:08 +02:00
|
|
|
get_table("news").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,
|
|
|
|
|
"description": "<b>Bold</b> & clean",
|
|
|
|
|
"content": "<p>Body</p>",
|
|
|
|
|
}
|
|
|
|
|
)
|
2026-06-05 20:34:03 +02:00
|
|
|
cli.cmd_news_sanitize(argparse.Namespace())
|
|
|
|
|
row = get_table("news").find_one(uid=uid)
|
|
|
|
|
assert row["description"] == "Bold & clean"
|
|
|
|
|
assert row["content"] == "Body"
|
|
|
|
|
assert "Sanitized" in capsys.readouterr().out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_attachments_prune_removes_only_stale_orphans(local_db, capsys):
|
|
|
|
|
old_uid = generate_uid()
|
|
|
|
|
fresh_uid = generate_uid()
|
|
|
|
|
attachments = get_table("attachments")
|
2026-06-09 18:48:08 +02:00
|
|
|
attachments.insert(
|
|
|
|
|
{
|
2026-06-14 16:46:36 +02:00
|
|
|
"deleted_at": None,
|
|
|
|
|
"deleted_by": None,
|
2026-06-09 18:48:08 +02:00
|
|
|
"uid": old_uid,
|
|
|
|
|
"target_type": "",
|
|
|
|
|
"target_uid": "",
|
|
|
|
|
"created_at": "2000-01-01T00:00:00+00:00",
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
attachments.insert(
|
|
|
|
|
{
|
2026-06-14 16:46:36 +02:00
|
|
|
"deleted_at": None,
|
|
|
|
|
"deleted_by": None,
|
2026-06-09 18:48:08 +02:00
|
|
|
"uid": fresh_uid,
|
|
|
|
|
"target_type": "",
|
|
|
|
|
"target_uid": "",
|
|
|
|
|
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
|
|
|
}
|
|
|
|
|
)
|
2026-06-05 20:34:03 +02:00
|
|
|
cli.cmd_attachments_prune(argparse.Namespace(hours=24))
|
|
|
|
|
assert attachments.find_one(uid=old_uid) is None
|
|
|
|
|
assert attachments.find_one(uid=fresh_uid) is not None
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
def test_apikey_get_prints_key(local_db, capsys):
|
2026-06-13 16:32:33 +02:00
|
|
|
username = _make_user_cli()
|
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
|
|
|
key = generate_uid()
|
2026-06-09 18:48:08 +02:00
|
|
|
get_table("users").update(
|
|
|
|
|
{"uid": get_table("users").find_one(username=username)["uid"], "api_key": key},
|
|
|
|
|
["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
|
|
|
cli.cmd_apikey_get(argparse.Namespace(username=username))
|
|
|
|
|
assert capsys.readouterr().out.strip() == key
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_apikey_reset_changes_key(local_db, capsys):
|
2026-06-13 16:32:33 +02:00
|
|
|
username = _make_user_cli()
|
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
|
|
|
users = get_table("users")
|
2026-06-09 18:48:08 +02:00
|
|
|
users.update(
|
|
|
|
|
{"uid": users.find_one(username=username)["uid"], "api_key": generate_uid()},
|
|
|
|
|
["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
|
|
|
before = users.find_one(username=username)["api_key"]
|
|
|
|
|
cli.cmd_apikey_reset(argparse.Namespace(username=username))
|
|
|
|
|
printed = capsys.readouterr().out.strip()
|
|
|
|
|
after = users.find_one(username=username)["api_key"]
|
|
|
|
|
assert after != before
|
|
|
|
|
assert printed == after
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_apikey_backfill_assigns_missing(local_db, capsys):
|
|
|
|
|
users = get_table("users")
|
|
|
|
|
uid = generate_uid()
|
2026-06-09 18:48:08 +02:00
|
|
|
users.insert(
|
|
|
|
|
{
|
|
|
|
|
"uid": uid,
|
|
|
|
|
"username": f"cli_{uid[:8]}",
|
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"{uid[:8]}@t.dev",
|
|
|
|
|
"role": "Member",
|
|
|
|
|
"created_at": datetime.now(timezone.utc).isoformat(),
|
|
|
|
|
}
|
|
|
|
|
)
|
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
|
|
|
cli.cmd_apikey_backfill(argparse.Namespace())
|
|
|
|
|
assert capsys.readouterr().out.strip().startswith("Assigned API keys to")
|
|
|
|
|
assert users.find_one(uid=uid).get("api_key")
|
|
|
|
|
|
|
|
|
|
|
2026-06-05 20:34:03 +02:00
|
|
|
def test_main_without_command_exits(monkeypatch):
|
|
|
|
|
monkeypatch.setattr("sys.argv", ["devplace"])
|
|
|
|
|
with pytest.raises(SystemExit):
|
|
|
|
|
cli.main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_main_dispatches_subcommand(local_db, monkeypatch, capsys):
|
2026-06-13 16:32:33 +02:00
|
|
|
username = _make_user_cli(role="Admin")
|
2026-06-05 20:34:03 +02:00
|
|
|
monkeypatch.setattr("sys.argv", ["devplace", "role", "get", username])
|
|
|
|
|
cli.main()
|
|
|
|
|
assert capsys.readouterr().out.strip() == "admin"
|