CI / lint (push) Successful in 3s
CI / extension-version (push) Successful in 3s
Build images / sign-extension (push) Successful in 4s
Build images / build-agent (push) Successful in 7s
CI / frontend-build (push) Successful in 21s
CI / backend-lint-and-test (push) Failing after 32s
Build images / build-web (push) Successful in 58s
Build images / smoke-web (push) Skipped
Build images / build-ml (push) Successful in 1m47s
Build images / promote (push) Skipped
CI / integration (push) Successful in 2m16s
A3 made a tier-gated source say "47 posts you can't see". The roster turns that into a reason: the membership ended, or the tier doesn't reach these posts, or it's a free follow. Rendered under A3's count in the health tooltip, quieter than the count it explains. FREE is a fourth case the step didn't enumerate, and it earns its own sentence. has_paid_access collapses "former patron" and "current free follower" to the same False, so deriving the reason from that boolean would tell a free follower "you're not a patron any more" - a false statement about a state they were never in. gated_reason reads the status axis first, calling has_paid_access with is_free_member forced off, then splits on the free flag. Silence is the default, and there are four ways into it: campaign absent from the roster, roster stale, platform never swept, status word not yet characterised. All four send null and the count stands alone. The frontend has no fallback sentence either - a default would turn "we don't know why" into a reason, which is the one thing this step must not do. The line that must not be crossed is pinned structurally rather than by inspection: test_no_fetch_path_can_read_the_roster walks the transitive first-party imports from the fetch roots and asserts the roster is unreachable. FC runs no local verification (rule 85), so a guard cannot be falsified by hand before it lands - it carries two positive controls instead, proving the walker finds roster imports that ARE there, one direct and one through a hop, so the real assertion can never pass merely because the walk resolved nothing. C4's identity loop moved to membership_roster.pair_sources_with_memberships when C5 became its second caller; two copies would let the Subscriptions row and the reconciliation card disagree about which creator a source IS. Three test files were each building PlatformMembership rows with their own drifting helper - consolidated into tests/roster_builders.py, same family as issue 3109. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SHQB1YukL3VyvMK8rcbmV9
304 lines
10 KiB
Python
304 lines
10 KiB
Python
"""Milestone 387 C4: what you pay for, against what FC actually follows.
|
|
|
|
The buckets are easy; the honesty is the work. `tracked_not_subscribed` is
|
|
computed from an ABSENCE — no membership matched this source — and three
|
|
different things produce that absence: the subscription really lapsed, the
|
|
sweep failed, or the creator renamed and this source has never been walked so
|
|
no exact id was ever cached. Only the first means what the bucket's name says.
|
|
|
|
So most of what follows pins refusals: the gate that empties the bucket when the
|
|
roster cannot be trusted, the tri-state that keeps "unknown" out of "lapsed",
|
|
and the per-row basis that stops the weakest claim sounding like the strongest.
|
|
"""
|
|
from datetime import timedelta
|
|
|
|
import pytest
|
|
|
|
from backend.app.models import Artist, MembershipSync, Source
|
|
from backend.app.services.membership_reconcile import (
|
|
BASIS_ABSENT_EXACT,
|
|
BASIS_ABSENT_HANDLE,
|
|
BASIS_LAPSED,
|
|
reconcile,
|
|
reconcile_all,
|
|
)
|
|
from backend.app.services.membership_roster import ROSTER_STALE_AFTER
|
|
from tests.roster_builders import membership as _membership
|
|
from tests.roster_builders import synced as _synced
|
|
|
|
pytestmark = pytest.mark.integration
|
|
|
|
|
|
async def _artist(db, name="Maewix"):
|
|
a = Artist(name=name, slug=name.lower().replace(" ", ""))
|
|
db.add(a)
|
|
await db.flush()
|
|
return a
|
|
|
|
|
|
async def _source(db, artist, *, url, platform="patreon", enabled=True, overrides=None):
|
|
s = Source(
|
|
artist_id=artist.id, platform=platform, url=url, enabled=enabled,
|
|
config_overrides=overrides,
|
|
)
|
|
db.add(s)
|
|
await db.flush()
|
|
return s
|
|
|
|
|
|
# --- the join --------------------------------------------------------------
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_a_cached_campaign_id_matches_regardless_of_the_url(db):
|
|
"""The exact key doing the work. The URL deliberately does NOT agree, so a
|
|
match here can only have come from the cached id."""
|
|
a = await _artist(db)
|
|
await _source(
|
|
db, a, url="https://www.patreon.com/an-old-handle",
|
|
overrides={"patreon_campaign_id": "c1"},
|
|
)
|
|
await _membership(db, campaign="c1")
|
|
await _synced(db)
|
|
await db.commit()
|
|
|
|
out = await reconcile(db, platform="patreon")
|
|
assert len(out["matched"]) == 1
|
|
assert out["matched"][0]["matched_by"] == "campaign"
|
|
assert out["subscribed_not_tracked"] == []
|
|
assert out["tracked_not_subscribed"] == []
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_the_handle_matches_when_nothing_has_been_cached_yet(db):
|
|
"""The fallback that exists because the id is only written AFTER a source
|
|
has been walked once — a freshly added source has no id at all."""
|
|
a = await _artist(db)
|
|
await _source(db, a, url="https://www.patreon.com/maewix")
|
|
await _membership(db, campaign="c1")
|
|
await _synced(db)
|
|
await db.commit()
|
|
|
|
out = await reconcile(db, platform="patreon")
|
|
assert len(out["matched"]) == 1
|
|
assert out["matched"][0]["matched_by"] == "vanity"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_the_c_and_cw_url_forms_both_reduce_to_the_vanity(db):
|
|
"""Patreon serves /c/<vanity> and /cw/<vanity> (#3886). A handle derivation
|
|
that missed these is the exact class of bug in #1485."""
|
|
a = await _artist(db)
|
|
await _source(db, a, url="https://www.patreon.com/c/maewix")
|
|
await _membership(db, campaign="c1")
|
|
await _synced(db)
|
|
await db.commit()
|
|
|
|
assert len((await reconcile(db, platform="patreon"))["matched"]) == 1
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_the_same_id_on_another_platform_is_not_a_match(db):
|
|
"""Nothing stops two platforms minting the same opaque id."""
|
|
a = await _artist(db)
|
|
await _source(
|
|
db, a, url="https://subscribestar.adult/maewix", platform="subscribestar",
|
|
overrides={"subscribestar_campaign_id": "c1"},
|
|
)
|
|
await _membership(db, campaign="c1", platform="patreon")
|
|
await _synced(db)
|
|
await db.commit()
|
|
|
|
out = await reconcile(db, platform="patreon")
|
|
assert out["matched"] == []
|
|
assert len(out["subscribed_not_tracked"]) == 1
|
|
|
|
|
|
# --- the gate: an untrustworthy roster accuses nobody -----------------------
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_a_stale_roster_produces_no_unaccounted_sources(db):
|
|
"""THE property. A sweep that stopped working a week ago must not turn every
|
|
source into "you no longer subscribe to this"."""
|
|
a = await _artist(db)
|
|
await _source(
|
|
db, a, url="https://www.patreon.com/tracked",
|
|
overrides={"patreon_campaign_id": "not-in-the-roster"},
|
|
)
|
|
await _synced(db, ago=ROSTER_STALE_AFTER + timedelta(days=1))
|
|
await db.commit()
|
|
|
|
out = await reconcile(db, platform="patreon")
|
|
assert out["fresh"] is False
|
|
assert out["tracked_not_subscribed"] == []
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_a_never_synced_roster_produces_no_unaccounted_sources(db):
|
|
"""Never-synced is not zero. With no MembershipSync row at all there is no
|
|
evidence of anything, and the bucket must stay empty."""
|
|
a = await _artist(db)
|
|
await _source(
|
|
db, a, url="https://www.patreon.com/tracked",
|
|
overrides={"patreon_campaign_id": "whatever"},
|
|
)
|
|
await db.commit()
|
|
|
|
out = await reconcile(db, platform="patreon")
|
|
assert out["fresh"] is False
|
|
assert out["last_success_at"] is None
|
|
assert out["tracked_not_subscribed"] == []
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_the_shape_is_complete_even_when_the_roster_is_stale(db):
|
|
"""A caller must be able to read any bucket unconditionally — the E2 lesson
|
|
where a shorter disabled payload broke an exact-shape assertion."""
|
|
await _synced(db, ago=ROSTER_STALE_AFTER + timedelta(days=1))
|
|
await db.commit()
|
|
|
|
out = await reconcile(db, platform="patreon")
|
|
assert set(out) == {
|
|
"platform", "fresh", "tracked_total", "last_success_at",
|
|
"subscribed_not_tracked", "tracked_not_subscribed", "matched",
|
|
"unidentified",
|
|
}
|
|
|
|
|
|
# --- what lands in the report-only bucket, and why -------------------------
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_a_lapsed_membership_reports_its_source_as_lapsed(db):
|
|
a = await _artist(db)
|
|
await _source(db, a, url="https://www.patreon.com/maewix")
|
|
await _membership(db, campaign="c1", status="former_patron")
|
|
await _synced(db)
|
|
await db.commit()
|
|
|
|
out = await reconcile(db, platform="patreon")
|
|
assert len(out["tracked_not_subscribed"]) == 1
|
|
assert out["tracked_not_subscribed"][0]["basis"] == BASIS_LAPSED
|
|
assert out["matched"] == []
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_a_known_id_missing_from_a_fresh_roster_is_the_strong_claim(db):
|
|
a = await _artist(db)
|
|
await _source(
|
|
db, a, url="https://www.patreon.com/tracked",
|
|
overrides={"patreon_campaign_id": "not-in-the-roster"},
|
|
)
|
|
await _synced(db)
|
|
await db.commit()
|
|
|
|
out = await reconcile(db, platform="patreon")
|
|
assert out["tracked_not_subscribed"][0]["basis"] == BASIS_ABSENT_EXACT
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_a_handle_only_source_makes_the_weaker_claim(db):
|
|
"""A renamed creator looks exactly like this, so it must not be phrased the
|
|
same way as the case where the id is known."""
|
|
a = await _artist(db)
|
|
await _source(db, a, url="https://www.patreon.com/some-old-name")
|
|
await _synced(db)
|
|
await db.commit()
|
|
|
|
out = await reconcile(db, platform="patreon")
|
|
assert out["tracked_not_subscribed"][0]["basis"] == BASIS_ABSENT_HANDLE
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_an_already_disabled_source_is_not_reported(db):
|
|
"""Telling the operator to stop following something they have already
|
|
stopped following is noise, not a finding."""
|
|
a = await _artist(db)
|
|
await _source(db, a, url="https://www.patreon.com/gone", enabled=False)
|
|
await _synced(db)
|
|
await db.commit()
|
|
|
|
assert (await reconcile(db, platform="patreon"))["tracked_not_subscribed"] == []
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_a_sidecar_anchor_is_unidentified_not_unsubscribed(db):
|
|
"""Pre-0030 synthetic anchors are not feeds. They cannot be matched, so they
|
|
are reported as unmatchable rather than filed under a verdict."""
|
|
a = await _artist(db)
|
|
await _source(db, a, url="sidecar:patreon:maewix", enabled=False)
|
|
await _synced(db)
|
|
await db.commit()
|
|
|
|
out = await reconcile(db, platform="patreon")
|
|
assert len(out["unidentified"]) == 1
|
|
assert out["tracked_not_subscribed"] == []
|
|
|
|
|
|
# --- what is offered for adoption, and what is withheld --------------------
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_a_membership_with_no_source_is_offered(db):
|
|
await _membership(db, campaign="c1")
|
|
await _synced(db)
|
|
await db.commit()
|
|
|
|
out = await reconcile(db, platform="patreon")
|
|
assert len(out["subscribed_not_tracked"]) == 1
|
|
assert out["subscribed_not_tracked"][0]["paid_access"] is True
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_a_lapsed_membership_is_not_offered_for_adoption(db):
|
|
"""Adding it would start a walk that can only fetch what is already public."""
|
|
await _membership(db, campaign="c1", status="former_patron")
|
|
await _synced(db)
|
|
await db.commit()
|
|
|
|
assert (await reconcile(db, platform="patreon"))["subscribed_not_tracked"] == []
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_an_unrecognised_status_is_still_offered(db):
|
|
"""None is not False. Withholding a membership because this build has not
|
|
been taught its status word would hide a real subscription."""
|
|
await _membership(db, campaign="c1", status="a_word_nobody_characterised")
|
|
await _synced(db)
|
|
await db.commit()
|
|
|
|
out = await reconcile(db, platform="patreon")
|
|
assert len(out["subscribed_not_tracked"]) == 1
|
|
assert out["subscribed_not_tracked"][0]["paid_access"] is None
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_a_free_follow_is_not_offered_as_a_subscription(db):
|
|
"""`is_free_member` is a second axis: a CURRENT membership nobody pays for
|
|
is not a subscription to adopt."""
|
|
await _membership(
|
|
db, campaign="c1", status="active_patron",
|
|
details={"campaign": {"vanity": "maewix"}, "is_free_member": True},
|
|
)
|
|
await _synced(db)
|
|
await db.commit()
|
|
|
|
assert (await reconcile(db, platform="patreon"))["subscribed_not_tracked"] == []
|
|
|
|
|
|
# --- the all-platforms payload ---------------------------------------------
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_a_platform_whose_sweep_never_succeeded_still_appears(db):
|
|
"""Deriving the platform list from memberships alone would drop exactly the
|
|
platform whose credential is broken — making it indistinguishable from one
|
|
FC was never asked about."""
|
|
db.add(MembershipSync(platform="patreon", last_error_type="PatreonAuthError"))
|
|
await db.commit()
|
|
|
|
out = await reconcile_all(db)
|
|
assert [p["platform"] for p in out["platforms"]] == ["patreon"]
|
|
assert out["platforms"][0]["fresh"] is False
|