#!/usr/bin/bash
set -eu
run_dir=/home/smoln/runs/research-deep-20261101
cd "$run_dir/source/core"
systemctl --user show research-deep-second.scope -p CPUQuotaPerSecUSec -p MemoryMax -p MemorySwapMax > "$run_dir/evidence/second-resource-limits.txt"
date --iso-8601=seconds > "$run_dir/evidence/second-started.txt"
set +e
/usr/bin/time -v -o "$run_dir/evidence/second-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_SCOPE_RESULTS="$run_dir/evidence/capy-scope-v2.json" RESEARCH_RECOVERY_RESULTS="$run_dir/evidence/capy-recovery.json" timeout 600s go test -p 1 ./internal/memory -run '^(TestResearchScopeMatrixV2|TestResearchRecoveryMatrixV1|TestInflightToolJournalRecoversKnownAndUnknownResultsOnce|TestCheckpointRejectsMismatchedResultAndKeepsPendingStart|TestConversationToolResultSearchFindsVerifiedSpillsOnlyInBoundChat|TestPromotionCannotCrossTeamOrTenant)$' -count=1 -json -timeout=90s > "$run_dir/evidence/second-test-events.jsonl" 2> "$run_dir/evidence/second-stderr.txt"
status=$?
printf '%s\n' "$status" > "$run_dir/evidence/second-exit.txt"
if ((status!=0));then exit "$status";fi
/usr/bin/time -v -o "$run_dir/evidence/scifact-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/scifact-fixtures.json" RESEARCH_RESULTS="$run_dir/evidence/capy-scifact.json" timeout 600s go test -p 1 ./internal/memory -run '^TestResearchMemoryRetrievalV1$' -count=1 -json -timeout=180s > "$run_dir/evidence/scifact-test-events.jsonl" 2> "$run_dir/evidence/scifact-stderr.txt"
status=$?
printf '%s\n' "$status" > "$run_dir/evidence/scifact-exit.txt"
if ((status!=0));then exit "$status";fi
timeout 600s python3 "$run_dir/baselines.py" "$run_dir" > "$run_dir/evidence/baseline-stdout.txt" 2> "$run_dir/evidence/baseline-stderr.txt"
status=$?
printf '%s\n' "$status" > "$run_dir/evidence/baseline-exit.txt"
date --iso-8601=seconds > "$run_dir/evidence/second-ended.txt"
exit "$status"
