diff --git a/tier2/gen-worker/scripts/store_roundtrip_harness.py b/tier2/gen-worker/scripts/store_roundtrip_harness.py index ee5a89cc..1d042056 100644 --- a/tier2/gen-worker/scripts/store_roundtrip_harness.py +++ b/tier2/gen-worker/scripts/store_roundtrip_harness.py @@ -89,18 +89,21 @@ def _rebuild(sp: dict) -> dict: if not esbuild: return {"source_digest": source_digest, "bundle_sha256": None, "mode": "source-bytes"} # 真 esbuild:把源写进临时目录、bundle 出单文件、算 sha256(bundle)。 + # 关键:cwd=tmp + 相对 entry/outfile 跑 esbuild。esbuild bundle 会把入口【路径】作为模块注释写进 + # 产物(`// `);若传绝对路径,mkdtemp 每次目录名不同 → 注释不同 → bundle 字节跨目录不稳, + # 会把「重建确定性」误判为失败(实为 harness 自身路径泄漏,非 store / esbuild 不确定)。故用 cwd + + # 相对路径,让注释恒为 `// src/game-logic.js`,bundle 字节跨目录稳定(2026-07-05 mini-infra 真库窗口实测坐实)。 tmp = Path(tempfile.mkdtemp(prefix="t2-rebuild-")) try: for f in files: dst = tmp / f["path"] dst.parent.mkdir(parents=True, exist_ok=True) dst.write_text(f["content"], encoding="utf-8") - out = tmp / "bundle.js" + entry = sp.get("entry") or "src/game-logic.js" subprocess.run( - [esbuild, str(tmp / (sp.get("entry") or "src/game-logic.js")), - "--bundle", f"--outfile={out}"], - check=True, capture_output=True, timeout=60) - bundle_sha = hashlib.sha256(out.read_bytes()).hexdigest() + [esbuild, entry, "--bundle", "--outfile=bundle.js"], + check=True, capture_output=True, timeout=60, cwd=str(tmp)) + bundle_sha = hashlib.sha256((tmp / "bundle.js").read_bytes()).hexdigest() return {"source_digest": source_digest, "bundle_sha256": bundle_sha, "mode": "bundle"} finally: shutil.rmtree(tmp, ignore_errors=True)