All three shared a shape: the symptom was invisible from the data, so every acceptance run stayed green while the VM was failing. daily_state still called _ensure_daily_news_reading, removed when the news feature was retired. The VM threw AttributeError 14 times in three hours and marked the "today's schedule" maintenance step failed, but the crash sits after the plan is saved -- so the stored plan always looked correct. Removed the call and added a repo-wide scan rather than a single-point assertion, since this kind of residue is by definition somewhere you did not look. enable_memory_companion_bridge, the master switch for the whole archive chain, was never added to _conf_schema.json. _cfg_bool falls back to True, so the feature worked and only its operability was missing -- nothing could have failed. It now sits in the visible external_memory_config group, with an assertion that _flat_get still resolves it by flat key. A fallback plan carried today's date, and all three reuse branches key on the date alone, so one startup timing hiccup froze a template plan into the day and archived it as real. source="fallback" was produced and never consumed; now a fallback can be upgraded once the provider is back, capped at three attempts and bucketed per day. Also fixed two test files whose classes sat after the __main__ guard (silently dropped when run directly) and the retired-config prefix list, which only listed the uppercase WEB_EXPLORATION_ form and missed the lowercase schema keys. VM after restart: 0 AttributeError, 0 ERRO/Traceback, plan intact at v2/llm, switch materialised as True. Companion suite 218 passed, joint E2E 135/135. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
104 行
4.7 KiB
Python
104 行
4.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""四段式窗口归类回归。
|
|
|
|
总览时间轴、运维页「当前时间段」、归档里的窗口快照此前各算各的,
|
|
现在统一走 agenda_contracts.window_for_minutes。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import pathlib
|
|
import sys
|
|
import unittest
|
|
from datetime import datetime, timedelta, timezone
|
|
|
|
# pytest 会把插件根目录放进 sys.path,直跑单文件不会——不补这一句,
|
|
# 「python tests/xxx.py」这条排查口径直接 ModuleNotFoundError。
|
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
|
|
|
from agenda_contracts import ( # noqa: E402
|
|
WINDOW_DEFINITIONS,
|
|
WINDOW_SLUGS,
|
|
window_for_datetime,
|
|
window_for_minutes,
|
|
window_for_plan_minutes,
|
|
)
|
|
|
|
TZ = timezone(timedelta(hours=8))
|
|
|
|
|
|
class WindowForMinutesTests(unittest.TestCase):
|
|
def test_each_window_boundary(self):
|
|
cases = [
|
|
(0, "深夜"), (5 * 60 + 59, "深夜"), (22 * 60, "深夜"), (23 * 60 + 59, "深夜"),
|
|
(6 * 60, "早晨"), (11 * 60 + 59, "早晨"),
|
|
(12 * 60, "下午"), (17 * 60 + 59, "下午"),
|
|
(18 * 60, "晚上"), (21 * 60 + 59, "晚上"),
|
|
]
|
|
for minutes, expected in cases:
|
|
with self.subTest(minutes=minutes):
|
|
self.assertEqual(window_for_minutes(minutes), expected)
|
|
|
|
def test_cross_midnight_offset_is_normalised(self):
|
|
"""跨零点的段带 +1440 偏移,必须先取模再归类。"""
|
|
self.assertEqual(window_for_minutes(24 * 60 + 30), "深夜")
|
|
self.assertEqual(window_for_minutes(24 * 60 + 7 * 60), "早晨")
|
|
|
|
def test_invalid_input_returns_empty(self):
|
|
for value in (None, "", "abc", object()):
|
|
self.assertEqual(window_for_minutes(value), "")
|
|
|
|
def test_every_window_has_a_slug(self):
|
|
for name, _start, _end in WINDOW_DEFINITIONS:
|
|
self.assertIn(name, WINDOW_SLUGS)
|
|
self.assertRegex(WINDOW_SLUGS[name], r"^[a-z_]+$")
|
|
|
|
def test_agrees_with_window_for_datetime(self):
|
|
"""与既有的 datetime 版判定必须一致,否则页面和归档又会各说各的。"""
|
|
for hour in range(24):
|
|
for minute in (0, 30, 59):
|
|
moment = datetime(2026, 7, 27, hour, minute, tzinfo=TZ)
|
|
expected = window_for_datetime(moment)[0]
|
|
with self.subTest(t=f"{hour:02d}:{minute:02d}"):
|
|
self.assertEqual(window_for_minutes(hour * 60 + minute), expected)
|
|
|
|
|
|
class WindowForPlanMinutesTests(unittest.TestCase):
|
|
"""跨午夜归属:同一份计划里的两个「深夜」分属两个日程日。"""
|
|
|
|
def test_early_morning_belongs_to_previous_night(self):
|
|
self.assertEqual(window_for_plan_minutes("2026-07-27", 30), ("深夜", "2026-07-26"))
|
|
self.assertEqual(window_for_plan_minutes("2026-07-27", 5 * 60 + 59), ("深夜", "2026-07-26"))
|
|
|
|
def test_late_evening_belongs_to_the_same_day(self):
|
|
self.assertEqual(window_for_plan_minutes("2026-07-27", 22 * 60), ("深夜", "2026-07-27"))
|
|
self.assertEqual(window_for_plan_minutes("2026-07-27", 23 * 60), ("深夜", "2026-07-27"))
|
|
|
|
def test_two_late_nights_in_one_plan_are_distinguishable(self):
|
|
"""时间轴上 00:30 与 23:00 都叫「深夜」,必须靠窗口日期分开。"""
|
|
early = window_for_plan_minutes("2026-07-27", 30)
|
|
late = window_for_plan_minutes("2026-07-27", 23 * 60)
|
|
self.assertEqual(early[0], late[0])
|
|
self.assertNotEqual(early[1], late[1])
|
|
|
|
def test_daytime_windows_keep_the_plan_date(self):
|
|
for minutes, expected in ((7 * 60, "早晨"), (13 * 60, "下午"), (19 * 60, "晚上")):
|
|
with self.subTest(minutes=minutes):
|
|
self.assertEqual(window_for_plan_minutes("2026-07-27", minutes), (expected, "2026-07-27"))
|
|
|
|
def test_wrapped_minutes_resolve_to_the_next_calendar_day(self):
|
|
"""计划里时间回绕到次日时,_normalized_plan_item_starts 会加 +1440。"""
|
|
self.assertEqual(window_for_plan_minutes("2026-07-27", 24 * 60 + 30), ("深夜", "2026-07-27"))
|
|
self.assertEqual(window_for_plan_minutes("2026-07-27", 24 * 60 + 7 * 60), ("早晨", "2026-07-28"))
|
|
|
|
def test_window_name_agrees_with_the_minutes_only_helper(self):
|
|
for minutes in range(0, 24 * 60, 17):
|
|
with self.subTest(minutes=minutes):
|
|
self.assertEqual(window_for_plan_minutes("2026-07-27", minutes)[0], window_for_minutes(minutes))
|
|
|
|
def test_invalid_input_returns_empty_pair(self):
|
|
self.assertEqual(window_for_plan_minutes("", 30), ("", ""))
|
|
self.assertEqual(window_for_plan_minutes("not-a-date", 30), ("", ""))
|
|
self.assertEqual(window_for_plan_minutes("2026-07-27", None), ("", ""))
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|