feat: add per-user avatar seed regeneration with irreversible random avatar replacement
Implement a new `avatar_seed` column on the users table that overrides the username-based seed for Multiavatar generation. Introduce a null-safe `avatar_seed(user)` choke point in `avatar.py` that resolves `user.get("avatar_seed") or user.get("username")`, registered as a Jinja global so every render site (`_avatar_link.html`, `avatar_url(...)` calls, SEO `og_image`, issues ad-hoc dicts, devRant payload/PNG) propagates a regenerated seed. Add `POST /profile/{username}/regenerate-avatar` endpoint (owner-or-admin only) that writes a fresh `generate_uid()` to `avatar_seed`, invalidates the target's user cache, and audits `profile.avatar.regenerate`. The previous seed is overwritten and never stored, making regeneration irreversible. Document the feature in `AGENTS.md` and `README.md`, add the API endpoint to `docs_api.py`, and include the `regenerate_avatar` Devii tool in `CONFIRM_REQUIRED`.
This commit is contained in:
@@ -490,6 +490,93 @@ def test_prestige_resets_farm_and_increments(local_db):
|
||||
assert len(store.get_plots(farm["uid"])) == economy.STARTING_PLOTS
|
||||
|
||||
|
||||
# --- legacy upgrades ---------------------------------------------------------
|
||||
|
||||
|
||||
def test_upgrade_legacy_success_spends_stars(local_db):
|
||||
user = _reset("unit_a")
|
||||
_set(user, stars=100, legacy_multiplier=0)
|
||||
cost = economy.legacy_cost(economy.legacy_for("multiplier"), 0)
|
||||
result = store.upgrade_legacy(user, "multiplier")
|
||||
assert result["level"] == 1
|
||||
assert result["spent"] == cost
|
||||
farm = store.get_farm(user["uid"])
|
||||
assert int(farm["legacy_multiplier"]) == 1
|
||||
assert int(farm["stars"]) == 100 - cost
|
||||
|
||||
|
||||
def test_upgrade_legacy_unknown_key(local_db):
|
||||
user = _reset("unit_a")
|
||||
_set(user, stars=100)
|
||||
with pytest.raises(GameError):
|
||||
store.upgrade_legacy(user, "telekinesis")
|
||||
|
||||
|
||||
def test_upgrade_legacy_maxed(local_db):
|
||||
user = _reset("unit_a")
|
||||
up = economy.legacy_for("multiplier")
|
||||
_set(user, stars=100000, legacy_multiplier=up.max_level)
|
||||
with pytest.raises(GameError):
|
||||
store.upgrade_legacy(user, "multiplier")
|
||||
|
||||
|
||||
def test_upgrade_legacy_insufficient_stars(local_db):
|
||||
user = _reset("unit_a")
|
||||
_set(user, stars=0, legacy_multiplier=0)
|
||||
with pytest.raises(GameError):
|
||||
store.upgrade_legacy(user, "multiplier")
|
||||
|
||||
|
||||
# --- stealing ----------------------------------------------------------------
|
||||
|
||||
|
||||
def _ripen_past_grace(user, slot=0):
|
||||
farm = store.get_farm(user["uid"])
|
||||
past = (datetime.now(timezone.utc) - timedelta(days=1)).isoformat()
|
||||
plot = store._plot_at(farm["uid"], slot)
|
||||
get_table("game_plots").update(
|
||||
{"uid": plot["uid"], "planted_at": past, "ready_at": past}, ["uid"]
|
||||
)
|
||||
|
||||
|
||||
def test_steal_transfers_coins_and_clears_plot(local_db):
|
||||
owner = _reset("unit_owner")
|
||||
thief = _reset("unit_thief", coins=0)
|
||||
store.plant(owner, 0, "shell")
|
||||
_ripen_past_grace(owner)
|
||||
result = store.steal(thief, owner, 0)
|
||||
assert result["coins"] > 0
|
||||
assert _coins(thief) == result["coins"]
|
||||
farm = store.get_farm(owner["uid"])
|
||||
assert (store._plot_at(farm["uid"], 0).get("crop_key") or "") == ""
|
||||
|
||||
|
||||
def test_steal_protected_within_grace(local_db):
|
||||
owner = _reset("unit_owner")
|
||||
thief = _reset("unit_thief")
|
||||
store.plant(owner, 0, "shell")
|
||||
farm = store.get_farm(owner["uid"])
|
||||
past = (datetime.now(timezone.utc) - timedelta(seconds=5)).isoformat()
|
||||
plot = store._plot_at(farm["uid"], 0)
|
||||
get_table("game_plots").update(
|
||||
{"uid": plot["uid"], "planted_at": past, "ready_at": past}, ["uid"]
|
||||
)
|
||||
with pytest.raises(GameError):
|
||||
store.steal(thief, owner, 0)
|
||||
|
||||
|
||||
def test_steal_cooldown_blocks_second_raid(local_db):
|
||||
owner = _reset("unit_owner")
|
||||
thief = _reset("unit_thief", coins=0)
|
||||
store.plant(owner, 0, "shell")
|
||||
_ripen_past_grace(owner)
|
||||
store.steal(thief, owner, 0)
|
||||
store.plant(owner, 0, "shell")
|
||||
_ripen_past_grace(owner)
|
||||
with pytest.raises(GameError):
|
||||
store.steal(thief, owner, 0)
|
||||
|
||||
|
||||
# --- backwards compatibility -------------------------------------------------
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user