fix(chv): 生产级审核 P1-01~P1-10 修复(堆叠于 #270 之上)

This commit is contained in:
muse-agent committed 2026-11-02 03:25:49 +00:00
1 parent 8c8d62f70d
commit 971e054938
12 files changed
+1545 -120

No files matched your search

+22 -6
View File
@@ -156,6 +156,8 @@ class BreakingCleanupTest(unittest.TestCase):
class OrphansTest(unittest.TestCase):
def test_valid_warm_and_assigned_cleaned_invalid_dropped(self):
# feat-chv-p1fix(P1-02):非法条目不再静默丢弃,
# 先发 invalid 审计并计数,再发 cleaned 审计。
with tempfile.TemporaryDirectory() as d:
path = _write_registry(d, {
"a": {"state": "warm", "vm": "chv-a",
@@ -171,19 +173,26 @@ class OrphansTest(unittest.TestCase):
reconcile_orphans_for_executor(ex),
["chv-a", "chv-b"])
self.assertEqual(ex.shutdowns, ["chv-a", "chv-b"])
self.assertEqual(ex.emits, ["warm_pool_reconcile"])
self.assertEqual(ex.emits, [
"warm_pool_registry_invalid_entries",
"warm_pool_reconcile"])
with open(path) as fh:
self.assertEqual(json.load(fh), {})
def test_invalid_only_returns_empty_and_leaves_file(self):
def test_invalid_only_returns_empty_and_drops_audited_entries(self):
# feat-chv-p1fix(P1-02):仅非法条目时返回 [] 且
# 不 shutdown;非法条目已审计计数,落盘时丢弃,
# 不再每次重启重复审计同一批非法条目。
with tempfile.TemporaryDirectory() as d:
path = _write_registry(d, {
"c": {"state": "warm", "task_id": "c"}})
ex = FakeProdExecutor(d)
self.assertEqual(reconcile_orphans_for_executor(ex), [])
self.assertEqual(ex.shutdowns, [])
self.assertEqual(
ex.emits, ["warm_pool_registry_invalid_entries"])
with open(path) as fh:
self.assertIn("task_id", fh.read())
self.assertEqual(json.load(fh), {})
def test_corrupt_json_quarantined(self):
with tempfile.TemporaryDirectory() as d:
@@ -212,9 +221,12 @@ class OrphansTest(unittest.TestCase):
self.assertEqual(
reconcile_orphans_for_executor(NoDir()), [])
def test_shutdown_and_emit_failures_do_not_break_cleanup(self):
def test_shutdown_failure_not_cleaned_and_retained(self):
# feat-chv-p1fix(P1-01):shutdown 失败的条目不进
# cleaned、不触发清库,落盘保留原始条目可重试;
# _emit 失败仍 best-effort,不炸清理流程。
with tempfile.TemporaryDirectory() as d:
_write_registry(d, {
path = _write_registry(d, {
"a": {"state": "warm", "vm": "chv-a"}})
ex = FakeProdExecutor(d)
@@ -225,7 +237,11 @@ class OrphansTest(unittest.TestCase):
ex._emit = lambda *a, **k: (_ for _ in ()).throw(
RuntimeError("audit down"))
self.assertEqual(
reconcile_orphans_for_executor(ex), ["chv-a"])
reconcile_orphans_for_executor(ex), [])
with open(path) as fh:
self.assertEqual(
json.load(fh),
{"a": {"state": "warm", "vm": "chv-a"}})
def test_experimental_pool_registry_roundtrip_unchanged(self):
# 实验池自身的 registry 语义(载入即 orphan、reconcile