fix(chv-guest): 客机镜像构建缺口补齐(B-02/B-03/B-04/B-05/B-06/B-07/B-08/B-09/B-10/B-13/B-15)

- B-10(实测):virt-customize chroot 里 sshd -t 必败,双因:
  无 host key(exit 1)+ 缺 /run/sshd(exit 255);修为
  mkdir -p /run/sshd + ssh-keygen -A 临时生成,断言通过后
  立删临时 key,镜像仍不带 host key(已在 WSL 真机预演验证)
- B-08:Playwright 装在第二次定制,须重写 pip freeze 否则
  BUILDINFO 里无 playwright;Chromium 以 ms-playwright 缓存
  目录名记录进 guest-versions-chromium.txt
- B-09:codex --version 须含 CODEX_VERSION;REPO_COMMIT 须
  等于 HEAD 短 hash;工作树脏即拒绝构建
- B-02/B-13:BUILDINFO 生成抽成 buildinfo.py(可单元测试),
  补 disk.raw/vmlinux sha256+大小、ubuntu 镜像 sha、cmdline、
  playwright 开关、image_sha256 字段
- generate_lockfile.py 改写:版本唯一来源改为
  BUILDINFO.versions(客机读回),codex 三件套取
  codex_version、/app/host.py 取 repo_commit、chromium 取
  versions.chromium;不再查构建宿主 dpkg/pip(旧方法不成立)
- check_lockfile.py 补强:条目格式、contents 全覆盖、冻结
  清单双向比对
- B-03/B-04 输入格式校验、B-05 curl 重试、B-06 哈希不符
  删文件重下、B-07 磁盘预检、B-15 set -euo pipefail
- 同步改 test_chv_to10.py:generate 不再查宿主,改断言客机
  版本来源 + 不回落宿主
This commit is contained in:
host committed 2026-11-06 15:13:23 +08:00
1 parent 8c8d62f70d
commit 7f18c2d13b
5 files changed
+372 -96

No files matched your search

+29 -4
View File
@@ -359,21 +359,46 @@ class LockfileScriptTest(unittest.TestCase):
spec.loader.exec_module(mod)
return mod
def test_generate_reads_real_dpkg_version(self):
def test_generate_reads_guest_versions(self):
# C 轨纠正(报告 §3.2):版本唯一来源是 BUILDINFO.versions
#(客机读回),不是构建宿主的 dpkg/pip;codex 类声明项
# 取 BUILDINFO 的 codex_version / repo_commit。
import json as _json
mod = self._load_script()
with tempfile.TemporaryDirectory() as tmp:
bi = os.path.join(tmp, "bi.json")
out = os.path.join(tmp, "lock.json")
with open(bi, "w") as fh:
_json.dump({"tag": "t", "contents": ["coreutils"]},
_json.dump({"tag": "t",
"contents": ["coreutils", "codex"],
"codex_version": "0.164.0-alpha.9",
"versions": {"dpkg": ["coreutils 9.4-3"],
"pip": []}},
fh)
self.assertEqual(mod.generate(bi, out), 0)
lock = _json.load(open(out))
self.assertEqual(lock["tag"], "t")
self.assertEqual(lock["unresolved"], [])
self.assertTrue(lock["versions"]["dpkg"][0].startswith(
"coreutils "))
self.assertEqual(lock["versions"]["dpkg"],
["coreutils 9.4-3"])
self.assertEqual(lock["versions"]["declared"],
["codex 0.164.0-alpha.9"])
def test_generate_does_not_query_host(self):
# 宿主上装着 coreutils,但 BUILDINFO.versions 里没有 →
# unresolved,绝不回落到宿主查询(旧方法不成立)。
import json as _json
mod = self._load_script()
with tempfile.TemporaryDirectory() as tmp:
bi = os.path.join(tmp, "bi.json")
out = os.path.join(tmp, "lock.json")
with open(bi, "w") as fh:
_json.dump({"tag": "t", "contents": ["coreutils"],
"versions": {"dpkg": [], "pip": []}},
fh)
self.assertEqual(mod.generate(bi, out), 0)
lock = _json.load(open(out))
self.assertEqual(lock["unresolved"], ["coreutils"])
def test_verify_fails_on_unresolved(self):
import json as _json