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()
+11 -1
View File
@@ -108,8 +108,11 @@ def test_readonly_routes_and_static():
status, _, payload = running.request("/api/videos")
assert status == 200
items = json.loads(payload)["data"]["items"]
heat_payload = json.loads(payload)["data"]
items = heat_payload["items"]
assert items and items[0]["aid"] == 102
# 非增长排序:省略 growth_days 时 days/growth_days 回落为 7,不做 7→1
assert heat_payload["days"] == heat_payload["growth_days"] == 7
status, _, payload = running.json("/api/videos?year=2026")
assert status == 200
@@ -120,6 +123,13 @@ def test_readonly_routes_and_static():
assert status == 200
assert payload["data"]["year"] == 2026
# 首页形态:省略 growth_days → 后端 auto,响应带 days/growth_days
status, _, payload = running.json("/api/videos?sort=growth&limit=6")
assert status == 200
growth = payload["data"]
assert growth["days"] == growth["growth_days"] == 1
assert growth["available"] is True
status, _, payload = running.request("/api/ups")
assert status == 200
assert json.loads(payload)["data"]["sort"] == "efficiency"