research: save repeatable experiment and sanitized environment manifest
This commit is contained in:
+2
-2
@@ -29,10 +29,10 @@ Durable intent до S3 PUT, row lock на время PUT/финализации
|
||||
```sh
|
||||
# Исследование получает admin keys только в отдельном profile tools.
|
||||
# Создаёт отдельные БД и bucket, очищает только их в finally.
|
||||
docker compose run --rm --no-deps research > evidence/reconcile-repeat-raw.txt 2>&1
|
||||
uv run --locked python research/run_local.py --output evidence/reconcile-repeat.json
|
||||
```
|
||||
|
||||
В строке `RESULT ` находится JSON с исходными счётчиками, проверками, хешами кода и результатами времени. Основная messenger БД и bucket не очищаются.
|
||||
Контроллер сохраняет raw output, JSON со счётчиками, проверками, хешами кода, результатами времени и кратким host manifest; рядом создаётся summary.md. В исходном выводе контейнера JSON начинается со строки `RESULT `. Основная messenger БД и bucket не очищаются.
|
||||
|
||||
Ошибки: настоящий trigger PostgreSQL после PUT; реальная ошибка подключения S3; успешный COMMIT с искусственно потерянным подтверждением; ошибка DELETE PostgreSQL после удаления bytes; ошибка S3 delete. Проверяются повтор, dry-run после сбоя, старый intent со свежим объектом, live row lock, missing used metadata и сохранность подтверждённого оригинала.
|
||||
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
"""Run and save the isolated experiment, plus a small sanitized host manifest."""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import platform
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--output", default="evidence/reconcile-study.json")
|
||||
args = parser.parse_args()
|
||||
output = ROOT / args.output
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
run = subprocess.run(
|
||||
["docker", "compose", "run", "--rm", "--no-deps", "research"],
|
||||
cwd=ROOT,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
output.with_suffix(".raw.txt").write_text(run.stdout + run.stderr)
|
||||
if run.returncode:
|
||||
raise SystemExit(f"Experiment failed; inspect {output.with_suffix('.raw.txt')}")
|
||||
marker = next(
|
||||
(line[7:] for line in run.stdout.splitlines() if line.startswith("RESULT ")), None
|
||||
)
|
||||
if marker is None:
|
||||
raise SystemExit("Experiment did not emit RESULT")
|
||||
result = json.loads(marker)
|
||||
result["host_manifest"] = {
|
||||
"system": platform.system(),
|
||||
"machine": platform.machine(),
|
||||
"release": platform.release(),
|
||||
"git_revision": subprocess.check_output(
|
||||
["git", "rev-parse", "HEAD"], cwd=ROOT, text=True
|
||||
).strip(),
|
||||
}
|
||||
result["host_manifest"]["docker"] = json.loads(
|
||||
subprocess.check_output(
|
||||
[
|
||||
"docker",
|
||||
"info",
|
||||
"--format",
|
||||
'{"version":"{{.ServerVersion}}","cpus":{{.NCPU}},"memory_bytes":{{.MemTotal}}}',
|
||||
],
|
||||
text=True,
|
||||
)
|
||||
)
|
||||
containers = subprocess.check_output(
|
||||
["docker", "compose", "ps", "-q"], cwd=ROOT, text=True
|
||||
).split()
|
||||
result["host_manifest"]["containers"] = []
|
||||
for container in containers:
|
||||
record = json.loads(subprocess.check_output(["docker", "inspect", container], text=True))[0]
|
||||
result["host_manifest"]["containers"].append(
|
||||
{
|
||||
"service": record["Config"]["Labels"].get("com.docker.compose.service"),
|
||||
"image": record["Image"],
|
||||
"cpu_nano": record["HostConfig"]["NanoCpus"],
|
||||
"memory_limit": record["HostConfig"]["Memory"],
|
||||
}
|
||||
)
|
||||
output.write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n")
|
||||
subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"research/analyze.py",
|
||||
str(output),
|
||||
"--output",
|
||||
str(output.with_suffix(".summary.md")),
|
||||
],
|
||||
cwd=ROOT,
|
||||
check=True,
|
||||
)
|
||||
print(
|
||||
f"Saved {len(result['checks'])} checks and {len(result['scan_cost'])} scan runs to {output}"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user