CloudLab CI/CD / 门禁 doctor (push) Failing after 33s
CloudLab CI/CD / 单元测试 (push) Skipped
CloudLab CI/CD / 归档完整性 (push) Skipped
CloudLab CI/CD / 构建站点与归档 (push) Skipped
CloudLab CI/CD / 部署到 lab.hdtime.space(rsync) (push) Skipped
CloudLab CI/CD / 构建镜像并推送 Gitea 容器仓库 (push) Skipped
CloudLab CI/CD / 容器部署到 lab.hdtime.space (push) Skipped
CloudLab CI/CD / 发布版本(Tag) (push) Skipped
用户:"资料库的历史遗留问题,需要单独处理"。
根因(一次重构、多处未同步):
22a2bf7 把 生命科学资料库 从编号目录重构成字母目录
(00-总索引与计划 → A-总论与工具,16-原子与分子化学基础 → B2-...),
但 4 个下游没跟着改,导致根目录套件 8 项失败。
修复:
1) integrity 系统补「删除登记」能力(根因级修复):
- read_changes 支持 deleted 字段
- verify 把已登记删除的基线文件从 FAIL 改为 EXPECTED
- snapshot 自动登记物理不存在的文件到 deleted
- verify 返回值带 deleted 计数
1800 个迁移旧路径一次登记,不再永久报「缺失」。
归档说明的纪律「清单是不可变基线、变动登记在修订记录」保持不变。
2) 路径同步:
- registry.py / doctor.py:build_portal.py 旧路径 → A-总论与工具
- doctor.py:统一索引路径同步;新增 _portal_meta() 解析新版门户
的 base64+gzip DATA 块(旧正则搜明文 n_libs 永远失败)
- cloudlab.py:_portal_libs 复用 doctor._portal_meta,消除重复解析漂移
- build_portal.py:HERE 与生成内容里的旧路径全部改为新目录
- rag.py / adapter.py:RAG 来源标注路径同步
3) 诚实纠正:上一轮我新增的 tests/test_portability.py 未登记到 changes,
导致 test_changes_cover_new_files 失败——是我引入的,已 snapshot 登记。
4) 本地测试残留 cloudlab.db 移到 .workbuddy 备份(非删除),
doctor 的「无运行库文件」检查恢复通过。
5) tests/test_library_paths.py 5/5:固化流水线脚本存在、索引新路径、
压缩门户解析、删除登记完整性,防止路径再漂移。
test_integrity 更新为允许「已登记删除」的基线缺失。
验证:根目录套件从 8 failed/24 passed → 37 passed;
doctor 9/9 门禁放行;verify 零意外损坏;build_portal 路径依赖全部就位
(未执行该脚本,避免重写门户)。
Co-Authored-By: WorkBuddy <noreply@workbuddy.ai>
144 lines
5.4 KiB
Python
144 lines
5.4 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""CloudLab 统一控制面入口(唯一推荐入口,纯标准库)。
|
||
|
||
python3 cloudlab.py doctor # 自检 + 回归门禁
|
||
python3 cloudlab.py test # 单元测试
|
||
python3 cloudlab.py verify # 归档完整性校验
|
||
python3 cloudlab.py snapshot # 自动登记本轮修订 / 新增
|
||
python3 cloudlab.py list # 查看资产与构建流水线
|
||
python3 cloudlab.py version # 版本
|
||
python3 cloudlab.py build portal # 门户编排(dry-run)
|
||
python3 cloudlab.py build portal --apply # 实际重建门户(含幂等校验)
|
||
python3 cloudlab.py build upload|deploy|archive
|
||
|
||
🔴 不要单独运行 build_portal.py:它只认 4 套资产,会把门户回退。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import argparse
|
||
import os
|
||
import subprocess
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||
|
||
import cloudlab_core.registry as registry
|
||
import cloudlab_core.integrity as integrity
|
||
import cloudlab_core.doctor as doctor
|
||
from cloudlab_core import VERSION, WORKSPACE
|
||
|
||
|
||
def _run(script: str, extra_env: dict | None = None) -> int:
|
||
env = os.environ.copy()
|
||
env.update(extra_env or {})
|
||
print(f" ▶ {script}")
|
||
return subprocess.run([sys.executable, str(WORKSPACE / script)],
|
||
cwd=str(WORKSPACE), env=env).returncode
|
||
|
||
|
||
def _portal_libs() -> int:
|
||
p = WORKSPACE / "资料库总门户.html"
|
||
if not p.is_file():
|
||
return -1
|
||
# 复用 doctor 的解析器:新版门户的 DATA 是 base64+gzip,
|
||
# 两处各写一份正则会再次漂移(历史教训)。
|
||
return int(doctor._portal_meta(
|
||
p.read_text(encoding="utf-8", errors="replace")).get("n_libs", -1))
|
||
|
||
|
||
def cmd_version(_):
|
||
print(f"CloudLab {VERSION} (schema {registry.SCHEMA_VERSION})")
|
||
print(f"工作区:{WORKSPACE}")
|
||
return 0
|
||
|
||
|
||
def cmd_doctor(_):
|
||
return 0 if doctor.run() else 1
|
||
|
||
|
||
def cmd_test(_):
|
||
return subprocess.run(
|
||
[sys.executable, "-m", "unittest", "discover", "-s", "tests", "-v"],
|
||
cwd=str(WORKSPACE)).returncode
|
||
|
||
|
||
def cmd_verify(_):
|
||
return integrity.main([])
|
||
|
||
|
||
def cmd_snapshot(_):
|
||
return integrity.snapshot()
|
||
|
||
|
||
def cmd_list(_):
|
||
print(f"=== CloudLab {VERSION} 注册表 ===")
|
||
print(f"资料库资产({len(registry.LIBRARY_NAMES)} 套):")
|
||
for i, name in enumerate(registry.LIBRARY_NAMES, 1):
|
||
tag = "基础" if name in registry.BASE_LIBRARIES else "幂等登记"
|
||
print(f" {i}. {name} [{tag}]")
|
||
print(f"\n顶层目录({len(registry.TOP_DIRS)}):{', '.join(registry.TOP_DIRS)}")
|
||
print(f"顶层交付文件({len(registry.TOP_FILES)})")
|
||
print("\n门户构建流水线(顺序不可调换):")
|
||
for i, (s, label, expect) in enumerate(registry.PORTAL_PIPELINE, 1):
|
||
print(f" {i}. {label:<24} → n_libs={expect} {s}")
|
||
print(f"\n生成器:{registry.GENERATORS}")
|
||
print(f"当前门户 n_libs = {_portal_libs()}")
|
||
return 0
|
||
|
||
|
||
def cmd_build(a):
|
||
if a.target == "portal":
|
||
if not a.apply:
|
||
print("=== 门户构建流水线(dry-run,未改动任何文件)===")
|
||
for i, (s, label, expect) in enumerate(registry.PORTAL_PIPELINE, 1):
|
||
print(f" {i}. {label:<24} → n_libs={expect} {s}")
|
||
print(f"当前 n_libs = {_portal_libs()}")
|
||
print("\n加 --apply 才会实际重建;重建后自动登记修订快照。")
|
||
return 0
|
||
print("=== 门户重建(按注册表顺序,每步校验幂等)===")
|
||
env = {"CLOUDLAB_ALLOW_PORTAL_RESET": "1"}
|
||
for script, label, expect in registry.PORTAL_PIPELINE:
|
||
rc = _run(script, env)
|
||
if rc:
|
||
print(f"❌ 步骤失败:{label} (exit={rc})")
|
||
return rc
|
||
got = _portal_libs()
|
||
if got != expect:
|
||
print(f"❌ {label} 后 n_libs={got},期望 {expect};已中止")
|
||
return 1
|
||
print(f" ✅ {label} → n_libs={got}")
|
||
integrity.snapshot()
|
||
print(f"✅ 门户重建完成,n_libs={_portal_libs()},修订已登记")
|
||
return 0
|
||
if a.target in registry.GENERATORS:
|
||
return _run(registry.GENERATORS[a.target])
|
||
print(f"未知构建目标:{a.target}")
|
||
return 2
|
||
|
||
|
||
def main(argv=None) -> int:
|
||
ap = argparse.ArgumentParser(prog="cloudlab.py", description="CloudLab 工程控制面")
|
||
sub = ap.add_subparsers(dest="cmd", required=True)
|
||
|
||
sub.add_parser("doctor", help="自检 + 回归门禁").set_defaults(fn=cmd_doctor)
|
||
sub.add_parser("test", help="运行单元测试").set_defaults(fn=cmd_test)
|
||
sub.add_parser("verify", help="归档完整性校验").set_defaults(fn=cmd_verify)
|
||
sub.add_parser("snapshot", help="登记本轮修订 / 新增").set_defaults(fn=cmd_snapshot)
|
||
sub.add_parser("list", help="查看注册表").set_defaults(fn=cmd_list)
|
||
sub.add_parser("version", help="版本信息").set_defaults(fn=cmd_version)
|
||
|
||
p_build = sub.add_parser("build", help="构建门户 / 交付包")
|
||
p_build.add_argument("target", choices=["portal", *registry.GENERATORS.keys()])
|
||
p_build.add_argument("--apply", action="store_true",
|
||
help="portal 实际执行(默认 dry-run)")
|
||
p_build.set_defaults(fn=cmd_build)
|
||
|
||
a = ap.parse_args(argv)
|
||
return int(a.fn(a) or 0)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|