feat(agent): make ingestion preparation reproducible
This commit is contained in:
1 parent
3b1b40f8b3
commit
65bc8a9422
9 files changed
+185
-40
No files matched your search
+53
-2
@@ -42,13 +42,18 @@ def _safe_regular(path: Path) -> bool:
|
||||
|
||||
|
||||
def _validated_state(state: object) -> dict[str, Any]:
|
||||
if not isinstance(state, dict) or set(state) != {
|
||||
base_keys = {
|
||||
"format",
|
||||
"mode",
|
||||
"pack_path",
|
||||
"files",
|
||||
"routes",
|
||||
}:
|
||||
}
|
||||
if (
|
||||
not isinstance(state, dict)
|
||||
or not base_keys.issubset(state)
|
||||
or set(state) - base_keys - {"run_pins"}
|
||||
):
|
||||
raise ValueError("unrecognized GEWU installation state")
|
||||
if (
|
||||
state.get("format") != "gewu-install-state@1"
|
||||
@@ -82,6 +87,38 @@ def _validated_state(state: object) -> dict[str, Any]:
|
||||
or not re.fullmatch(r"[a-f0-9]{64}", route["block_sha256"])
|
||||
):
|
||||
raise ValueError("GEWU installation routes are invalid")
|
||||
if "run_pins" in state:
|
||||
pins = state["run_pins"]
|
||||
if not isinstance(pins, dict) or set(pins) != {
|
||||
"pack_id",
|
||||
"pack_version",
|
||||
"pack_snapshot_digest",
|
||||
"module_pins",
|
||||
}:
|
||||
raise ValueError("GEWU run pins are invalid")
|
||||
if (
|
||||
not isinstance(pins.get("pack_id"), str)
|
||||
or not pins["pack_id"]
|
||||
or not isinstance(pins.get("pack_version"), str)
|
||||
or not pins["pack_version"]
|
||||
or not isinstance(pins.get("pack_snapshot_digest"), str)
|
||||
or not re.fullmatch(r"[a-f0-9]{64}", pins["pack_snapshot_digest"])
|
||||
or not isinstance(pins.get("module_pins"), list)
|
||||
or not pins["module_pins"]
|
||||
):
|
||||
raise ValueError("GEWU run pins are invalid")
|
||||
for module in pins["module_pins"]:
|
||||
if (
|
||||
not isinstance(module, dict)
|
||||
or set(module) != {"module_id", "implementation_version", "sha256"}
|
||||
or not isinstance(module.get("module_id"), str)
|
||||
or not module["module_id"]
|
||||
or not isinstance(module.get("implementation_version"), str)
|
||||
or not module["implementation_version"]
|
||||
or not isinstance(module.get("sha256"), str)
|
||||
or not re.fullmatch(r"[a-f0-9]{64}", module["sha256"])
|
||||
):
|
||||
raise ValueError("GEWU run pins are invalid")
|
||||
return state
|
||||
|
||||
|
||||
@@ -159,6 +196,7 @@ def install(workspace: Path, source: Path = PACK_ROOT, mode: str = "integrated")
|
||||
|
||||
# Prepare all bytes and validate the destinations before mutating the workspace.
|
||||
copied = {name: path.read_bytes() for name, path in source_files.items()}
|
||||
manifest = json.loads(copied["manifest.json"])
|
||||
route_originals = {
|
||||
name: target.read_bytes() if target.exists() else None for name, target in targets.items()
|
||||
}
|
||||
@@ -171,6 +209,19 @@ def install(workspace: Path, source: Path = PACK_ROOT, mode: str = "integrated")
|
||||
"mode": mode,
|
||||
"pack_path": PACK_DIR.as_posix(),
|
||||
"files": {name: digest(content) for name, content in copied.items()},
|
||||
"run_pins": {
|
||||
"pack_id": manifest["pack_id"],
|
||||
"pack_version": manifest["pack_version"],
|
||||
"pack_snapshot_digest": manifest["snapshot"]["digest"],
|
||||
"module_pins": [
|
||||
{
|
||||
"module_id": module["module_id"],
|
||||
"implementation_version": module["implementation_version"],
|
||||
"sha256": module["sha256"],
|
||||
}
|
||||
for module in manifest["modules"]
|
||||
],
|
||||
},
|
||||
"routes": {
|
||||
name: {
|
||||
"block_sha256": digest(route_blocks[name]),
|
||||
|
||||
Reference in new issue
Block a user