Commit graph

1028 commits

Author SHA1 Message Date
f2f273ebaa
bump GIT_HASH to 4fcd1ea 2026-05-09 19:06:43 -04:00
4fcd1eacaa
MPS-21: lib/offer.py — counter/accept/decline/expire state machine
Pure validators:
- validate_actor_turn: actor's party must match offer.current_party;
  terminal-state offers reject all actions
- validate_round_cap: rejects when round_count >= shop.offer_max_rounds
  (forces accept/decline at the cap)
- validate_floor: silent reject below shop.offer_min_in_cents
- auto_resolve_open: classifies a new offer as accept/decline/queue
  using shop's auto_accept_threshold_pct (default 95) and
  auto_decline_threshold_pct (default 50); list_price=0 always queues

Orchestrators (write OFFER_EVENT_* rows for audit log):
- open_offer: writes offer + OPEN event; applies auto-accept/decline
  thresholds before queuing seller; expires_timestamp = now + shop's
  expiration_hours
- counter_offer: flips current_party, increments round_count, sets
  state COUNTERED, persists actor's message
- accept_offer: terminal — caller's responsibility to write a cart
  line item at offer.current_amount_in_cents
- decline_offer: terminal
- withdraw_offer: terminal; buyer-only (caller validates identity)
- expire_offer: idempotent system action — flips non-terminal offers
  past expires_timestamp to EXPIRED
- mark_paid: cart-success hook; ACCEPTED → PAID; raises if not in
  ACCEPTED state

OfferRejected exception carries reason in .args[0].

Self-offer (buyer == seller) blocking is the view layer's job — same
pattern as auctions.

Tests:
- 12 unit tests: validate_actor_turn (terminal/wrong-party/correct-party),
  validate_round_cap (at-or-above/below), validate_floor (none/below/at),
  auto_resolve_open (accept/decline/queue/free-product)
- 10 integration tests: auto-accept high offer, auto-decline low offer,
  queue mid-range offer, floor enforcement, full negotiation flow
  (open → seller counter → buyer counter → seller accept), round cap,
  decline terminal, withdraw, expire only past expiration, mark_paid
  only after accept

Total: 881 tests pass (was 859 + 22).
2026-05-09 19:06:36 -04:00
a75cacdfcb
bump GIT_HASH to 5b8f6bc 2026-05-09 18:50:05 -04:00
5b8f6bcb58
MPS-20: lib/auction.py — bid placement, proxy, soft-close
Pure functions:
- validate_bid: state must be ACTIVE; first bid >= start_price; subsequent
  bids >= current_high + bid_increment; positive integer; max_proxy >= amount
- is_within_soft_close: now_ms inside (end - soft_close_seconds*1000, end]
- extended_end_timestamp: now_ms + soft_close_seconds*1000
- resolve_proxy: eBay-style — higher proxy wins; loser auto-bids defending
  bidder up to min(loser_proxy + increment, winner_proxy); ties go to
  the existing top (first-in wins)

Orchestrator place_bid:
- writes the new bid, marks the prior winning bid is_winning=False with
  outbid_timestamp, applies proxy resolution to choose visible amounts,
  applies soft-close to extend end_timestamp when bid lands in window,
  bumps auction.updated_timestamp

BidRejected exception carries reason in .args[0].

Tests:
- 16 unit tests: validate_bid matrix (state, start_price, increment,
  proxy >= amount), soft-close window math, 6 proxy resolution edge
  cases (no proxy, defending proxy auto-increments, breaking through
  top proxy, tie tie-break, capped at ceiling)
- 8 integration tests: first bid wins, increment floor, outbid marks
  prior bid is_winning=False, exactly-one-winner invariant, proxy
  defending bidder auto-increments, soft-close fires only inside window,
  inactive auction rejects

Self-bid (bidder == seller) blocking is the view layer's responsibility —
the pure validate_bid does not have visibility into seller identity.

Total: 859 tests pass (was 835 + 24).
2026-05-09 18:49:55 -04:00
2f1a41d089
bump GIT_HASH to 80b4fa6 2026-05-09 18:31:40 -04:00
80b4fa6698
MPS-20 + MPS-21: foundation — pricing_mode + auction/offer models
Auction (MPS-20) and make-an-offer (MPS-21) modes share a Product.pricing_mode
column so a single migration adds the foundation for both.

Schema:
- mps_product.pricing_mode (Integer, default 0): 0=fixed, 1=auction,
  2=auction+buy_now, 3=offer, 4=offer+buy_now
- mps_product.allow_offers (Boolean nullable): per-product override of
  shop default; NULL = inherit shop.offer_enabled
- mps_shop: 7 offer-* settings columns (enabled, min, auto-accept/decline
  thresholds, expiration, max rounds, min buyer age)
- 5 new tables: mps_auction, mps_bid, mps_auction_watcher,
  mps_offer, mps_offer_event

Models:
- MpsAuction: state machine helpers (is_draft/active/ended/settled/etc.),
  current_high_in_cents (queries top bid), reserve_met, time_remaining_ms,
  has_buy_now, has_reserve, min_next_bid_in_cents
- MpsBid: amount + max_proxy_in_cents (proxy bidding ceiling) + is_winning
  flag the bid resolution code will flip
- MpsAuctionWatcher: per-user notification preferences
- MpsOffer: state machine (pending/countered/accepted/declined/expired/
  withdrawn/paid), waiting_on_buyer/seller, time_remaining_ms, is_expired
- MpsOfferEvent: audit log row per action (open/counter/accept/etc.)

Product gets is_fixed_price / is_auction / is_buy_now_allowed /
is_offer_mode / offers_allowed helpers — offers_allowed resolves the
per-product override + shop default.

Migration is idempotent (table_exists / column_exists guards) since
make init-db creates tables from models.

Tests:
- 17 unit tests in test_models.py (state helpers, pricing_mode classifiers,
  inheritance rules)
- 10 integration tests in test_integration.py (DB persistence, cascade
  delete bids/watchers/events when parent deleted, unique product_id
  on auction, defaults applied)

Functional tests defer to commits 4-5 (auction views, offer views).
2026-05-09 18:31:29 -04:00
98352496a9
bump GIT_HASH to 2659ebd 2026-05-09 16:51:38 -04:00
2659ebdcbe
MPS-22: kill-switch feature flags for karaoke + torrent
Karaoke (MPS-18) and torrent (MPS-19) are broken in production. Adding
two global feature flags off by default so neither feature surfaces in
UI or accepts route traffic until they're fixed.

Pattern mirrors app.features.popout_player.enabled — reified request
properties (request.karaoke_enabled, request.torrent_enabled) read from
ini settings. Templates wrap UI in {% if %}, views return HTTPNotFound
on form sections + routes, view contexts blank out feature-specific
keys when flag off so SPA navigation does not try to render them.

test.ini sets both flags True so existing feature tests keep working.
TestKillSwitches builds a fresh app with both False and verifies the
off path: form_section POSTs return 404, settings page omits sections,
karaoke route 404s, landing page omits karaoke marketing copy.

GET /s/{shop_id}/torrent-backfill-status is shadowed by an earlier
shop_slug catch-all route in production — pre-existing routing defect
that MPS-19 needs to fix when it lands.
2026-05-09 16:51:24 -04:00
b3d9b2b39c
docs: tickets MPS-18..21 — karaoke/torrent fixes + auction/offer proposals
MPS-18: diagnose and fix broken karaoke vocal isolation pipeline.
MPS-19: diagnose and fix broken torrent / magnet link distribution.
MPS-20: propose eBay-style auction house mode (bidding, reserve,
soft-close, proxy, buy-now).
MPS-21: propose make-an-offer mode (counter/accept/decline/expire
state machine, auto-accept and auto-decline thresholds).

Each ticket carries proposal, full file list, models, state machine,
GTM plan, and unit/integration/functional test requirements.

architecture.md ticket index extended with MPS-17 (was missing) plus
the four new tickets.
2026-05-09 16:13:57 -04:00
f38e9d58ec
modified: .gitignore 2026-05-09 11:31:01 -04:00
6f5c6be3a5 bump GIT_HASH to e159d2f 2026-04-23 17:37:51 -04:00
e159d2f2bf fix: consistent section order across mobile, desktop, and cinema modes
Mobile previously placed product-right (price, download, Up Next)
as the 2nd section, right after images — a different reading flow
from desktop and cinema modes, which keep description + comments
above/alongside product-right.

Unified order for every mode and viewport:

  1. images         (sticky video/cover on mobile + desktop watch)
  2. description
  3. comments
  4. product-right  (price, download, Up Next)

Desktop normal: column 1 = images → description → comments (stacked),
column 2 = product-right (spans all rows on the right).

Desktop cinema: row 1 = images full-width, row 2 = content (description
+ comments stack) on the left, product-right on the right.

Mobile normal: all four stacked single-column in that order. Cinema
stays a no-op below 800px; the classes exist but match no rules and
the page falls through to the consistent mobile watch-mode layout.

CLAUDE.md mobile layout section updated to match.
2026-04-23 17:37:45 -04:00
795b845cf9 bump GIT_HASH to 7fa9c15 2026-04-23 13:58:28 -04:00
7fa9c15a03 fix: cinema mode is no-op on mobile; section order matches normal mode
Mobile (<800px) never really needed a different cinema layout — the
normal watch-mode mobile rules already stack images, purchase,
description, and comments in a single column with full-viewport-width
media. Cinema was re-ordering those sections (putting purchase AFTER
description/comments) and creating an inconsistency between cinema
and normal modes on the same device.

Fix: gate every cinema layout rule on @media (min-width: 800px). Below
that the .cinema-mode.cinema-wide classes exist but match no layout
rules, and the page falls through to normal mobile watch-mode.

JS: isViewportWideEnoughForCinema() uses the same 800px boundary to
decide whether to relocate the hamburger+Edit taskbar into the
sidebar. A debounced resize listener re-runs applyCinemaMode() so
the layout flips cleanly when the viewport crosses the boundary.
2026-04-23 13:58:21 -04:00
ababe32a0a bump GIT_HASH to f57abd5 2026-04-22 17:41:48 -04:00
f57abd5193 fix: cinema 2-col at 800px, comment section breathing room, button gap
Three polish tweaks for cinema mode in narrow desktop panels:

1. 2-column layout kicks in at >=800px instead of >=960px. Cinema's
   video already fills the full width, so the content | purchase
   split below it doesn't need a typical desktop-wide viewport —
   it works fine on smaller panels. This removes the 800-960px dead
   zone where cinema-wide was still single-column stacking.

2. Comments get 24px margin-top + 20px padding-top + a top border so
   they read as their own section instead of running continuous into
   the description above and the sidebar controls below.

3. Stacked sidebar buttons (hamburger, Edit, Download) now have an
   8px margin-bottom between each so they don't look shoulder-to-
   shoulder. Inherits evenly from the task-bar grid gap.
2026-04-22 17:41:41 -04:00
3c6c579b73 bump GIT_HASH to ba424d5 2026-04-22 17:24:40 -04:00
ba424d537a fix: uniform button shape in cinema sidebar
Hamburger, Edit, and Download now all render as the same component
in the cinema sidebar — full column width, same padding (14px 16px),
same font size, same line height. mps-button-small's narrow min-width
was making Edit look like a leftover chip next to the full-width
hamburger and Download buttons; overridden in the cinema sidebar
scope only.

Task-bar grid gap bumped to 8px so hamburger + Edit don't touch
each other, and their nested padding zeroed so spacing lives in
the outer grid gap rather than in mixed inline padding.
2026-04-22 17:24:35 -04:00
d6487f8861 bump GIT_HASH to 92a3050 2026-04-22 15:46:40 -04:00
92a305072e feat: cinema only activates for landscape media (aspect > 1)
Portrait and square media stay in the normal watch layout even when
the Cinema toggle is on — tall phone videos no longer get stretched
into a skinny column on a wide screen. Only wider-than-square media
triggers the layout adjustment that makes wide/ultrawide content
fill the horizontal viewport.

Two-class gate:
  .cinema-mode       — user intent (from the toggle)
  .cinema-wide       — runtime state (current media aspect > 1)

CSS layout rules now require BOTH classes. When cinema is on but
media is portrait, .cinema-mode is on and .cinema-wide is off, and
the selectors don't match — normal watch layout applies.

Aspect detection reads video.videoWidth/videoHeight or
img.naturalWidth/naturalHeight. Unknown dimensions (metadata not
yet loaded) defaults to not wide; a loadedmetadata / img.load
listener re-invokes applyCinemaMode once real dimensions are known.

Taskbar relocation also gated on cinema-wide — portrait doesn't
steal the hamburger + Edit from their normal home.
2026-04-22 15:46:33 -04:00
aa72430323 bump GIT_HASH to 872a712 2026-04-22 15:43:18 -04:00
872a7121f8 feat: cinema mode — hamburger + Edit into sidebar above Download
Two cinema-mode polishes:

1. Top task bar (hamburger / shop name / Edit button) relocates into
   .product-right above the .well on cinema-on. Cached original parent
   + next sibling at init lets us put it back on cinema-off. Moved
   within the same DOM subtree that survives SPA nav so it persists
   across product changes. CSS stacks its children vertically inside
   the sidebar instead of the horizontal strip shape up top.

2. The 'click image to open in new window' wrapper link on static
   products (images, PDFs) is redundant in cinema mode since media
   already fills the viewport. pointer-events:none disables the
   click without removing the anchor from the DOM.
2026-04-22 15:43:12 -04:00
f6654ba7d2 bump GIT_HASH to 23dd740 2026-04-22 15:30:32 -04:00
23dd740b52 fix: Autoplay rightmost in toggle row (Fresh | Reverse | Cinema | Autoplay) 2026-04-22 15:30:26 -04:00
4b5422266d bump GIT_HASH to 1386fc6 2026-04-22 15:18:24 -04:00
1386fc660c fix: cinema — description+comments in one grid cell, no row stretch
Previously purchase (ring sidebar) spanned grid rows 2 and 3. When
Up Next was tall and description was short, grid distributed the
spanning column's height across both rows — description sat at top
of a stretched row 2 with hundreds of pixels of empty space before
comments.

New structure: wrap description + comments in .cinema-content-stack.
Outside cinema mode the wrapper is display:contents (transparent,
zero effect). In cinema mode it becomes a single grid cell containing
description + comments as an internal stack. Main grid is now just
two rows: images (full width) then content | purchase.

Row 2 height = max(content column, purchase column). If purchase is
taller, content stack still starts at top, and description + comments
stay glued together at the top of the column — comments is reachable
without scrolling past a dead zone.
2026-04-22 15:18:17 -04:00
eb9dcf6df4 bump GIT_HASH to ace7bc0 2026-04-22 14:18:36 -04:00
ace7bc0475 fix: cinema mode works at every viewport size (no 800-960px dead zone)
Cinema rules previously lived only inside @media (min-width: 960px).
Between 800px and 960px the rules silently vanished and section.two-column
fell back to natural block flow — description, comments, download,
and Up Next stacked chaotically while the video floated elsewhere.
Split-screen viewports and tablet widths hit this gap.

Base cinema rules now sit outside any media query:
  narrow: single column — video > description > comments > purchase
  >= 960px: 2fr 1fr — video full-width top, description+comments
             left column, product-right (ring+download) right column

Video sizing (width:100% + max-height:92vh + object-fit:contain)
applies at all sizes.
2026-04-22 14:18:31 -04:00
54d0c944d8 bump GIT_HASH to 8b9b411 2026-04-22 14:07:49 -04:00
8b9b411ec0 fix: all 4 toggles on one row, nav fills bottom row cleanly
Cinema toggle kept flowing onto its own row because ring-header-controls
was 3-col. Bumped to 4-col so row 1 fits Fresh / Reverse / Autoplay /
Cinema together.

Nav buttons (Prev / Random / Next) now use explicit grid-columns —
Next spans cols 3→end — so there's no empty fourth column on the
right edge. Karaoke button keeps its full-row span via grid-column: 1/-1.
2026-04-22 14:07:43 -04:00
2422e5feb1 bump GIT_HASH to 157134a 2026-04-22 13:29:45 -04:00
157134ab60 fix: cinema mode — description beside ring, comments under description
Cinema grid now mirrors the non-watch desktop layout below the video:
  row 1: video (full viewport width)
  row 2: description | product-right (price + download + Up Next)
  row 3: comments   | product-right (continues, spans 2 rows)

Previously description took full width and purchase/comments
shared row 3. Fox wants the ring visible alongside the description
so viewers see Up Next while reading, and comments stacked below
description in the same column.
2026-04-22 13:29:38 -04:00
1ee956b95f bump GIT_HASH to 09f9de4 2026-04-21 18:58:35 -04:00
09f9de4636 feat: deploy + reforge bust client ring cache (HTML + localStorage)
Two paths to stale client state, both closed:

1. HTML cache — content.py and product.py now send Cache-Control:
   no-store, must-revalidate on responses. Browsers were holding
   onto rendered sidebar HTML from before the pocket fix deployed,
   producing phantom 'this didn't work' reports.

2. localStorage cache — shop.json_discovery_ring + GIT_HASH are
   hashed into a short cache_version token, stamped on every page
   (<meta name='mps-cache-version'>) and every watch_json response.
   watch.js stores it in localStorage; on page load and every SPA
   nav, mismatch triggers removal of watchRing, watchRingPosition,
   watchRingHistory, watchRingLoops, watchQueue before anything
   reads them.

watch_json error responses (404 no media, 403 not public) also
carry cache_version so clients can flush even when the target
product can't be played.

Tests:
  - test_models.py TestCacheVersion: 6 unit tests (stability, ring
    content change, ring order change, empty ring, none shop,
    GIT_HASH flip via patch).
  - test_functional.py: 3 functional tests (content page sends
    no-store + meta tag, watch_json error carries cache_version,
    cache_version shifts after reforge).

All 370 model+integration tests + 8 new functional tests green.
2026-04-21 18:58:30 -04:00
2a9e993d5d bump GIT_HASH to 690f945 2026-04-21 18:30:37 -04:00
690f945f70 feat: validate_discovery_ring health check + mod-only diagnostic endpoint
Adds validate_discovery_ring(shop) in models/shop.py that returns a
dict diagnosing four ring topology defects:

  - duplicates: IDs appearing more than once in ring (greedy-walk bug)
  - orphans: public products missing from ring (added after reforge)
  - stale: ring IDs no longer public/present (deleted or unlisted
    after reforge — the 'pocket' condition we just patched)
  - length_mismatch: ring_length != public_count

Wired into reforge_discovery_ring_async — anomalies log a warning
after each background reforge, making silent drift visible.

New route /s/{shop_id}/ring/health.json exposes the validator to
shop mods (403 for anon and non-editor users, 404 for missing shop).

Tests across all three layers:
  - Unit (test_models.py, 7 tests): mocked shop.products, each
    anomaly class verified in isolation.
  - Integration (test_integration.py, 4 tests): real shop + products
    + reforge, simulates visibility changes and late additions,
    confirms reforge heals the ring.
  - Functional (test_functional.py, 5 tests): auth required, mod
    ownership enforced, 404 on unknown shop, real-world stale
    detection through the HTTP endpoint.
2026-04-21 18:30:31 -04:00
ace97a1ef6 bump GIT_HASH to 81a5de4 2026-04-21 18:20:35 -04:00
81a5de4ce1 fix: ring 'pocket' — fill gaps from deleted/unlisted products
get_ring_related_products walked exactly backward+forward positions
in the ring and silently dropped entries whose IDs no longer resolved
to visible products. Result: sparse offsets like [-2, -1, 1, 5, 28]
visible in Up Next — a 'pocket' of live items in an otherwise stale
ring slice.

New behavior: fetch every ring product once (bulk query), keep only
visibility==1, then walk further along the ring to collect the
requested backward/forward VALID neighbors. Offsets are renumbered
contiguously (-N..-1, 1..N). Pocket is filled by skipping past
deleted/unlisted entries until we have the requested count or
exhaust the ring.

Ring traversal on the client (ringPosition + direction) uses ring
indices directly and is unaffected — only the rendered Up Next
sidebar slice is densified.
2026-04-21 18:20:28 -04:00
3470d747f3 bump GIT_HASH to 2464d87 2026-04-21 18:12:41 -04:00
2464d8722b fix: cinema mode actually fills viewport width (override media-sizing rule)
Previous cinema CSS used width:auto which pinned small-resolution videos
to their natural size, leaving huge side-margins on wide displays.

Cinema explicitly wants edge-to-edge video: width:100%, height:auto,
max-height:92vh, object-fit:contain. This trades a small letterbox on
extra-wide viewports for real full-width rendering — intentional
override of the CLAUDE.md 'never combine width:100% with max-height'
rule, which exists to prevent dead whitespace on images. For cinema
the tradeoff is reversed: fox wants big video, accepts edge letterbox.
2026-04-21 18:12:35 -04:00
c5b0637d50 bump GIT_HASH to ee1d642 2026-04-21 17:36:59 -04:00
ee1d642d92 feat: cinema mode — full-width video, Up Next + Download beside comments
New Cinema toggle alongside Fresh/Reverse/Autoplay. When on, adds
.cinema-mode class to section.two-column, restructuring the grid:

  row 1: video (full viewport width, max 85vh, preserved aspect)
  row 2: description (full width)
  row 3: product-right (price + download + Up Next) | comments

Uses display:contents on .watch-left so watch-mode children bubble
up as direct grid items. Video sizing follows CLAUDE.md media rule
(width:auto + max-width:100% + max-height:85vh) to avoid letterbox
whitespace.

Preference persisted in localStorage (watchCinemaMode). Toggle
handler attached in rebindToggles; class applied on init and on
every toggle change.
2026-04-21 17:36:53 -04:00
78378f78d6 bump GIT_HASH to a2ffcdf 2026-04-21 14:38:04 -04:00
a2ffcdfea2 fix: karaoke button on its own row, separated from Prev/Random/Next
Karaoke toggle now spans full width of ring-header-controls grid,
pushing nav buttons (Prev/Random/Next) to their own 3-column row.
When karaoke is display:none (non-eligible shops), nav buttons
flow naturally into row 2. No template changes.
2026-04-21 14:37:53 -04:00
e055619037 bump GIT_HASH to b09d1fc 2026-04-21 14:23:11 -04:00
b09d1fc739 fix: watch-mode Next/autoplay follow one true ring, honor Fresh toggle
Every forward path through the ring now uses a single selector:
  chooseNextInRing() = freshMode ? getNextUnwatchedItem() : getNextItem()

Next button, autoplay countdown, DJ crossfade target, preload, and
countdown-play-now all route through it. Previously, Next button
hardcoded skipToNextUnwatched() regardless of Fresh toggle — user
would see offset +1 in sidebar but land on a farther unwatched item.

navigateToNext and completeDjFadeout now sync ringPosition via
indexOf(target) instead of blindly advancing by +direction — necessary
when Fresh mode jumps past watched items.
2026-04-21 14:22:59 -04:00
206ff49e68 docs: never broad-grep config files — rule for operation voyeur 2026-04-16 19:31:52 -04:00
e8d4c9a0d9 bump GIT_HASH to 7d7d4a3 2026-04-16 19:26:00 -04:00
7d7d4a371a fix: pass request.app (not registry.settings) to capture_karaoke_config
KeyError 'bucket.secure_uploads.region' in the detached karaoke child
on prod. production.ini stores keys with the app. prefix
(app.bucket.secure_uploads.region) and a request hook strips that
prefix into a dict attached as request.app. request.registry.settings
still carries the raw, prefixed keys.

The upload-time and on-demand karaoke call sites were passing
request.registry.settings; capture_karaoke_config expected the
stripped dict. Dev .ini happens to match both layouts which masked
this — prod raised KeyError and the response 502'd.

Switch both call sites to request.app (matches the pattern used by
backfill_karaoke_async and backfill_mirror_async) and document the
expected shape on capture_karaoke_config.
2026-04-16 19:25:48 -04:00
a9345bb7ea bump GIT_HASH to 806a97b 2026-04-16 15:45:37 -04:00