#!/usr/bin/env bash
cd /c/Users/decid/Documents/projects/spt-core/.worktrees/gate-ns23-w1 || exit 1
reap() {
  n=0
  for p in $(powershell -NoProfile -Command "Get-CimInstance Win32_Process -Filter \"Name='spt.exe'\" | Where-Object {\$_.ExecutablePath -like '*gate-ns23-w1*'} | Select-Object -ExpandProperty ProcessId" 2>/dev/null); do
    powershell -NoProfile -Command "Stop-Process -Id $p -Force" 2>/dev/null; n=$((n+1))
  done
  echo "reap-by-path count=$n"
}
reap
S="env -u OWL_SESSION_ID -u SPT_AGENT_ID -u SPT_ENDPOINT_ID -u SPT_HOME"
$S cargo build --workspace --bins > W_prebuild.raw 2>&1; echo $? > W_prebuild.exit
$S cargo clippy --workspace --all-targets -- -D warnings > W_clippy.raw 2>&1; echo $? > W_clippy.exit
$S traceable-reqs check > W_treqs.raw 2>&1; echo $? > W_treqs.exit
$S cargo run -p xtask -- check > W_xtask.raw 2>&1; echo $? > W_xtask.exit
$S cargo nextest run -p spt-daemon > W_daemon.raw 2>&1; echo $? > W_daemon.exit
$S cargo nextest run -p spt --test attach_link_push_e2e > W_e2e.raw 2>&1; echo $? > W_e2e.exit
reap
echo DRIVER_COMPLETE
