fix: clear the three P0 defects that were bleeding in production
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>
这个提交存在于:
父节点
2518f7b6bf
当前提交
cdc402888b
共有 7 个文件被更改,包括 274 次插入 和 15 次删除
|
|
@ -5634,6 +5634,13 @@
|
|||
"type": "object",
|
||||
"hint": "统一接入已适配的外部长期记忆插件。当前支持“我会牢牢记住你”/MemoryCompanion。",
|
||||
"items": {
|
||||
"enable_memory_companion_bridge": {
|
||||
"description": "记忆插件桥接总闸",
|
||||
"type": "bool",
|
||||
"hint": "关闭后本插件不再向“我会牢牢记住你”写入任何内容,也不再读取记忆上下文:Bot 个人归档(日程计划、窗口快照、结算、日记、创作媒体等 12 类)全部停写,本组其余开关随之失效。仅在需要临时切断双插件联动时关闭。",
|
||||
"default": true,
|
||||
"condition": {}
|
||||
},
|
||||
"memory_companion_context_timeout_seconds": {
|
||||
"description": "记忆上下文超时(秒)",
|
||||
"type": "float",
|
||||
|
|
|
|||
|
|
@ -25,7 +25,18 @@ _PHOTO_REFERENCE_SUFFIXES = {".png", ".jpg", ".jpeg", ".webp"}
|
|||
# QQ 空间、新闻、主动搜索的实现早已在功能删减轮移除,只剩这些配置项还挂在设置页与命令里,
|
||||
# 用户点开会看到一堆开关,打开却什么也不会发生。按「只隐藏入口,不恢复、不删除旧数据」处理:
|
||||
# 从展示面过滤掉,配置文件里的旧值原样保留。
|
||||
RETIRED_FEATURE_CONFIG_PREFIXES = ("enable_qzone", "qzone_", "enable_news", "news_", "WEB_EXPLORATION_")
|
||||
# 网页探索的配置键两种大小写都有:手动配置面用 WEB_EXPLORATION_API_KEY 这类大写键,
|
||||
# _conf_schema.json 里则是 enable_web_exploration 这类小写键。原先只列了大写前缀,
|
||||
# 小写那批一个都没被过滤掉。前缀匹配区分大小写,两种都要写上。
|
||||
RETIRED_FEATURE_CONFIG_PREFIXES = (
|
||||
"enable_qzone",
|
||||
"qzone_",
|
||||
"enable_news",
|
||||
"news_",
|
||||
"WEB_EXPLORATION_",
|
||||
"enable_web_exploration",
|
||||
"web_exploration_",
|
||||
)
|
||||
|
||||
|
||||
def _is_retired_feature_config(key: str) -> bool:
|
||||
|
|
|
|||
|
|
@ -76,6 +76,9 @@ except Exception:
|
|||
# 对话 Provider 未就绪时最多跳过几轮日程生成。调度 tick 本身 300 秒一次,
|
||||
# 因此 5 轮 ≈ 每 5 分钟重试、共 5 次;超过则退回兜底并记错误,避免无限等待。
|
||||
DAILY_PLAN_PROVIDER_MAX_WAITS = 5
|
||||
# 当天已经落了兜底日程后,最多再尝试几次换成真实生成。防住「Provider 就绪但生成
|
||||
# 始终失败」时每个 tick 都重跑一遍模型。
|
||||
DAILY_PLAN_FALLBACK_RETRY_LIMIT = 3
|
||||
|
||||
from .constants import (
|
||||
DEFAULT_DAILY_PLAN_ITEMS,
|
||||
|
|
@ -444,6 +447,35 @@ class DailyStateMixin:
|
|||
if previous is None and upcoming is None: return {}
|
||||
return {"now_minutes": current.hour * 60 + current.minute, "previous": previous[2] if previous else None, "previous_age": int(max(0, (current - previous[0]).total_seconds() // 60)) if previous else None, "upcoming": upcoming[2] if upcoming else None, "upcoming_in": int(max(0, (upcoming[0] - current).total_seconds() // 60)) if upcoming else None}
|
||||
|
||||
def _daily_plan_can_upgrade_from_fallback(self, plan: Any, today: str) -> bool:
|
||||
"""今天这份计划是不是「兜底、且现在有条件换成真实的」。
|
||||
|
||||
只认当天的兜底计划;真实计划不会被反复重生成。次数上限用来防住
|
||||
「Provider 就绪但生成始终失败」时每个 tick 都重跑一遍模型。
|
||||
"""
|
||||
if not isinstance(plan, dict):
|
||||
return False
|
||||
if _single_line(plan.get("date"), 16) != today:
|
||||
return False
|
||||
if _single_line(plan.get("source"), 16) != "fallback":
|
||||
return False
|
||||
if self._daily_plan_fallback_retries(today) >= DAILY_PLAN_FALLBACK_RETRY_LIMIT:
|
||||
return False
|
||||
return self._chat_provider_ready()
|
||||
|
||||
def _daily_plan_fallback_retries(self, today: str) -> int:
|
||||
state = self.data.get("daily_plan_fallback_retry")
|
||||
if not isinstance(state, dict) or _single_line(state.get("date"), 16) != today:
|
||||
return 0
|
||||
return _safe_int(state.get("count"), 0, 0)
|
||||
|
||||
def _note_daily_plan_fallback_retry(self, today: str) -> int:
|
||||
"""记一次兜底升级尝试。调用方已持有 _data_lock,这里不能再取锁。"""
|
||||
attempts = self._daily_plan_fallback_retries(today) + 1
|
||||
self.data["daily_plan_fallback_retry"] = {"date": today, "count": attempts}
|
||||
self._save_data_sync()
|
||||
return attempts
|
||||
|
||||
async def _note_plan_provider_wait(self) -> int:
|
||||
"""记一次「Provider 未就绪」,返回已等待轮次。"""
|
||||
async with self._data_lock:
|
||||
|
|
@ -470,19 +502,30 @@ class DailyStateMixin:
|
|||
known_users = [
|
||||
user for user in self.data.get("users", {}).values() if isinstance(user, dict) and user.get("umo")
|
||||
]
|
||||
if not force and current_plan.get("date") == today:
|
||||
# 兜底日程一旦带上今天的日期,下面三处复用分支都会直接把它返回,当天不再生成。
|
||||
# 于是一次启动时序抖动就把模板兜底固化成正式的一天,并顺着归档进长期记忆。
|
||||
# Provider 恢复后允许再取一次真实计划,版本水位会让归档 upsert 而不是撞版本冲突。
|
||||
upgrade_fallback = (not force) and self._daily_plan_can_upgrade_from_fallback(current_plan, today)
|
||||
if upgrade_fallback:
|
||||
attempts = self._note_daily_plan_fallback_retry(today)
|
||||
logger.info(
|
||||
"[PrivateCompanion] 今日日程当前为兜底且对话 Provider 已就绪,尝试改用真实生成 (%s/%s)",
|
||||
attempts,
|
||||
DAILY_PLAN_FALLBACK_RETRY_LIMIT,
|
||||
)
|
||||
if not force and not upgrade_fallback and current_plan.get("date") == today:
|
||||
if self._sanitize_daily_plan_inplace(current_plan):
|
||||
self._refresh_daily_state_location_from_plan(plan=current_plan)
|
||||
self._save_data_sync()
|
||||
return current_plan
|
||||
if not force and self._is_plan_date_active(current_plan.get("date")):
|
||||
if not force and not upgrade_fallback and self._is_plan_date_active(current_plan.get("date")):
|
||||
if self._sanitize_daily_plan_inplace(current_plan):
|
||||
self._refresh_daily_state_location_from_plan(plan=current_plan)
|
||||
self._save_data_sync()
|
||||
return current_plan
|
||||
if not force and not known_users:
|
||||
return None
|
||||
if not force and not self._is_daily_plan_due():
|
||||
if not force and not upgrade_fallback and not self._is_daily_plan_due():
|
||||
if self._is_plan_date_active(current_plan.get("date")):
|
||||
if self._sanitize_daily_plan_inplace(current_plan):
|
||||
self._refresh_daily_state_location_from_plan(plan=current_plan)
|
||||
|
|
@ -512,6 +555,10 @@ class DailyStateMixin:
|
|||
plan = await self._generate_daily_plan()
|
||||
async with self._data_lock:
|
||||
self.data["daily_plan"] = plan
|
||||
if _single_line((plan or {}).get("source"), 16) == "llm":
|
||||
# 真实计划到手,兜底升级的次数就没有意义了;留着会在同一天再次
|
||||
# 退化成兜底时错误地占掉重试额度。
|
||||
self.data.pop("daily_plan_fallback_retry", None)
|
||||
self._refresh_daily_state_location_from_plan(plan=plan)
|
||||
self._save_data_sync()
|
||||
outfit_generator = getattr(self, "_ensure_daily_outfit_photo", None)
|
||||
|
|
@ -523,7 +570,10 @@ class DailyStateMixin:
|
|||
"[PrivateCompanion] 今日日程已保存,但每日穿搭照片生成失败: %s",
|
||||
_single_line(exc, 180),
|
||||
)
|
||||
await self._ensure_daily_news_reading(force=force)
|
||||
# 这里曾调用 _ensure_daily_news_reading:新闻/日报功能在删减轮已整体退役,
|
||||
# 实现被删了但调用点留了下来,于是每轮日程维护写盘后必抛 AttributeError,
|
||||
# 主动循环把「今日日程」标为失败并进冷却。计划本身早已保存,故障一直藏在
|
||||
# 「计划看起来是好的」后面。
|
||||
return plan
|
||||
|
||||
async def _ensure_daily_diary(self, force: bool = False) -> dict[str, Any] | None:
|
||||
|
|
|
|||
|
|
@ -531,3 +531,33 @@ docs\运维陪伴错题本.md
|
|||
- 修复或规避:新增 `_next_daily_plan_version(plugin, plan_date)`,同时看 `daily_plan` 与 `daily_plan_history` 取最大版本 +1(历史条目同步补 `version` 字段,运维清空 `daily_plan` 后版本才不会退回 1 撞上库里已有记录);另外把「远端拒绝」的告警移到 `accepted` 判断之外,任何 `ok=False` 都留一条可检索的 warning。
|
||||
- 预防规则:透传字段之前先确认上游真的在产生它——「把 `version` 传下去」和「`version` 有值」是两件事。凡是同一幂等键会被重复写入的链路,必须有一条测试证明第二次写入改变了库内容,而不是只证明第一次能写进去。
|
||||
- 验证证据:`tests/test_daily_plan_version.py` 7 项;VM 复跑本地 `v=2 source=llm 10 段` 与库内 `v=2 source=llm 10 段` 一致,`updated_at` 推进到 `2026-07-26T20:13:31Z`。
|
||||
|
||||
## 2026-07-27 — 删功能时删了实现没删调用点,故障藏在「结果看起来是好的」后面
|
||||
|
||||
- 阶段:P0 生产缺陷清理
|
||||
- 类型:清理未完成 / 可观测性
|
||||
- 现象:`daily_state.py` 调用 `_ensure_daily_news_reading`,该方法在新闻/日报功能退役时已被删除,全仓只剩这一个调用点。生产 VM 三小时内抛 14 次 `AttributeError`,主动循环把「今日日程」标为失败并进冷却;「查看日程/重置细化」等命令与页面 refine_schedule 入口同样报错。而这一切在验收里完全不可见——崩溃点在计划保存**之后**,所以查 `companions.json` 永远看到一份完整正确的计划。
|
||||
- 根因:删功能只删了实现与配置入口,没有反查调用方。更关键的是调用点位于「保存之后、返回之前」,异常被上层 catch 成一条 warning,主链数据正确,于是没有任何一个断言会失败。
|
||||
- 修复或规避:删掉调用点;补 `test_no_production_code_calls_the_removed_news_reader`,用全仓扫描而不是单点断言——这类残余按定义就不知道会藏在哪。同时补一条反面断言证明该方法确实不存在,否则测试本身可能因为改名而失效。
|
||||
- 预防规则:删除一个方法之前先全仓搜它的名字,把调用点一起处理;退役功能的收口要有一条「全仓无引用」的扫描型断言。凡是 `try/except` 包住的调用,都要问一句「如果它一直失败,我从哪看得出来」——看不出来就得升级日志级别或加断言。
|
||||
- 验证证据:`tests/test_p0_runtime_fixes.py` 12 项;VM 重启后 3 分钟窗口内 `_ensure_daily_news_reading` 与「主动循环维护步骤失败」命中数均为 0,ERRO/Traceback 为 0。
|
||||
|
||||
## 2026-07-27 — 新开关没写进 _conf_schema.json,等于没有开关
|
||||
|
||||
- 阶段:P0 生产缺陷清理
|
||||
- 类型:配置一致性
|
||||
- 现象:归档总闸 `enable_memory_companion_bridge`(`main.py` 用 `_cfg_bool` 读)在 `_conf_schema.json` 里 grep 命中 0 处。后果是设置页看不到它、改了也不落盘,运维想确认或临时切断双插件联动时无从下手。
|
||||
- 根因:上一轮把桥的开关从 `enable_livingmemory_integration` 拆出来时,只改了 Python 侧的读取,没同步 schema。而 `_cfg_bool` 读不到就取默认值 `True`,功能表现完全正常——缺失的是**可操作性**,不是功能,所以任何功能测试都不会失败。
|
||||
- 修复或规避:加进 `external_memory_config.items`(可见分组,不是 invisible 的 legacy flat 区),并补两条断言:一条钉死它在可见分组里且未被标 invisible,一条证明 `_flat_get` 能穿过分组按扁平键读到——schema 挂在分组下而代码按扁平键读,这两件事必须同时成立。
|
||||
- 预防规则:新增配置项的定义是「Python 读取 + schema 条目」两半,缺一半时功能仍然正常,只有可操作性消失。凡是新增 `_cfg_*` 读取,同一个提交里必须有对应的 schema 条目。
|
||||
- 验证证据:`tests/test_p0_runtime_fixes.py::BridgeSwitchSchemaTests`;VM 重启后配置文件里 `external_memory_config.enable_memory_companion_bridge = True` 已落盘。
|
||||
|
||||
## 2026-07-27 — 兜底结果带上日期,就等于把降级固化成一整天
|
||||
|
||||
- 阶段:P0 生产缺陷清理
|
||||
- 类型:功能行为
|
||||
- 现象:Provider 连续 5 轮未就绪后写入模板兜底日程,而 `_ensure_daily_plan` 有三处复用分支都以「`daily_plan.date == today`」为条件直接返回,于是当天不再生成。一次启动时序抖动就把模板兜底固化成正式的一天,并顺着归档链路进入长期记忆;下游的细化增强、日记、每日穿搭全部基于这份假计划。
|
||||
- 根因:`source="fallback"` 这个标记产出了却无人消费。复用分支只看日期,不看这份计划是真实生成还是降级产物。
|
||||
- 修复或规避:新增 `_daily_plan_can_upgrade_from_fallback`,当天的兜底计划在 Provider 恢复后允许再取一次真实计划;`DAILY_PLAN_FALLBACK_RETRY_LIMIT = 3` 防住「Provider 就绪但生成始终失败」时每个 tick 重跑模型;重试计数按日期分桶,昨天用掉的额度不占今天的;真实计划到手即清空计数。归档侧靠已有的版本水位做 upsert,不会撞版本冲突。
|
||||
- 预防规则:凡是写入了「降级/兜底」标记的数据,都要有一条链路消费这个标记——否则标记只是自我安慰。带日期的缓存键要问一句「如果这份数据是坏的,什么时候会被替换」,答不上来就是固化。
|
||||
- 验证证据:`tests/test_p0_runtime_fixes.py::FallbackUpgradeTests` 8 项(含额度耗尽、跨日分桶、坏状态容错);VM 上当天计划保持 `source=llm v=2 10 段`,重试计数为空。
|
||||
|
|
|
|||
|
|
@ -6,10 +6,16 @@
|
|||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import pathlib
|
||||
import sys
|
||||
import unittest
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from agenda_contracts import (
|
||||
# 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,
|
||||
|
|
@ -56,10 +62,6 @@ class WindowForMinutesTests(unittest.TestCase):
|
|||
self.assertEqual(window_for_minutes(hour * 60 + minute), expected)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
class WindowForPlanMinutesTests(unittest.TestCase):
|
||||
"""跨午夜归属:同一份计划里的两个「深夜」分属两个日程日。"""
|
||||
|
||||
|
|
@ -97,3 +99,6 @@ class WindowForPlanMinutesTests(unittest.TestCase):
|
|||
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()
|
||||
|
|
|
|||
|
|
@ -176,7 +176,21 @@ class R7RetiredEntryTests(unittest.TestCase):
|
|||
def test_retired_prefixes_cover_the_deleted_features(self):
|
||||
self.assertEqual(
|
||||
set(self.handlers.RETIRED_FEATURE_CONFIG_PREFIXES),
|
||||
{"enable_qzone", "qzone_", "enable_news", "news_", "WEB_EXPLORATION_"})
|
||||
{"enable_qzone", "qzone_", "enable_news", "news_",
|
||||
"WEB_EXPLORATION_", "enable_web_exploration", "web_exploration_"})
|
||||
|
||||
def test_lowercase_web_exploration_keys_are_hidden_too(self):
|
||||
"""网页探索的键在手动配置面是大写、在 _conf_schema.json 里是小写;
|
||||
前缀匹配区分大小写,只列大写会漏掉 schema 里那批。"""
|
||||
mapping = {
|
||||
"WEB_EXPLORATION_API_KEY": 1,
|
||||
"enable_web_exploration": 1,
|
||||
"enable_web_exploration_boredom_search": 1,
|
||||
"web_exploration_max_results": 1,
|
||||
"enable_daily_diary": 1,
|
||||
}
|
||||
visible = self.handlers._hide_retired_feature_configs(mapping)
|
||||
self.assertEqual(set(visible), {"enable_daily_diary"})
|
||||
|
||||
def test_retired_keys_are_hidden_from_display_surfaces(self):
|
||||
hidden = ("enable_qzone_integration", "qzone_comment_inbox_interval_minutes",
|
||||
|
|
@ -204,10 +218,6 @@ class R7RetiredEntryTests(unittest.TestCase):
|
|||
"残余配置项被直接删掉了,与「不删除旧数据」相悖")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
class R7BridgeGateTests(unittest.TestCase):
|
||||
"""桥的开关必须独立于 LivingMemory。
|
||||
|
||||
|
|
@ -260,3 +270,7 @@ class R7BridgeGateTests(unittest.TestCase):
|
|||
if "livingmemory" in line.lower() and not line.strip().startswith("#"):
|
||||
offenders.append(f"{path.name}:{num}")
|
||||
self.assertEqual(offenders, [], f"仍有 LivingMemory 代码残留: {offenders}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
142
tests/test_p0_runtime_fixes.py
普通文件
142
tests/test_p0_runtime_fixes.py
普通文件
|
|
@ -0,0 +1,142 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""P0 生产缺陷回归(2026-07-27)。
|
||||
|
||||
三件事,共同点是「生产在报错/退化,而验收全绿」:
|
||||
|
||||
1. `daily_state.py` 还在调用早已被删掉的 `_ensure_daily_news_reading`,
|
||||
每轮日程维护写盘后必抛 AttributeError,主动循环把「今日日程」标失败并冷却。
|
||||
计划本身已经保存,所以故障一直藏在「计划看起来是好的」后面。
|
||||
2. 归档总闸 `enable_memory_companion_bridge` 不在 `_conf_schema.json` 里,
|
||||
设置页看不到、改了也不落盘——上次整条归档链路静默停摆三天就是同一处开关问题。
|
||||
3. 兜底日程带上当天日期后,三处复用分支都会直接把它返回,当天不再生成,
|
||||
于是一次启动时序抖动把模板兜底固化成正式的一天并归档进长期记忆。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib
|
||||
import json
|
||||
import logging
|
||||
import pathlib
|
||||
import sys
|
||||
import types
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
|
||||
import _host_stub # noqa: E402
|
||||
|
||||
_host_stub.install()
|
||||
|
||||
_package_name = "_p0_companion"
|
||||
_package = types.ModuleType(_package_name)
|
||||
_package.__path__ = [str(pathlib.Path(__file__).resolve().parents[1])]
|
||||
sys.modules.setdefault(_package_name, _package)
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
||||
daily_state = importlib.import_module(f"{_package_name}.daily_state")
|
||||
helpers = importlib.import_module(f"{_package_name}.helpers")
|
||||
|
||||
TODAY = "2026-07-27"
|
||||
|
||||
|
||||
class Host(daily_state.DailyStateMixin):
|
||||
"""只带本组用例需要的状态,其余走 Mixin 真实实现。"""
|
||||
|
||||
def __init__(self, plan=None, retry=None, provider_ready=True):
|
||||
self.data = {}
|
||||
if plan is not None:
|
||||
self.data["daily_plan"] = plan
|
||||
if retry is not None:
|
||||
self.data["daily_plan_fallback_retry"] = retry
|
||||
self._provider_ready = provider_ready
|
||||
self.saves = 0
|
||||
|
||||
def _chat_provider_ready(self) -> bool:
|
||||
return self._provider_ready
|
||||
|
||||
def _save_data_sync(self) -> None:
|
||||
self.saves += 1
|
||||
|
||||
|
||||
class DeadNewsCallTests(unittest.TestCase):
|
||||
def test_no_production_code_calls_the_removed_news_reader(self):
|
||||
offenders = []
|
||||
for path in ROOT.rglob("*.py"):
|
||||
parts = set(path.parts)
|
||||
if parts & {"tests", ".tmp", "__pycache__"}:
|
||||
continue
|
||||
for num, line in enumerate(path.read_text(encoding="utf-8", errors="ignore").splitlines(), 1):
|
||||
if "_ensure_daily_news_reading" in line and not line.strip().startswith("#"):
|
||||
offenders.append(f"{path.name}:{num}")
|
||||
self.assertEqual(offenders, [], f"仍在调用已删除的新闻阅读实现: {offenders}")
|
||||
|
||||
def test_the_method_really_does_not_exist(self):
|
||||
"""反面证据:它确实没有实现,所以上面的调用点必然是 AttributeError。"""
|
||||
self.assertFalse(hasattr(daily_state.DailyStateMixin, "_ensure_daily_news_reading"))
|
||||
|
||||
|
||||
class BridgeSwitchSchemaTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.schema = json.loads((ROOT / "_conf_schema.json").read_text(encoding="utf-8"))
|
||||
|
||||
def test_bridge_switch_is_visible_in_the_external_memory_group(self):
|
||||
items = self.schema["external_memory_config"]["items"]
|
||||
self.assertIn("enable_memory_companion_bridge", items)
|
||||
entry = items["enable_memory_companion_bridge"]
|
||||
self.assertEqual(entry["type"], "bool")
|
||||
self.assertIs(entry["default"], True)
|
||||
self.assertFalse(entry.get("invisible"), "总闸被标成 invisible 就等于设置页还是看不到")
|
||||
|
||||
def test_the_switch_is_read_through_the_same_path_main_uses(self):
|
||||
"""schema 里挂在分组下,main.py 却按扁平键读——_flat_get 必须能穿过分组。"""
|
||||
config = {"external_memory_config": {"enable_memory_companion_bridge": False}}
|
||||
self.assertIs(helpers._flat_get(config, "enable_memory_companion_bridge", True), False)
|
||||
|
||||
|
||||
class FallbackUpgradeTests(unittest.TestCase):
|
||||
def test_fallback_plan_can_be_upgraded_when_provider_is_back(self):
|
||||
host = Host(plan={"date": TODAY, "source": "fallback"})
|
||||
self.assertTrue(host._daily_plan_can_upgrade_from_fallback(host.data["daily_plan"], TODAY))
|
||||
|
||||
def test_real_plan_is_never_regenerated(self):
|
||||
host = Host(plan={"date": TODAY, "source": "llm"})
|
||||
self.assertFalse(host._daily_plan_can_upgrade_from_fallback(host.data["daily_plan"], TODAY))
|
||||
|
||||
def test_provider_still_down_means_no_upgrade_attempt(self):
|
||||
host = Host(plan={"date": TODAY, "source": "fallback"}, provider_ready=False)
|
||||
self.assertFalse(host._daily_plan_can_upgrade_from_fallback(host.data["daily_plan"], TODAY))
|
||||
|
||||
def test_yesterdays_fallback_is_not_upgraded_today(self):
|
||||
host = Host(plan={"date": "2026-07-26", "source": "fallback"})
|
||||
self.assertFalse(host._daily_plan_can_upgrade_from_fallback(host.data["daily_plan"], TODAY))
|
||||
|
||||
def test_retry_budget_is_capped(self):
|
||||
limit = daily_state.DAILY_PLAN_FALLBACK_RETRY_LIMIT
|
||||
host = Host(plan={"date": TODAY, "source": "fallback"})
|
||||
for expected in range(1, limit + 1):
|
||||
self.assertTrue(host._daily_plan_can_upgrade_from_fallback(host.data["daily_plan"], TODAY))
|
||||
self.assertEqual(host._note_daily_plan_fallback_retry(TODAY), expected)
|
||||
self.assertFalse(
|
||||
host._daily_plan_can_upgrade_from_fallback(host.data["daily_plan"], TODAY),
|
||||
"重试次数用尽后仍在尝试,Provider 就绪但生成始终失败时会每个 tick 重跑模型",
|
||||
)
|
||||
|
||||
def test_retry_counter_is_scoped_to_its_own_day(self):
|
||||
"""昨天用掉的额度不能占掉今天的。"""
|
||||
host = Host(plan={"date": TODAY, "source": "fallback"},
|
||||
retry={"date": "2026-07-26", "count": 99})
|
||||
self.assertEqual(host._daily_plan_fallback_retries(TODAY), 0)
|
||||
self.assertTrue(host._daily_plan_can_upgrade_from_fallback(host.data["daily_plan"], TODAY))
|
||||
|
||||
def test_broken_retry_state_is_tolerated(self):
|
||||
host = Host(plan={"date": TODAY, "source": "fallback"}, retry="不是字典")
|
||||
self.assertEqual(host._daily_plan_fallback_retries(TODAY), 0)
|
||||
|
||||
def test_note_retry_persists(self):
|
||||
host = Host(plan={"date": TODAY, "source": "fallback"})
|
||||
host._note_daily_plan_fallback_retry(TODAY)
|
||||
self.assertEqual(host.data["daily_plan_fallback_retry"], {"date": TODAY, "count": 1})
|
||||
self.assertEqual(host.saves, 1, "重试计数必须落盘,否则重启后额度重置")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
正在加载…
添加表格
在新工单中引用