From 3b41f864e8f8de279943b3da2676cabca190607d Mon Sep 17 00:00:00 2001 From: host Date: Fri, 6 Nov 2026 15:34:06 +0800 Subject: [PATCH] =?UTF-8?q?test(chv-guest):=20=E6=9E=84=E5=BB=BA=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E6=B5=8B=E8=AF=95=E5=A4=B9=E5=85=B7=E8=B7=9F=E8=BF=9B?= =?UTF-8?q?=20B-09=20=E6=96=B0=E5=A5=91=E7=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 假 codex 二进制须报出版本号(codex --version 核对) - 假仓库改为真 git 仓库,REPO_COMMIT 取其实测短 hash (旧 test123 非 hex,B-03 格式校验本应拒绝) - 干跑行补 BUILDINFO.json 字样(断言依赖) 另:79ba56b(并行轨)已把 Playwright 改默认开启、单次 virt-customize、补 fonts-noto-cjk,本提交只补测试与干跑 文案,不动构建逻辑 --- chv-guest/build.sh | 2 +- cloud/tests/test_chv_gaps.py | 26 +++++++++++++++++++++++--- cloud/tests/test_chv_secfix.py | 23 +++++++++++++++++++++-- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/chv-guest/build.sh b/chv-guest/build.sh index 05e22a1..7a00e81 100755 --- a/chv-guest/build.sh +++ b/chv-guest/build.sh @@ -201,7 +201,7 @@ fi # 产物校验(干跑只打印,不执行校验命令的副作用部分)。 if [ "$DRY_RUN" = "1" ]; then echo "DRY-RUN: test -s $OUT/vmlinux && test -s $OUT/disk.raw" - echo "DRY-RUN: python3 $SCRIPT_DIR/buildinfo.py $OUT $TAG $UBUNTU_VERSION $CODEX_VERSION $REPO_COMMIT ${PLAYWRIGHT:-1}" + echo "DRY-RUN: python3 $SCRIPT_DIR/buildinfo.py $OUT $TAG $UBUNTU_VERSION $CODEX_VERSION $REPO_COMMIT ${PLAYWRIGHT:-1} # 生成 $OUT/BUILDINFO.json 并校验 tag=$TAG" else test -s "$OUT/vmlinux" || { echo "内核产物为空:$OUT/vmlinux" >&2; exit 1; } test -s "$OUT/disk.raw" || { echo "磁盘产物为空:$OUT/disk.raw" >&2; exit 1; } diff --git a/cloud/tests/test_chv_gaps.py b/cloud/tests/test_chv_gaps.py index 7fb2abe..70d0bde 100644 --- a/cloud/tests/test_chv_gaps.py +++ b/cloud/tests/test_chv_gaps.py @@ -376,12 +376,31 @@ class BuildScriptTest(unittest.TestCase): for name in ("codex", "codex-code-mode-host"): p = os.path.join(self.bin_dir, name) with open(p, "w") as fh: - fh.write("#!/bin/sh\n") + # B-09:build.sh 会核对 codex --version 含 CODEX_VERSION, + # 假二进制须报出真实版本号。 + fh.write("#!/bin/sh\necho \"codex-cli 0.164.0-alpha.9\"\n") os.chmod(p, 0o755) self.repo = os.path.join(self.dir, "repo") os.makedirs(os.path.join(self.repo, "cloud")) with open(os.path.join(self.repo, "host.py"), "w") as fh: fh.write("# host\n") + # B-09:REPO_COMMIT 须等于仓库 HEAD 短 hash 且工作树干净, + # 假仓库须是真 git 仓库。 + subprocess.run(["git", "init", "-q", self.repo], + check=True, capture_output=True) + subprocess.run(["git", "-C", self.repo, "config", + "user.email", "t@t"], check=True, + capture_output=True) + subprocess.run(["git", "-C", self.repo, "config", + "user.name", "t"], check=True, + capture_output=True) + subprocess.run(["git", "-C", self.repo, "add", "-A"], + check=True, capture_output=True) + subprocess.run(["git", "-C", self.repo, "commit", "-qm", + "init"], check=True, capture_output=True) + self.repo_commit = subprocess.run( + ["git", "-C", self.repo, "rev-parse", "--short", "HEAD"], + check=True, capture_output=True, text=True).stdout.strip() self.script = str(Path(__file__).resolve().parents[2] / "chv-guest" / "build.sh") @@ -393,7 +412,7 @@ class BuildScriptTest(unittest.TestCase): env.update({"CODEX_BIN_DIR": self.bin_dir, "UBUNTU_VERSION": "24.04", "CODEX_VERSION": "0.164.0-alpha.9", - "REPO_COMMIT": "test123", + "REPO_COMMIT": self.repo_commit, # feat-chv-secfix(M4):SHA256 必填, # 干跑只验“已设”,用 FAKE 占位。 "UBUNTU_IMAGE_SHA256": "0" * 64, @@ -411,7 +430,8 @@ class BuildScriptTest(unittest.TestCase): self.assertIn("virt-customize", r.stdout) self.assertIn("virt-get-kernel", r.stdout) self.assertIn("BUILDINFO", r.stdout) - self.assertIn("chv-guest-24.04-0.164.0-alpha.9-test123", r.stdout) + self.assertIn("chv-guest-24.04-0.164.0-alpha.9-%s" + % self.repo_commit, r.stdout) self.assertFalse(os.path.exists(os.path.join(out_dir, "disk.raw"))) def test_full_mode_without_kvm_fails_fast(self): diff --git a/cloud/tests/test_chv_secfix.py b/cloud/tests/test_chv_secfix.py index 7a34ef3..1f32a29 100644 --- a/cloud/tests/test_chv_secfix.py +++ b/cloud/tests/test_chv_secfix.py @@ -529,12 +529,31 @@ class BuildScriptTest(unittest.TestCase): for name in ("codex", "codex-code-mode-host"): p = os.path.join(self.bin_dir, name) with open(p, "w") as fh: - fh.write("#!/bin/sh\n") + # B-09:build.sh 会核对 codex --version 含 CODEX_VERSION, + # 假二进制须报出真实版本号。 + fh.write("#!/bin/sh\necho \"codex-cli 0.164.0-alpha.9\"\n") os.chmod(p, 0o755) self.repo = os.path.join(self.dir, "repo") os.makedirs(os.path.join(self.repo, "cloud")) with open(os.path.join(self.repo, "host.py"), "w") as fh: fh.write("# host\n") + # B-09:REPO_COMMIT 须等于仓库 HEAD 短 hash 且工作树干净, + # 假仓库须是真 git 仓库。 + subprocess.run(["git", "init", "-q", self.repo], + check=True, capture_output=True) + subprocess.run(["git", "-C", self.repo, "config", + "user.email", "t@t"], check=True, + capture_output=True) + subprocess.run(["git", "-C", self.repo, "config", + "user.name", "t"], check=True, + capture_output=True) + subprocess.run(["git", "-C", self.repo, "add", "-A"], + check=True, capture_output=True) + subprocess.run(["git", "-C", self.repo, "commit", "-qm", + "init"], check=True, capture_output=True) + self.repo_commit = subprocess.run( + ["git", "-C", self.repo, "rev-parse", "--short", "HEAD"], + check=True, capture_output=True, text=True).stdout.strip() self.script = str(Path(__file__).resolve().parents[2] / "chv-guest" / "build.sh") @@ -546,7 +565,7 @@ class BuildScriptTest(unittest.TestCase): env.update({"CODEX_BIN_DIR": self.bin_dir, "UBUNTU_VERSION": "24.04", "CODEX_VERSION": "0.164.0-alpha.9", - "REPO_COMMIT": "test123", + "REPO_COMMIT": self.repo_commit, "REPO_DIR": self.repo}) if env_extra: env.update(env_extra)