fix(home): server-owned growth window; expose days

Home omits growth_days; backend auto (or home_growth_days 1/7) picks
the window. Response includes days alongside growth_days. Growth榜 link
uses the returned days. Non-growth sorts treat omitted/auto as 7.
This commit is contained in:
bot-ci committed 2026-11-02 10:05:00 +08:00
1 parent 9163f47b76
commit 297d9279d8
5 files changed
+52 -28

No files matched your search

+9 -2
View File
@@ -106,6 +106,8 @@ def test_growth_and_cold_start():
try:
growth = q.list_videos(sort="growth", growth_days=2)
assert growth["available"] is True
assert growth["days"] == 2
assert growth["growth_days"] == 2
assert {item["aid"] for item in growth["items"]} == {101, 102}
first = next(item for item in growth["items"] if item["aid"] == 101)
assert first["growth"]["available"] is True
@@ -570,15 +572,19 @@ def test_growth_auto_falls_back_to_one_day():
with tempfile.TemporaryDirectory() as tmp:
db, q = setup(tmp)
try:
auto = q.list_videos(sort="growth", growth_days="auto", page_size=6)
# 省略 growth_days 与显式 auto 等价:后端决定窗口并回传 days
auto = q.list_videos(sort="growth", page_size=6)
assert auto["available"] is True
assert auto["growth_days"] == 1
assert auto["days"] == 1
assert {item["aid"] for item in auto["items"]} == {101, 102}
first = next(item for item in auto["items"] if item["aid"] == 101)
assert first["growth"]["delta"] == 100 # 相邻日
forced7 = q.list_videos(sort="growth", growth_days=7)
assert forced7["available"] is False
assert forced7["days"] == 7
assert forced7["growth_days"] == 7
assert "至少 8 天快照" in forced7["reason"]
# 配置钉死 7 天:auto 不再降级
@@ -589,8 +595,9 @@ def test_growth_auto_falls_back_to_one_day():
target = max(path.stat().st_mtime_ns, time.time_ns()) + 1_000_000
os.utime(path, ns=(target, target))
DASHBOARD_CACHE.clear()
pinned = q.list_videos(sort="growth", growth_days="auto")
pinned = q.list_videos(sort="growth") # omit → auto → 配置钉死 7
assert pinned["growth_days"] == 7
assert pinned["days"] == 7
assert pinned["available"] is False
finally:
db.close()