Files
devplacepy/tests/api/sync/comments.py
T
retoorandClaude Sonnet 5.5 02ab747cd0
DevPlace CI / test (push) Failing after 44m45s
Code Farm: per-plot auto-replant pause and crop-lock check; community sync and node work
Continuous Delivery could never be turned off once a crop was planted. Add a
one-shot per-plot "stop after harvest" flag (POST /game/plot/stop, Devii tool
game_plot_stop, game_plots.stop_after_harvest), cleared by the next plant,
autoreplant claim or Refactor. Autoreplant now also respects crop locks through
the shared _crop_lock predicate. Plan and measurements in happyplanting.md.

Also includes the pending community sync, node network and related work in the
tree; the full suite passed (4999) with all of it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-17 02:23:43 +02:00

72 lines
3.4 KiB
Python

# retoor <retoor@molodetz.nl>
from devplacepy.database import get_table
from tests.api.sync.conftest import comment_record, post_record, sync_ok, unique, user_record
def seed_thread(client, admin, origin):
sync_ok(client, admin, "users", origin, [user_record("u1", unique("cu1")), user_record("u2", unique("cu2"))])
sync_ok(client, admin, "posts", origin, [post_record("p1", "u1"), post_record("p2", "u1")])
def test_unknown_references_are_deferred_with_specific_reasons(client, admin, origin):
seed_thread(client, admin, origin)
body = sync_ok(
client, admin, "comments", origin,
[
comment_record("c1", author="nobody"),
comment_record("c2", post="nopost"),
comment_record("c3", parent_uid="noparent"),
],
)
assert [r["reason"] for r in body["results"]] == ["unknown_author", "unknown_post", "unknown_parent"]
assert [r["status"] for r in body["results"]] == ["deferred", "deferred", "deferred"]
def test_create_with_nested_reply_in_one_batch(client, admin, origin):
seed_thread(client, admin, origin)
body = sync_ok(
client, admin, "comments", origin,
[comment_record("c1", author="u2"), comment_record("c2", author="u1", parent_uid="c1")],
)
assert [r["status"] for r in body["results"]] == ["created", "created"]
parent, reply = (get_table("comments").find_one(uid=r["local_uid"]) for r in body["results"])
post = get_table("posts").find_one(uid=reply["post_uid"])
assert reply["parent_uid"] == parent["uid"]
assert reply["target_type"] == "post" and reply["target_uid"] == post["uid"]
assert parent["deleted_at"] is None
def test_parent_on_a_different_post_is_rejected(client, admin, origin):
seed_thread(client, admin, origin)
sync_ok(client, admin, "comments", origin, [comment_record("c1", post="p1")])
body = sync_ok(client, admin, "comments", origin, [comment_record("c2", post="p2", parent_uid="c1")])
assert body["results"][0]["reason"] == "parent_mismatch"
def test_edit_replay_and_tombstone(client, admin, origin):
seed_thread(client, admin, origin)
created = sync_ok(client, admin, "comments", origin, [comment_record("c1")])["results"][0]
assert sync_ok(client, admin, "comments", origin, [comment_record("c1")])["results"][0]["status"] == "unchanged"
edited = sync_ok(
client, admin, "comments", origin,
[comment_record("c1", content="edited comment", updated_at="2025-02-01T00:00:00Z")],
)["results"][0]
assert edited["status"] == "updated"
assert get_table("comments").find_one(uid=created["local_uid"])["content"] == "edited comment"
sync_ok(
client, admin, "comments", origin,
[comment_record("c1", content="edited comment", updated_at="2025-03-01T00:00:00Z", deleted=True)],
)
row = get_table("comments").find_one(uid=created["local_uid"])
assert row["deleted_at"] and row["deleted_by"] == "sync"
def test_synced_comment_renders_on_the_post_page(client, admin, origin):
seed_thread(client, admin, origin)
sync_ok(client, admin, "comments", origin, [comment_record("c1", content="comment visible on the page")])
link = get_table("sync_links").find_one(origin=origin, kind="posts", origin_uid="p1")
slug = get_table("posts").find_one(uid=link["local_uid"])["slug"]
page = client.get(f"/posts/{slug}")
assert page.status_code == 200 and "comment visible on the page" in page.text