#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
cd "$ROOT_DIR"

SANDBOX="$ROOT_DIR/sandbox/two-console"
UUID="11111111-2222-3333-4444-555555555555"
DATASET_NAME="prices-demo-test"
OWNER="agent1"
PEER="agent2"
REQUEST_ID="req-$UUID"
MOCK_REQUEST_ID="req-mock-$UUID"
RESULT_ID="result-$UUID"
BLOCKED_RUN_ID="run-blocked-$UUID"
MOCK_BLOCKED_RUN_ID="run-mock-blocked-$UUID"
BAD_TIER_REQUEST_ID="req-bad-tier-$UUID"
CONTROL_ACTION_ID="act-run-real-$UUID"
CONTROL_MOCK_ACTION_ID="act-run-mock-$UUID"
CONTROL_GONDOLIN_MOCK_ACTION_ID="act-run-mock-gondolin-$UUID"
CONTROL_BAD_SCRIPT_ID="act-bad-script-$UUID"
CONTROL_UNKNOWN_TOOL_ID="act-unknown-tool-$UUID"
CONTROL_TOOL_MISMATCH_ID="act-tool-mismatch-$UUID"
CONTROL_RUN_ID="run-run-real-$UUID"
CONTROL_MOCK_RUN_ID="run-run-mock-$UUID"
CONTROL_GONDOLIN_MOCK_RUN_ID="run-run-mock-gondolin-$UUID"
CONTROL_TAMPER_ID="act-tamper-$UUID"
RELEASE_ACTION_ID="act-release-$UUID"
RELEASE_BAD_INPUT_ID="act-release-bad-input-$UUID"
RELEASE_OUTPUT="$SANDBOX/shared/results/$REQUEST_ID/output.txt"

rm -rf "$SANDBOX"
mkdir -p "$SANDBOX/shared/workspace"

cargo run --quiet --bin rho -- dataset \
  --name "$DATASET_NAME" \
  --real prototype/tests/scenarios/two-console-demo/assets/datasets/prices-real.csv \
  --mock prototype/tests/scenarios/two-console-demo/assets/datasets/prices-mock.csv \
  --owner "$OWNER" \
  --share-dir "$SANDBOX/users/$OWNER/datasets/share" \
  --private-dir "$SANDBOX/users/$OWNER/datasets/private" \
  --uuid "$UUID" \
  --description "Rust e2e smoke test"

cargo run --quiet --bin rho -- publish \
  "$OWNER" "$UUID" \
  --source-root "$SANDBOX/users" \
  --target-root "$SANDBOX/shared/datasets"

cargo run --quiet --bin rho -- tools install-minimal \
  --shared-root "$SANDBOX/shared" \
  --owner "$OWNER"
test "$(cargo run --quiet --bin rho -- tools list --shared-root "$SANDBOX/shared" | tr '\n' ' ')" = "publish_results run_mock run_real "

cp prototype/tests/scenarios/two-console-demo/assets/workspace/sum_prices.py "$SANDBOX/shared/workspace/sum_prices.py"
CODE_SHA256="$(shasum -a 256 "$SANDBOX/shared/workspace/sum_prices.py" | awk '{print $1}')"
MOCK_OUT="$(python3 "$SANDBOX/shared/workspace/sum_prices.py" "$SANDBOX/shared/datasets/$DATASET_NAME/mock/prices-mock.csv")"
test "$MOCK_OUT" = "555.00"

cargo run --quiet --bin rho -- request create-run \
  --shared-root "$SANDBOX/shared" \
  --id "$REQUEST_ID" \
  --from "$PEER" \
  --to "$OWNER" \
  --tool-id run_real \
  --dataset-uuid "$UUID" \
  --code-path "$SANDBOX/shared/workspace/sum_prices.py" \
  --command "python3 sum_prices.py DATASET_CSV" \
  --tier real

cargo run --quiet --bin rho -- request create-run \
  --shared-root "$SANDBOX/shared" \
  --id "$MOCK_REQUEST_ID" \
  --from "$PEER" \
  --to "$OWNER" \
  --tool-id run_mock \
  --dataset-uuid "$UUID" \
  --code-path "$SANDBOX/shared/workspace/sum_prices.py" \
  --command "python3 sum_prices.py DATASET_CSV" \
  --tier mock

if cargo run --quiet --bin rho -- request create-run \
  --shared-root "$SANDBOX/shared" \
  --id "$BAD_TIER_REQUEST_ID" \
  --from "$PEER" \
  --to "$OWNER" \
  --tool-id run_real \
  --dataset-uuid "$UUID" \
  --code-path "$SANDBOX/shared/workspace/sum_prices.py" \
  --command "python3 sum_prices.py DATASET_CSV" \
  --tier secret; then
  echo "bad tier request unexpectedly succeeded" >&2
  exit 1
fi

cargo run --quiet --bin rho -- message send \
  --shared-root "$SANDBOX/shared" \
  --from "$PEER" \
  --to "$OWNER" \
  --type request_run_real \
  --related-request-id "$REQUEST_ID" \
  --id "msg-$UUID" \
  --text "Please review and run $REQUEST_ID on the real dataset."

test "$(cargo run --quiet --bin rho -- request status "$REQUEST_ID" --shared-root "$SANDBOX/shared")" = "pending"

if cargo run --quiet --bin rho -- run request \
  --shared-root "$SANDBOX/shared" \
  --request-id "$REQUEST_ID" \
  --run-id "$BLOCKED_RUN_ID" \
  --private-root "$SANDBOX/users/$OWNER/datasets/private" \
  --tier real; then
  echo "real run unexpectedly succeeded before approval" >&2
  exit 1
fi
grep -q "blocked" "$SANDBOX/shared/.rho/runs/$BLOCKED_RUN_ID.yaml"
grep -q "requires approved request" "$SANDBOX/shared/.rho/runs/$BLOCKED_RUN_ID.yaml"

if cargo run --quiet --bin rho -- run request \
  --shared-root "$SANDBOX/shared" \
  --request-id "$MOCK_REQUEST_ID" \
  --run-id "$MOCK_BLOCKED_RUN_ID" \
  --private-root "$SANDBOX/users/$OWNER/datasets/private" \
  --tier mock; then
  echo "mock run unexpectedly succeeded before approval" >&2
  exit 1
fi
grep -q "blocked" "$SANDBOX/shared/.rho/runs/$MOCK_BLOCKED_RUN_ID.yaml"
grep -q "requires approved request" "$SANDBOX/shared/.rho/runs/$MOCK_BLOCKED_RUN_ID.yaml"

test "$(cargo run --quiet --bin rho -- request status "$REQUEST_ID" --shared-root "$SANDBOX/shared")" = "pending"
test "$(cargo run --quiet --bin rho -- request status "$MOCK_REQUEST_ID" --shared-root "$SANDBOX/shared")" = "pending"

mkdir -p "$SANDBOX/users/$OWNER/local"
cp "$SANDBOX/shared/workspace/sum_prices.py" "$SANDBOX/users/$OWNER/local/outside_shared.py"

export RHO_SANDBOX_RUNNER=fake
mkdir -p "$SANDBOX/control/outbox" "$SANDBOX/control/inbox"
cat > "$SANDBOX/control/outbox/$CONTROL_MOCK_ACTION_ID.json" <<EOF
{
  "version": 1,
  "kind": "controlled_action",
  "action": {
    "action_id": "$CONTROL_MOCK_ACTION_ID",
    "request_id": "$MOCK_REQUEST_ID",
    "tool_id": "run_mock",
    "requested_by": "$PEER",
    "requested_for": "$OWNER",
    "action_type": "run_mock_data",
    "summary": "Run the submitted sum_prices script on mock data.",
    "reason": "Check behavior before requesting real data.",
    "script_path": "$SANDBOX/shared/workspace/sum_prices.py",
    "output_path": "$SANDBOX/shared/.rho/runs/$CONTROL_MOCK_RUN_ID/stdout.txt"
  }
}
EOF
cargo run --quiet --bin rho -- run grant-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$CONTROL_MOCK_ACTION_ID" \
  --granted-by "$OWNER" \
  --input "code:$SANDBOX/shared/workspace/sum_prices.py"
CONTROL_MOCK_STATUS_PATH="$(cargo run --quiet --bin rho -- run controlled-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$CONTROL_MOCK_ACTION_ID" \
  --private-root "$SANDBOX/users/$OWNER/datasets/private")"
grep -q "completed" "$CONTROL_MOCK_STATUS_PATH"
grep -q "completed" "$SANDBOX/shared/.rho/runs/$CONTROL_MOCK_RUN_ID.yaml"
grep -q "runner: fake" "$SANDBOX/shared/.rho/runs/$CONTROL_MOCK_RUN_ID.yaml"
grep -q "runner: fake" "$SANDBOX/shared/.rho/runs/$CONTROL_MOCK_RUN_ID/sandbox-run.yaml"
grep -q "tier: mock" "$SANDBOX/shared/.rho/runs/$CONTROL_MOCK_RUN_ID.yaml"
test "$(cat "$SANDBOX/shared/.rho/runs/$CONTROL_MOCK_RUN_ID/stdout.txt")" = "555.00"
test "$(cargo run --quiet --bin rho -- request status "$MOCK_REQUEST_ID" --shared-root "$SANDBOX/shared")" = "pending"

cat > "$SANDBOX/fake-gondolin.sh" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
eval "$RHO_GONDOLIN_HOST_COMMAND" > "$RHO_GONDOLIN_STDOUT_PATH" 2> "$RHO_GONDOLIN_STDERR_PATH"
EOF
chmod +x "$SANDBOX/fake-gondolin.sh"
cat > "$SANDBOX/control/outbox/$CONTROL_GONDOLIN_MOCK_ACTION_ID.json" <<EOF
{
  "version": 1,
  "kind": "controlled_action",
  "action": {
    "action_id": "$CONTROL_GONDOLIN_MOCK_ACTION_ID",
    "request_id": "$MOCK_REQUEST_ID",
    "tool_id": "run_mock",
    "requested_by": "$PEER",
    "requested_for": "$OWNER",
    "action_type": "run_mock_data",
    "summary": "Run the submitted sum_prices script through the Gondolin runner adapter.",
    "reason": "Verify the runner adapter writes a Gondolin plan.",
    "script_path": "$SANDBOX/shared/workspace/sum_prices.py",
    "output_path": "$SANDBOX/shared/.rho/runs/$CONTROL_GONDOLIN_MOCK_RUN_ID/stdout.txt"
  }
}
EOF
cargo run --quiet --bin rho -- run grant-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$CONTROL_GONDOLIN_MOCK_ACTION_ID" \
  --granted-by "$OWNER" \
  --input "code:$SANDBOX/shared/workspace/sum_prices.py"
CONTROL_GONDOLIN_MOCK_STATUS_PATH="$(RHO_SANDBOX_RUNNER=gondolin RHO_GONDOLIN_RUNNER_CMD="$SANDBOX/fake-gondolin.sh" cargo run --quiet --bin rho -- run controlled-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$CONTROL_GONDOLIN_MOCK_ACTION_ID" \
  --private-root "$SANDBOX/users/$OWNER/datasets/private")"
grep -q "completed" "$CONTROL_GONDOLIN_MOCK_STATUS_PATH"
grep -q "runner: gondolin" "$SANDBOX/shared/.rho/runs/$CONTROL_GONDOLIN_MOCK_RUN_ID.yaml"
grep -q "runner: gondolin" "$SANDBOX/shared/.rho/runs/$CONTROL_GONDOLIN_MOCK_RUN_ID/sandbox-run.yaml"
grep -q "guest: /input" "$SANDBOX/shared/.rho/runs/$CONTROL_GONDOLIN_MOCK_RUN_ID/gondolin-run.yaml"
grep -q "/output/stdout.txt" "$SANDBOX/shared/.rho/runs/$CONTROL_GONDOLIN_MOCK_RUN_ID/gondolin-run.yaml"
test "$(cat "$SANDBOX/shared/.rho/runs/$CONTROL_GONDOLIN_MOCK_RUN_ID/stdout.txt")" = "555.00"

if [[ "${RUN_REAL_GONDOLIN:-0}" == "1" ]]; then
  REAL_GONDOLIN_STATUS_PATH="$(RHO_SANDBOX_RUNNER=gondolin cargo run --quiet --bin rho -- run controlled-action \
    --shared-root "$SANDBOX/shared" \
    --control-root "$SANDBOX/control" \
    --action-id "$CONTROL_GONDOLIN_MOCK_ACTION_ID" \
    --private-root "$SANDBOX/users/$OWNER/datasets/private")"
  grep -q "completed" "$REAL_GONDOLIN_STATUS_PATH"
  test "$(cat "$SANDBOX/shared/.rho/runs/$CONTROL_GONDOLIN_MOCK_RUN_ID/stdout.txt")" = "555.00"
fi

cat > "$SANDBOX/control/outbox/$CONTROL_UNKNOWN_TOOL_ID.json" <<EOF
{
  "version": 1,
  "kind": "controlled_action",
  "action": {
    "action_id": "$CONTROL_UNKNOWN_TOOL_ID",
    "request_id": "$REQUEST_ID",
    "tool_id": "missing_tool",
    "requested_by": "$PEER",
    "requested_for": "$OWNER",
    "action_type": "run_real_data",
    "summary": "Attempt to use an unknown host tool.",
    "reason": "Negative e2e case.",
    "script_path": "$SANDBOX/shared/workspace/sum_prices.py",
    "output_path": "$SANDBOX/shared/.rho/runs/$CONTROL_RUN_ID/stdout.txt"
  }
}
EOF
if cargo run --quiet --bin rho -- run grant-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$CONTROL_UNKNOWN_TOOL_ID" \
  --granted-by "$OWNER" \
  --input "code:$SANDBOX/shared/workspace/sum_prices.py"; then
  echo "unknown tool action grant unexpectedly succeeded" >&2
  exit 1
fi
if cargo run --quiet --bin rho -- run controlled-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$CONTROL_UNKNOWN_TOOL_ID" \
  --private-root "$SANDBOX/users/$OWNER/datasets/private"; then
  echo "unknown tool controlled action unexpectedly succeeded" >&2
  exit 1
fi
grep -q "action grant not found" "$SANDBOX/control/inbox/$CONTROL_UNKNOWN_TOOL_ID.status.json"

cat > "$SANDBOX/control/outbox/$CONTROL_TOOL_MISMATCH_ID.json" <<EOF
{
  "version": 1,
  "kind": "controlled_action",
  "action": {
    "action_id": "$CONTROL_TOOL_MISMATCH_ID",
    "request_id": "$REQUEST_ID",
    "tool_id": "run_mock",
    "requested_by": "$PEER",
    "requested_for": "$OWNER",
    "action_type": "run_real_data",
    "summary": "Attempt to use run_mock for a real-data action.",
    "reason": "Negative e2e case.",
    "script_path": "$SANDBOX/shared/workspace/sum_prices.py",
    "output_path": "$SANDBOX/shared/.rho/runs/$CONTROL_RUN_ID/stdout.txt"
  }
}
EOF
cargo run --quiet --bin rho -- run grant-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$CONTROL_TOOL_MISMATCH_ID" \
  --granted-by "$OWNER" \
  --input "code:$SANDBOX/shared/workspace/sum_prices.py"
if cargo run --quiet --bin rho -- run controlled-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$CONTROL_TOOL_MISMATCH_ID" \
  --private-root "$SANDBOX/users/$OWNER/datasets/private"; then
  echo "tool mismatch controlled action unexpectedly succeeded" >&2
  exit 1
fi
grep -q "has action_type" "$SANDBOX/control/inbox/$CONTROL_TOOL_MISMATCH_ID.status.json"

cat > "$SANDBOX/control/outbox/$CONTROL_BAD_SCRIPT_ID.json" <<EOF
{
  "version": 1,
  "kind": "controlled_action",
  "action": {
    "action_id": "$CONTROL_BAD_SCRIPT_ID",
    "request_id": "$REQUEST_ID",
    "tool_id": "run_real",
    "requested_by": "$PEER",
    "requested_for": "$OWNER",
    "action_type": "run_real_data",
    "summary": "Attempt to run from an unapproved script path.",
    "reason": "Negative e2e case.",
    "script_path": "$SANDBOX/users/$OWNER/local/outside_shared.py",
    "output_path": "$SANDBOX/shared/.rho/runs/$CONTROL_RUN_ID/stdout.txt"
  }
}
EOF
cargo run --quiet --bin rho -- run grant-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$CONTROL_BAD_SCRIPT_ID" \
  --granted-by "$OWNER" \
  --input "code:$SANDBOX/users/$OWNER/local/outside_shared.py"
if cargo run --quiet --bin rho -- run controlled-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$CONTROL_BAD_SCRIPT_ID" \
  --private-root "$SANDBOX/users/$OWNER/datasets/private"; then
  echo "bad controlled action unexpectedly succeeded" >&2
  exit 1
fi
grep -q "failed" "$SANDBOX/control/inbox/$CONTROL_BAD_SCRIPT_ID.status.json"
grep -q "script path must be under" "$SANDBOX/control/inbox/$CONTROL_BAD_SCRIPT_ID.status.json"

cat > "$SANDBOX/control/outbox/$CONTROL_TAMPER_ID.json" <<EOF
{
  "version": 1,
  "kind": "controlled_action",
  "action": {
    "action_id": "$CONTROL_TAMPER_ID",
    "request_id": "$REQUEST_ID",
    "tool_id": "run_real",
    "requested_by": "$PEER",
    "requested_for": "$OWNER",
    "action_type": "run_real_data",
    "summary": "Attempt to run after code tampering.",
    "reason": "Negative e2e case.",
    "script_path": "$SANDBOX/shared/workspace/sum_prices.py",
    "output_path": "$SANDBOX/shared/.rho/runs/$CONTROL_RUN_ID/stdout.txt"
  }
}
EOF
cargo run --quiet --bin rho -- run grant-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$CONTROL_TAMPER_ID" \
  --granted-by "$OWNER" \
  --input "code:$SANDBOX/shared/workspace/sum_prices.py"
cp "$SANDBOX/shared/workspace/sum_prices.py" "$SANDBOX/shared/workspace/sum_prices.py.clean"
printf '\nprint("tampered")\n' >> "$SANDBOX/shared/workspace/sum_prices.py"
if cargo run --quiet --bin rho -- run controlled-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$CONTROL_TAMPER_ID" \
  --private-root "$SANDBOX/users/$OWNER/datasets/private"; then
  echo "tampered controlled action unexpectedly succeeded" >&2
  exit 1
fi
grep -q "input digest mismatch" "$SANDBOX/control/inbox/$CONTROL_TAMPER_ID.status.json"
mv "$SANDBOX/shared/workspace/sum_prices.py.clean" "$SANDBOX/shared/workspace/sum_prices.py"
test "$(shasum -a 256 "$SANDBOX/shared/workspace/sum_prices.py" | awk '{print $1}')" = "$CODE_SHA256"

cat > "$SANDBOX/control/outbox/$CONTROL_ACTION_ID.json" <<EOF
{
  "version": 1,
  "kind": "controlled_action",
  "action": {
    "action_id": "$CONTROL_ACTION_ID",
    "request_id": "$REQUEST_ID",
    "tool_id": "run_real",
    "requested_by": "$PEER",
    "requested_for": "$OWNER",
    "action_type": "run_real_data",
    "summary": "Run the granted sum_prices script on real data.",
    "reason": "Produce the aggregate requested by the peer.",
    "script_path": "$SANDBOX/shared/workspace/sum_prices.py",
    "output_path": "$SANDBOX/shared/.rho/runs/$CONTROL_RUN_ID/stdout.txt"
  }
}
EOF
cargo run --quiet --bin rho -- run grant-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$CONTROL_ACTION_ID" \
  --granted-by "$OWNER" \
  --input "code:$SANDBOX/shared/workspace/sum_prices.py"
CONTROL_STATUS_PATH="$(cargo run --quiet --bin rho -- run controlled-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$CONTROL_ACTION_ID" \
  --private-root "$SANDBOX/users/$OWNER/datasets/private")"
grep -q "completed" "$CONTROL_STATUS_PATH"
grep -q "completed" "$SANDBOX/shared/.rho/runs/$CONTROL_RUN_ID.yaml"
grep -q "runner: fake" "$SANDBOX/shared/.rho/runs/$CONTROL_RUN_ID.yaml"
grep -q "runner: fake" "$SANDBOX/shared/.rho/runs/$CONTROL_RUN_ID/sandbox-run.yaml"
test "$(cat "$SANDBOX/shared/.rho/runs/$CONTROL_RUN_ID/stdout.txt")" = "1113.03"
test "$(cargo run --quiet --bin rho -- request status "$REQUEST_ID" --shared-root "$SANDBOX/shared")" = "pending"

mkdir -p "$SANDBOX/shared/results/$REQUEST_ID"
cat > "$SANDBOX/control/outbox/$RELEASE_BAD_INPUT_ID.json" <<EOF
{
  "version": 1,
  "kind": "controlled_action",
  "action": {
    "action_id": "$RELEASE_BAD_INPUT_ID",
    "request_id": "$REQUEST_ID",
    "tool_id": "publish_results",
    "requested_by": "$PEER",
    "requested_for": "$OWNER",
    "action_type": "release_results",
    "summary": "Attempt to release a non-run artifact.",
    "reason": "Negative e2e case.",
    "input_path": "$SANDBOX/shared/workspace/sum_prices.py",
    "output_path": "$RELEASE_OUTPUT"
  }
}
EOF
cargo run --quiet --bin rho -- run grant-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$RELEASE_BAD_INPUT_ID" \
  --granted-by "$OWNER" \
  --input "artifact:$SANDBOX/shared/workspace/sum_prices.py"
if cargo run --quiet --bin rho -- run controlled-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$RELEASE_BAD_INPUT_ID" \
  --private-root "$SANDBOX/users/$OWNER/datasets/private"; then
  echo "bad release controlled action unexpectedly succeeded" >&2
  exit 1
fi
grep -q "release input path must be under" "$SANDBOX/control/inbox/$RELEASE_BAD_INPUT_ID.status.json"

cat > "$SANDBOX/control/outbox/$RELEASE_ACTION_ID.json" <<EOF
{
  "version": 1,
  "kind": "controlled_action",
  "action": {
    "action_id": "$RELEASE_ACTION_ID",
    "request_id": "$REQUEST_ID",
    "tool_id": "publish_results",
    "requested_by": "$PEER",
    "requested_for": "$OWNER",
    "action_type": "release_results",
    "summary": "Release the granted aggregate result.",
    "reason": "Make the granted output visible to the requester.",
    "input_path": "$SANDBOX/shared/.rho/runs/$CONTROL_RUN_ID/stdout.txt",
    "output_path": "$RELEASE_OUTPUT"
  }
}
EOF
cargo run --quiet --bin rho -- run grant-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$RELEASE_ACTION_ID" \
  --granted-by "$OWNER" \
  --input "artifact:$SANDBOX/shared/.rho/runs/$CONTROL_RUN_ID/stdout.txt"
RELEASE_STATUS_PATH="$(cargo run --quiet --bin rho -- run controlled-action \
  --shared-root "$SANDBOX/shared" \
  --control-root "$SANDBOX/control" \
  --action-id "$RELEASE_ACTION_ID" \
  --private-root "$SANDBOX/users/$OWNER/datasets/private")"
grep -q "completed" "$RELEASE_STATUS_PATH"

grep -q "released" "$SANDBOX/shared/.rho/results/$REQUEST_ID.yaml"
grep -q "1113.03" "$RELEASE_OUTPUT"
echo "inspect sandbox: $SANDBOX"
find "$SANDBOX/shared/.rho" -maxdepth 3 -type f | sort
find "$SANDBOX/control" -maxdepth 3 -type f | sort
echo "two-console smoke passed"
