Просмотр исходного кода

fix(test): repair split-repository acceptance tooling

root 3 месяцев назад
Родитель
Сommit
e469021c5f

+ 12 - 18
tools/package_hth_review.py

@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 #!/usr/bin/env python3
-"""Draft packager: zip host/ (no .git, venv, caches) to /tmp/hth-platform-review-*.zip.
+"""Package the standalone HTH repository under a compatibility ``host/`` prefix.
 
 
-Parent may run this later. Works without the `zip` / `rsync` binaries.
+Works without the `zip` / `rsync` binaries.
 """
 """
 
 
 from __future__ import annotations
 from __future__ import annotations
@@ -90,12 +90,14 @@ def _tools_text() -> str:
     return "\n".join(lines) + "\n"
     return "\n".join(lines) + "\n"
 
 
 
 
-def snapshot_evidence(repo: Path, host_root: Path) -> dict[str, bytes]:
+def snapshot_evidence(host_root: Path) -> dict[str, bytes]:
     mapping = {
     mapping = {
-        "evidence/host-contract.json": repo / "src" / "generated" / "host-contract.json",
-        "evidence/golden-vectors.json": repo / "src" / "generated" / "golden-vectors.json",
-        "evidence/prod2u-door-temp-protocol.zh-CN.md": repo / "docs" / "prod2u-door-temp-protocol.zh-CN.md",
-        "evidence/project.json": repo / "projects" / "prod2u-door-temp" / "project.json",
+        "evidence/host-contract.json": host_root / "contracts" / "evidence" / "host-contract.json",
+        "evidence/golden-vectors.json": host_root / "contracts" / "evidence" / "golden-vectors.json",
+        "evidence/legacy-RTL_REF.txt": host_root / "contracts" / "evidence" / "RTL_REF.txt",
+        "evidence/legacy-SHA256SUMS": host_root / "contracts" / "evidence" / "SHA256SUMS",
+        "evidence/6400-host-contract.json": host_root / "contracts" / "6400" / "host-contract.json",
+        "evidence/6400-SHA256SUMS": host_root / "contracts" / "6400" / "SHA256SUMS",
         "evidence/profile.json": host_root / "profiles" / "prod2u-door-temp" / "profile.json",
         "evidence/profile.json": host_root / "profiles" / "prod2u-door-temp" / "profile.json",
         "evidence/hth.proto": host_root / "api" / "proto" / "hth" / "api" / "v1" / "hth.proto",
         "evidence/hth.proto": host_root / "api" / "proto" / "hth" / "api" / "v1" / "hth.proto",
     }
     }
@@ -137,7 +139,7 @@ def main() -> int:
 
 
     global _ZIP_DATE
     global _ZIP_DATE
     host_root = Path(__file__).resolve().parents[1]
     host_root = Path(__file__).resolve().parents[1]
-    repo_root = host_root.parent
+    repo_root = host_root
     stamp = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
     stamp = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
     head, short, diffstat = git_info(repo_root)
     head, short, diffstat = git_info(repo_root)
     run_id = os.environ.get("HTH_RUN_ID") or stamp
     run_id = os.environ.get("HTH_RUN_ID") or stamp
@@ -187,7 +189,7 @@ It does not mean the device acknowledged execution. Current UART has no ACK.
 
 
 ## Layout
 ## Layout
 
 
-- `host/` daemon, proto, Python SDK, docs, deploy, reviews
+- `host/` standalone HTH daemon, proto, Python SDK, docs, deploy, reviews
 - `run/` this-run logs only
 - `run/` this-run logs only
 - `reviews/` five current authority reports
 - `reviews/` five current authority reports
 - `MANIFEST.json` / `MANIFEST` / `SHA256SUMS`
 - `MANIFEST.json` / `MANIFEST` / `SHA256SUMS`
@@ -217,16 +219,8 @@ python3 host/tools/verify_review_package.py . --mode release
         "source_date_epoch": int(epoch),
         "source_date_epoch": int(epoch),
     }
     }
     extras[f"{root_name}/PACKAGE_IDENTITY.json"] = (json.dumps(ident, indent=2).encode("utf-8") + b"\n", 0o644, "meta")
     extras[f"{root_name}/PACKAGE_IDENTITY.json"] = (json.dumps(ident, indent=2).encode("utf-8") + b"\n", 0o644, "meta")
-    for name, data in snapshot_evidence(repo_root, host_root).items():
+    for name, data in snapshot_evidence(host_root).items():
         extras[f"{root_name}/{name}"] = (data, 0o644, "evidence")
         extras[f"{root_name}/{name}"] = (data, 0o644, "evidence")
-        aliases = {
-            "evidence/host-contract.json": "src/generated/host-contract.json",
-            "evidence/golden-vectors.json": "src/generated/golden-vectors.json",
-            "evidence/project.json": "projects/prod2u-door-temp/project.json",
-            "evidence/prod2u-door-temp-protocol.zh-CN.md": "docs/prod2u-door-temp-protocol.zh-CN.md",
-        }
-        if name in aliases:
-            extras[f"{root_name}/{aliases[name]}"] = (data, 0o644, "evidence")
     run_dir = os.environ.get("HTH_RUN_DIR", "").strip()
     run_dir = os.environ.get("HTH_RUN_DIR", "").strip()
     if run_dir:
     if run_dir:
         rd = Path(run_dir)
         rd = Path(run_dir)

+ 1 - 1
tools/package_hth_user_kits.py

@@ -127,7 +127,7 @@ def find_wheel() -> Path:
     dist = sorted((_sdk() / "dist").glob("hth_sdk-*.whl")) if (_sdk() / "dist").is_dir() else []
     dist = sorted((_sdk() / "dist").glob("hth_sdk-*.whl")) if (_sdk() / "dist").is_dir() else []
     if dist:
     if dist:
         return dist[-1]
         return dist[-1]
-    raise SystemExit("set HTH_SDK_WHEEL or build host/sdk/python wheel first")
+    raise SystemExit("set HTH_SDK_WHEEL or build sdk/python wheel first")
 
 
 
 
 def _script_bytes(name: str) -> bytes:
 def _script_bytes(name: str) -> bytes:

+ 56 - 11
tools/rtl_uart_cosim/run_hthd_pty_rtl.py

@@ -9,6 +9,7 @@ from __future__ import annotations
 import os
 import os
 import pty
 import pty
 import select
 import select
+import shutil
 import socket
 import socket
 import subprocess
 import subprocess
 import sys
 import sys
@@ -41,6 +42,10 @@ def _cad_root() -> Path | None:
     return None
     return None
 
 
 
 
+def _system_cad_available() -> bool:
+    return all(shutil.which(tool) for tool in ("iverilog", "vvp"))
+
+
 def _python_libdir(python: Path) -> str:
 def _python_libdir(python: Path) -> str:
     r = subprocess.run(
     r = subprocess.run(
         [str(python), "-c", "import sysconfig; print(sysconfig.get_config_var('LIBDIR') or '')"],
         [str(python), "-c", "import sysconfig; print(sysconfig.get_config_var('LIBDIR') or '')"],
@@ -53,6 +58,25 @@ def _python_libdir(python: Path) -> str:
     return (r.stdout or "").strip()
     return (r.stdout or "").strip()
 
 
 
 
+def _python_library(python: Path) -> str:
+    r = subprocess.run(
+        [
+            str(python),
+            "-c",
+            "import pathlib,sysconfig; "
+            "print(pathlib.Path(sysconfig.get_config_var('LIBDIR') or '') / "
+            "(sysconfig.get_config_var('LDLIBRARY') or ''))",
+        ],
+        stdout=subprocess.PIPE,
+        stderr=subprocess.DEVNULL,
+        text=True,
+        timeout=10,
+        env={k: v for k, v in os.environ.items() if k not in OSS_CAD_POISON},
+    )
+    candidate = Path((r.stdout or "").strip())
+    return str(candidate) if candidate.is_file() else ""
+
+
 def _write_clean_cad_shims(shim: Path, cad: Path, extra_libs: list[str] | None = None) -> None:
 def _write_clean_cad_shims(shim: Path, cad: Path, extra_libs: list[str] | None = None) -> None:
     """Call libexec iverilog/vvp without the OSS CAD vvp wrapper's PYTHONEXECUTABLE poison."""
     """Call libexec iverilog/vvp without the OSS CAD vvp wrapper's PYTHONEXECUTABLE poison."""
     shim.mkdir(parents=True, exist_ok=True)
     shim.mkdir(parents=True, exist_ok=True)
@@ -79,6 +103,12 @@ def _write_clean_cad_shims(shim: Path, cad: Path, extra_libs: list[str] | None =
 
 
 
 
 def _select_cocotb_python() -> Path | None:
 def _select_cocotb_python() -> Path | None:
+    probe = """import cocotb
+try:
+    import cocotb_tools.runner
+except ModuleNotFoundError:
+    import cocotb.runner
+"""
     candidates = [
     candidates = [
         Path(os.environ.get("PROD2U_P4_COCOTB_PYTHON", "")),
         Path(os.environ.get("PROD2U_P4_COCOTB_PYTHON", "")),
         Path("/opt/hth-cocotb312/bin/python"),
         Path("/opt/hth-cocotb312/bin/python"),
@@ -91,7 +121,7 @@ def _select_cocotb_python() -> Path | None:
         if not cand.is_file():
         if not cand.is_file():
             continue
             continue
         r = subprocess.run(
         r = subprocess.run(
-            [str(cand), "-B", "-c", "import cocotb, cocotb_tools"],
+            [str(cand), "-B", "-c", probe],
             stdout=subprocess.DEVNULL,
             stdout=subprocess.DEVNULL,
             stderr=subprocess.DEVNULL,
             stderr=subprocess.DEVNULL,
             timeout=20,
             timeout=20,
@@ -124,14 +154,21 @@ def _sdk_python() -> Path:
     return Path(sys.executable)
     return Path(sys.executable)
 
 
 
 
-def _shim_dir(build: Path, python: Path, cad: Path) -> Path:
+def _shim_dir(build: Path, python: Path, cad: Path | None) -> Path:
     shim = build / "path-shim"
     shim = build / "path-shim"
-    extra = []
-    pydir = _python_libdir(python)
-    if pydir:
-        extra.append(pydir)
-    extra.append("/opt/python-3.12/lib")
-    _write_clean_cad_shims(shim, cad, extra)
+    if cad is not None:
+        extra = []
+        pydir = _python_libdir(python)
+        if pydir:
+            extra.append(pydir)
+        extra.append("/opt/python-3.12/lib")
+        _write_clean_cad_shims(shim, cad, extra)
+    else:
+        shim.mkdir(parents=True, exist_ok=True)
+        for name in ("iverilog", "vvp"):
+            resolved = shutil.which(name)
+            if resolved:
+                (shim / name).symlink_to(resolved)
     for name in ("python", "python3"):
     for name in ("python", "python3"):
         path = shim / name
         path = shim / name
         if path.exists() or path.is_symlink():
         if path.exists() or path.is_symlink():
@@ -535,7 +572,10 @@ asyncio.run(main())
 
 
 def _run_sim_child() -> int:
 def _run_sim_child() -> int:
     py = Path(os.environ["PYGPI_PYTHON_BIN"])
     py = Path(os.environ["PYGPI_PYTHON_BIN"])
-    from cocotb_tools.runner import get_runner
+    try:
+        from cocotb_tools.runner import get_runner
+    except ModuleNotFoundError:
+        from cocotb.runner import get_runner
 
 
     uart_top, hdl_top, clks = _uart_choice()
     uart_top, hdl_top, clks = _uart_choice()
     runner = get_runner("icarus")
     runner = get_runner("icarus")
@@ -582,6 +622,7 @@ def main() -> int:
 
 
     skip = "--skip-missing" in sys.argv
     skip = "--skip-missing" in sys.argv
     cad = _cad_root()
     cad = _cad_root()
+    cad_available = cad is not None or _system_cad_available()
     py = _select_cocotb_python()
     py = _select_cocotb_python()
     uart_top, hdl_top, clks = _uart_choice()
     uart_top, hdl_top, clks = _uart_choice()
     try:
     try:
@@ -593,9 +634,11 @@ def main() -> int:
         return 2
         return 2
     if not uart_top.is_file():
     if not uart_top.is_file():
         missing_rtl.append(str(uart_top))
         missing_rtl.append(str(uart_top))
-    if cad is None or py is None or missing_rtl:
+    if not cad_available or py is None or missing_rtl:
         print("RTL-in-the-loop hthd+PTY+UART-bit: NOT RUN")
         print("RTL-in-the-loop hthd+PTY+UART-bit: NOT RUN")
         print("cad_root:", cad)
         print("cad_root:", cad)
+        print("iverilog:", shutil.which("iverilog"))
+        print("vvp:", shutil.which("vvp"))
         print("cocotb_python:", py)
         print("cocotb_python:", py)
         print("missing_rtl:", ",".join(missing_rtl) or "none")
         print("missing_rtl:", ",".join(missing_rtl) or "none")
         return 2
         return 2
@@ -641,7 +684,9 @@ def main() -> int:
     )
     )
 
 
     env = {k: v for k, v in os.environ.items() if k not in OSS_CAD_POISON}
     env = {k: v for k, v in os.environ.items() if k not in OSS_CAD_POISON}
-    libpython = os.environ.get("LIBPYTHON_LOC", "/opt/python-3.12/lib/libpython3.12.so.1.0")
+    libpython = os.environ.get("LIBPYTHON_LOC") or _python_library(py)
+    if not libpython:
+        libpython = "/opt/python-3.12/lib/libpython3.12.so.1.0"
     env["PATH"] = os.pathsep.join([str(py.parent), str(shim), "/usr/bin", "/bin"])
     env["PATH"] = os.pathsep.join([str(py.parent), str(shim), "/usr/bin", "/bin"])
     env["LD_LIBRARY_PATH"] = "/opt/python-3.12/lib" + os.pathsep + env.get("LD_LIBRARY_PATH", "")
     env["LD_LIBRARY_PATH"] = "/opt/python-3.12/lib" + os.pathsep + env.get("LD_LIBRARY_PATH", "")
     env["PYTHONPATH"] = str(HERE) + os.pathsep + str(RTL_REPO)
     env["PYTHONPATH"] = str(HERE) + os.pathsep + str(RTL_REPO)

+ 50 - 26
tools/rtl_uart_cosim/test_hthd_pty_bridge.py

@@ -19,7 +19,7 @@ CLKS_PER_BIT = int(os.environ.get("HTH_CLKS_PER_BIT", "8"))
 async def clocks(dut, count: int) -> None:
 async def clocks(dut, count: int) -> None:
     clk = getattr(getattr(dut, "u_dut", None), "sys_clk", None)
     clk = getattr(getattr(dut, "u_dut", None), "sys_clk", None)
     if clk is None or count <= 0:
     if clk is None or count <= 0:
-        await Timer(max(count, 1) * 40, unit="ns")
+        await Timer(max(count, 1) * 40, units="ns")
         return
         return
     if count < 32:
     if count < 32:
         for _ in range(count):
         for _ in range(count):
@@ -27,7 +27,7 @@ async def clocks(dut, count: int) -> None:
         return
         return
     # Advance sim time in one wait, then sync to a clock edge. 217 RisingEdge
     # Advance sim time in one wait, then sync to a clock edge. 217 RisingEdge
     # callbacks per bit made production UART miss the host probe window.
     # callbacks per bit made production UART miss the host probe window.
-    await Timer((count - 1) * 40, unit="ns")
+    await Timer((count - 1) * 40, units="ns")
     await RisingEdge(clk)
     await RisingEdge(clk)
 
 
 
 
@@ -100,6 +100,31 @@ def _start_socket_threads(sock: socket.socket) -> tuple[queue.Queue, queue.Queue
     return rx_q, tx_q
     return rx_q, tx_q
 
 
 
 
+async def finish_axis_calibration(dut, step_sig, limit_ls, limit_hs, axis: str) -> int:
+    """Let one serial axis measure at least two open steps, then hit its open limit."""
+    rises = {"n": 0}
+
+    async def count_rises():
+        while True:
+            await RisingEdge(step_sig)
+            rises["n"] += 1
+
+    counter = cocotb.start_soon(count_rises())
+    try:
+        for _ in range(100_000):
+            await clocks(dut, 625)
+            if rises["n"] >= 2:
+                break
+        else:
+            raise AssertionError(f"insufficient measure-open rises axis={axis} rises={rises['n']}")
+        limit_hs.value = 1
+        limit_ls.value = 0
+        await clocks(dut, 4000)
+        return rises["n"]
+    finally:
+        counter.kill()
+
+
 @cocotb.test()
 @cocotb.test()
 async def test_hthd_pty_set_all(dut):
 async def test_hthd_pty_set_all(dut):
     result = _result_path()
     result = _result_path()
@@ -120,21 +145,12 @@ async def test_hthd_pty_set_all(dut):
     rx_q, tx_q = _start_socket_threads(sock)
     rx_q, tx_q = _start_socket_threads(sock)
     Path(os.environ["HTH_BRIDGE_READY"]).write_text("ready\n", encoding="utf-8")
     Path(os.environ["HTH_BRIDGE_READY"]).write_text("ready\n", encoding="utf-8")
 
 
-    x_rises = {"n": 0}
-
-    async def count_x():
-        while True:
-            await RisingEdge(dut.x_step)
-            x_rises["n"] += 1
-
-    cocotb.start_soon(count_x())
-
     async def host_to_dut():
     async def host_to_dut():
         while True:
         while True:
             try:
             try:
                 value = rx_q.get_nowait()
                 value = rx_q.get_nowait()
             except queue.Empty:
             except queue.Empty:
-                await Timer(1, unit="us")
+                await Timer(1, units="us")
                 continue
                 continue
             await send_uart_byte(dut, value)
             await send_uart_byte(dut, value)
 
 
@@ -148,21 +164,29 @@ async def test_hthd_pty_set_all(dut):
                 value = await with_timeout(receive_uart_byte(dut), rx_timeout_s, "sec")
                 value = await with_timeout(receive_uart_byte(dut), rx_timeout_s, "sec")
                 tx_q.put(value)
                 tx_q.put(value)
             except Exception:
             except Exception:
-                await Timer(1, unit="us")
+                await Timer(1, units="us")
 
 
     cocotb.start_soon(host_to_dut())
     cocotb.start_soon(host_to_dut())
     cocotb.start_soon(dut_to_host())
     cocotb.start_soon(dut_to_host())
 
 
-    for _ in range(40000):
-        await clocks(dut, 2500)
-        if x_rises["n"] >= 2:
-            break
-    dut.x_limit_hs.value = 1
-    dut.y_limit_hs.value = 1
-    dut.z_limit_hs.value = 1
-    dut.x_limit_ls.value = 0
-    dut.y_limit_ls.value = 0
-    dut.z_limit_ls.value = 0
+    # Calibration is serial X -> Y -> Z. Asserting Y/Z open limits while they
+    # are still in seek-close strands those axes until their 5000-step fault
+    # cap, so each open limit is asserted only after that axis starts measure-open.
+    x_rises = await finish_axis_calibration(
+        dut, dut.x_step, dut.x_limit_ls, dut.x_limit_hs, "x"
+    )
+    y_rises = await finish_axis_calibration(
+        dut, dut.y_step, dut.y_limit_ls, dut.y_limit_hs, "y"
+    )
+    z_rises = await finish_axis_calibration(
+        dut, dut.z_step, dut.z_limit_ls, dut.z_limit_hs, "z"
+    )
+    cocotb.log.info(
+        "serial calibration complete x_rises=%d y_rises=%d z_rises=%d",
+        x_rises,
+        y_rises,
+        z_rises,
+    )
 
 
     matched_startup = False
     matched_startup = False
     for _ in range(200000):
     for _ in range(200000):
@@ -183,7 +207,7 @@ async def test_hthd_pty_set_all(dut):
     target = int(os.environ.get("HTH_EXPECT_PERCENT", "50"))
     target = int(os.environ.get("HTH_EXPECT_PERCENT", "50"))
     matched = False
     matched = False
     for _ in range(40000):
     for _ in range(40000):
-        await Timer(0.2, unit="ms")
+        await Timer(0.2, units="ms")
         try:
         try:
             x = int(dut.u_dut.door_percent_x.value)
             x = int(dut.u_dut.door_percent_x.value)
             y = int(dut.u_dut.door_percent_y.value)
             y = int(dut.u_dut.door_percent_y.value)
@@ -196,7 +220,7 @@ async def test_hthd_pty_set_all(dut):
 
 
     if not matched:
     if not matched:
         result.write_text(
         result.write_text(
-            f"FAIL door percents never reached {target} sim={get_sim_time(unit='ns')}ns\n",
+            f"FAIL door percents never reached {target} sim={get_sim_time(units='ns')}ns\n",
             encoding="utf-8",
             encoding="utf-8",
         )
         )
         raise AssertionError("RTL did not latch hthd SET_ALL percents")
         raise AssertionError("RTL did not latch hthd SET_ALL percents")
@@ -208,4 +232,4 @@ async def test_hthd_pty_set_all(dut):
     for _ in range(400000):
     for _ in range(400000):
         if stop and stop.is_file():
         if stop and stop.is_file():
             return
             return
-        await Timer(1, unit="us")
+        await Timer(1, units="us")

+ 7 - 2
tools/run_algorithm_gates.sh

@@ -7,6 +7,11 @@ SDK="${SRC}/sdk/python"
 RUN="${HTH_RUN_DIR:-/tmp/hth-algo-run}"
 RUN="${HTH_RUN_DIR:-/tmp/hth-algo-run}"
 PKG="${HTH_PACKAGE_DIR:-/tmp}"
 PKG="${HTH_PACKAGE_DIR:-/tmp}"
 mkdir -p "$RUN" "$PKG"
 mkdir -p "$RUN" "$PKG"
+SDK_BUILD="${RUN}/sdk-build-src"
+rm -rf "$SDK_BUILD"
+mkdir -p "$SDK_BUILD"
+cp -a "$SDK/." "$SDK_BUILD/"
+rm -rf "$SDK_BUILD/build" "$SDK_BUILD/hth_sdk.egg-info" "$SDK_BUILD/.pytest_cache"
 export HTH_RUN_DIR="$RUN"
 export HTH_RUN_DIR="$RUN"
 export HTH_PACKAGE_DIR="$PKG"
 export HTH_PACKAGE_DIR="$PKG"
 export HTH_GIT_COMMIT="${HTH_GIT_COMMIT:-unknown}"
 export HTH_GIT_COMMIT="${HTH_GIT_COMMIT:-unknown}"
@@ -32,13 +37,13 @@ PY
 BUILD_PY="${PYTHON:-python3}"
 BUILD_PY="${PYTHON:-python3}"
 if [[ -x /data/prod2u/venvs/hth-verify/bin/python ]]; then
 if [[ -x /data/prod2u/venvs/hth-verify/bin/python ]]; then
   BUILD_PY=/data/prod2u/venvs/hth-verify/bin/python
   BUILD_PY=/data/prod2u/venvs/hth-verify/bin/python
-elif ! "$BUILD_PY" -c 'import build' >/dev/null 2>&1; then
+elif ! "$BUILD_PY" -c 'import build.__main__' >/dev/null 2>&1; then
   VENV="${RUN}/build-venv"
   VENV="${RUN}/build-venv"
   "$BUILD_PY" -m venv "$VENV"
   "$BUILD_PY" -m venv "$VENV"
   "$VENV/bin/pip" install -q -i https://mirrors.aliyun.com/pypi/simple build
   "$VENV/bin/pip" install -q -i https://mirrors.aliyun.com/pypi/simple build
   BUILD_PY="$VENV/bin/python"
   BUILD_PY="$VENV/bin/python"
 fi
 fi
-rec algorithm-wheel "$BUILD_PY" -m build --wheel --outdir "${RUN}/dist" .
+rec algorithm-wheel "$BUILD_PY" -m build --wheel --outdir "${RUN}/dist" "$SDK_BUILD"
 WHEEL="$(ls -1t "${RUN}/dist"/hth_sdk-*.whl 2>/dev/null | head -n1 || true)"
 WHEEL="$(ls -1t "${RUN}/dist"/hth_sdk-*.whl 2>/dev/null | head -n1 || true)"
 export HTH_SDK_WHEEL="$WHEEL"
 export HTH_SDK_WHEEL="$WHEEL"
 export HTH_USER_KIT="${HTH_USER_KIT:-linux}"
 export HTH_USER_KIT="${HTH_USER_KIT:-linux}"

+ 15 - 4
tools/run_host_verify.sh

@@ -12,7 +12,12 @@ else
 fi
 fi
 
 
 export PATH="/usr/bin:/bin:/usr/local/bin:/opt/python-3.13/bin:/opt/python-3.12/bin:/opt/python-3.11/bin:/data/prod2u/opt/go1.25.13/bin:/root/go/bin:/data/prod2u/oss-cad-suite/latest/bin:${PATH}"
 export PATH="/usr/bin:/bin:/usr/local/bin:/opt/python-3.13/bin:/opt/python-3.12/bin:/opt/python-3.11/bin:/data/prod2u/opt/go1.25.13/bin:/root/go/bin:/data/prod2u/oss-cad-suite/latest/bin:${PATH}"
-export GOROOT="${GOROOT:-/data/prod2u/opt/go1.25.13}"
+if [[ -n "${GOROOT:-}" && ! -d "${GOROOT}" ]]; then
+  unset GOROOT
+fi
+if [[ -z "${GOROOT:-}" && -d /data/prod2u/opt/go1.25.13 ]]; then
+  export GOROOT=/data/prod2u/opt/go1.25.13
+fi
 export GOTOOLCHAIN="${GOTOOLCHAIN:-local}"
 export GOTOOLCHAIN="${GOTOOLCHAIN:-local}"
 export GOFLAGS="${GOFLAGS:-}"
 export GOFLAGS="${GOFLAGS:-}"
 if [[ -z "${PYTHON:-}" ]]; then
 if [[ -z "${PYTHON:-}" ]]; then
@@ -27,16 +32,22 @@ fi
 
 
 SRC="${HTH_SRC:-$(cd "$(dirname "$0")/.." && pwd)}"
 SRC="${HTH_SRC:-$(cd "$(dirname "$0")/.." && pwd)}"
 if [[ -z "${HTH_SKIP_LINUX_WORKTREE:-}" && -d /data/prod2u && -n "$(git -C "${SRC}" rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then
 if [[ -z "${HTH_SKIP_LINUX_WORKTREE:-}" && -d /data/prod2u && -n "$(git -C "${SRC}" rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then
+  SOURCE_HEAD="$(git -C "${SRC}" rev-parse HEAD)"
   SHORT_HINT="$(git -C "${SRC}" rev-parse --short HEAD 2>/dev/null || echo host)"
   SHORT_HINT="$(git -C "${SRC}" rev-parse --short HEAD 2>/dev/null || echo host)"
-  WT="${HTH_LINUX_WORKTREE:-/data/prod2u/worktrees/hth-host-${SHORT_HINT}}"
+  WT="${HTH_LINUX_WORKTREE:-/data/prod2u/worktrees/hth-verify-${SHORT_HINT}}"
   if [[ ! -e "${WT}/.git" ]]; then
   if [[ ! -e "${WT}/.git" ]]; then
     mkdir -p "$(dirname "${WT}")"
     mkdir -p "$(dirname "${WT}")"
-    git -C "${SRC}" worktree add --detach "${WT}" HEAD || true
+    git clone --quiet --no-hardlinks --no-checkout "${SRC}" "${WT}" || true
+    git -C "${WT}" checkout --quiet --detach "${SOURCE_HEAD}" || true
   fi
   fi
-  if git -C "${WT}" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
+  if git -C "${WT}" rev-parse --is-inside-work-tree >/dev/null 2>&1 \
+      && [[ "$(git -C "${WT}" rev-parse HEAD)" == "${SOURCE_HEAD}" ]]; then
     SRC="${WT}"
     SRC="${WT}"
   fi
   fi
 fi
 fi
+if [[ -z "${HTH_CPLD_ROOT:-}" && -d /workspace/cpld-temperature-control ]]; then
+  export HTH_CPLD_ROOT=/workspace/cpld-temperature-control
+fi
 cd "${SRC}"
 cd "${SRC}"
 export HTH_GIT_ROOT="${SRC}"
 export HTH_GIT_ROOT="${SRC}"
 export HTH_GIT_SCOPE=all
 export HTH_GIT_SCOPE=all

+ 6 - 1
tools/sdk_wheel_matrix.sh

@@ -6,6 +6,11 @@ ROOT="$(cd "$(dirname "$0")/.." && pwd)"
 SDK="$ROOT/sdk/python"
 SDK="$ROOT/sdk/python"
 WORKDIR="${TMPDIR:-/tmp}/hth-sdk-matrix"
 WORKDIR="${TMPDIR:-/tmp}/hth-sdk-matrix"
 mkdir -p "$WORKDIR/dist" "$WORKDIR/run"
 mkdir -p "$WORKDIR/dist" "$WORKDIR/run"
+SDK_BUILD="$WORKDIR/sdk-src"
+rm -rf "$SDK_BUILD"
+mkdir -p "$SDK_BUILD"
+cp -a "$SDK/." "$SDK_BUILD/"
+rm -rf "$SDK_BUILD/build" "$SDK_BUILD/hth_sdk.egg-info" "$SDK_BUILD/.pytest_cache"
 export PATH="/opt/python-3.11/bin:/opt/python-3.12/bin:/usr/bin:/data/prod2u/opt/go1.25.13/bin:/root/go/bin:${PATH}"
 export PATH="/opt/python-3.11/bin:/opt/python-3.12/bin:/usr/bin:/data/prod2u/opt/go1.25.13/bin:/root/go/bin:${PATH}"
 export GOTOOLCHAIN="${GOTOOLCHAIN:-local}"
 export GOTOOLCHAIN="${GOTOOLCHAIN:-local}"
 if [[ -d /data/prod2u/opt/go1.25.13 ]]; then
 if [[ -d /data/prod2u/opt/go1.25.13 ]]; then
@@ -18,7 +23,7 @@ BUILD_VENV="$WORKDIR/build-venv"
 rm -rf "$BUILD_VENV"
 rm -rf "$BUILD_VENV"
 "$PY_BUILD" -m venv "$BUILD_VENV"
 "$PY_BUILD" -m venv "$BUILD_VENV"
 "$BUILD_VENV/bin/pip" install -q -i https://mirrors.aliyun.com/pypi/simple build
 "$BUILD_VENV/bin/pip" install -q -i https://mirrors.aliyun.com/pypi/simple build
-"$BUILD_VENV/bin/python" -m build --wheel --outdir "$WORKDIR/dist" "$SDK"
+"$BUILD_VENV/bin/python" -m build --wheel --outdir "$WORKDIR/dist" "$SDK_BUILD"
 WHEEL="$(ls -1t "$WORKDIR/dist"/hth_sdk-*.whl | head -n1)"
 WHEEL="$(ls -1t "$WORKDIR/dist"/hth_sdk-*.whl | head -n1)"
 echo "wheel=$WHEEL"
 echo "wheel=$WHEEL"