#!/usr/bin/bash
set -eu
run_dir=/home/smoln/runs/research-deep-20261101
mkdir -p "$run_dir/empty-home" "$run_dir/empty-gopath"
cd "$run_dir/source/core"
date --iso-8601=seconds > "$run_dir/evidence/memory-started.txt"
systemctl --user show research-deep-memory.scope -p CPUQuotaPerSecUSec -p MemoryMax -p MemorySwapMax > "$run_dir/evidence/resource-limits.txt"
set +e
/usr/bin/time -v -o "$run_dir/evidence/memory-resources.txt" env -i PATH=/usr/local/go/bin:/usr/bin:/bin HOME="$run_dir/empty-home" GOCACHE=/home/smoln/.cache/go-build GOPATH="$run_dir/empty-gopath" GOENV=off GOPROXY=off GOSUMDB=off GOTOOLCHAIN=local GOMAXPROCS=1 RESEARCH_FIXTURES="$run_dir/rag-fixtures.json" RESEARCH_RESULTS="$run_dir/evidence/capy-retrieval.json" RESEARCH_SCOPE_RESULTS="$run_dir/evidence/capy-scope.json" timeout 600s go test -p 1 ./internal/memory -run '^TestResearch' -count=1 -json -timeout=90s > "$run_dir/evidence/memory-test-events.jsonl" 2> "$run_dir/evidence/memory-stderr.txt"
status=$?
printf '%s\n' "$status" > "$run_dir/evidence/memory-exit.txt"
date --iso-8601=seconds > "$run_dir/evidence/memory-ended.txt"
exit "$status"
