fix(chv-hybrid): 严格快照默认翻转的旧测试适配 + 长函数拆分
ci / test (push) Successful in 1h8m45s

全量复核 4676 项出现 4 失败 6 错误,全是集成时翻为默认开启的
严格快照校验(设计 §2.2)的连锁反应——旧测试用未登记/未标记
快照走 legacy 放行路径。按新语义逐项适配,不改生产校验本身:

- test_chv_opt_stage1.CrossTenantRestoreTest:跨租户拒绝的审计
  事件改断言 vm_restore_denied(严格路径的设计事件;
  vm_restore_tenant_denied 只在显式关闭严格校验时出现);
  legacy 警告放行测试改走显式 CHV_SNAPSHOT_STRICT_TENANT=0。
- test_chv_v3_fixes(5 个 restore 测试):登记带匹配 tenant
  (proj1)的快照,意图不变(盘预检 / source_url / 清旧 VMM
  仍由各自断言覆盖)。
- test_cloud_hypervisor.LifecycleTest:登记 file:///snap/1
  (tenant proj1),restore/resume 顺序断言不变。
- 长函数:B 轨合入把 _run_with_persistent_vm 推到 53 行,超
  50 行架构上限;finally 收尾块抽为 _suspend_persistent_after_task。

针对性 12 项全部通过;全量待重跑。
This commit is contained in:
host committed 2026-11-08 22:14:39 +00:00
1 parent 04a208a98b
commit 6c03ac9b0f
4 files changed
+45 -13

No files matched your search

+6
View File
@@ -20,6 +20,7 @@ from pathlib import Path
from unittest import mock
try:
from cloud.chv.disk import record_snapshot
from cloud.chv.experimental_pool import WarmPool
from cloud.sandbox import (
ChvFailure,
@@ -28,6 +29,7 @@ try:
)
except ImportError: # discover -s cloud/tests 时把项目根目录补进 sys.path
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
from cloud.chv.disk import record_snapshot
from cloud.chv.experimental_pool import WarmPool
from cloud.sandbox import (
ChvFailure,
@@ -406,6 +408,10 @@ class LifecycleTest(ChvCase):
# 路径 + 声明快照目录(生产默认 provisioned + 白名单
# 目录,旧 file:///snap/1 不再直通)。
ex = self.make_exec(env_extra={"CHV_SNAPSHOT_DIR": "/snap"})
# 严格快照校验(设计 §2.2,默认开启):恢复须登记带
# tenant 且与 _task() 的 project_id(proj1)一致。
record_snapshot(self.state_dir, "chv-abc123",
"file:///snap/1", 20.0, tenant_id="proj1")
out = ex.restore_vm(self._task(), "file:///snap/1")
self.assertEqual(out["mode"], "restored")
self.assertTrue(out["ready"])