Files
mcp-use__mcp-use/.github/scripts/dev-server-smoke-windows.ps1
2026-09-02 14:28:52 -07:00

60 lines
2.3 KiB
PowerShell

$ErrorActionPreference = 'Stop'
# Own the job before launching any app process. The handle is non-inheritable;
# killing this supervisor closes it and terminates all descendants, even if an
# intermediate npm/cmd process has already exited. Never enumerate by port/name.
Add-Type -TypeDefinition @'
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
public static class SmokeJob {
[StructLayout(LayoutKind.Sequential)]
struct BasicLimits {
public long ProcessTime, JobTime;
public uint Flags;
public UIntPtr MinimumWorkingSet, MaximumWorkingSet;
public uint ActiveProcessLimit;
public UIntPtr Affinity;
public uint PriorityClass, SchedulingClass;
}
[StructLayout(LayoutKind.Sequential)]
struct IoCounters {
public ulong ReadOps, WriteOps, OtherOps, ReadBytes, WriteBytes, OtherBytes;
}
[StructLayout(LayoutKind.Sequential)]
struct ExtendedLimits {
public BasicLimits Basic;
public IoCounters Io;
public UIntPtr ProcessMemory, JobMemory, PeakProcessMemory, PeakJobMemory;
}
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
static extern IntPtr CreateJobObject(IntPtr attributes, string name);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool SetInformationJobObject(IntPtr job, int infoClass,
ref ExtendedLimits limits, uint length);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
[DllImport("kernel32.dll")]
static extern IntPtr GetCurrentProcess();
// Retain the handle for the lifetime of this process.
static IntPtr job;
public static void OwnProcessTree() {
job = CreateJobObject(IntPtr.Zero, null);
if (job == IntPtr.Zero) throw new Win32Exception();
var limits = new ExtendedLimits();
limits.Basic.Flags = 0x2000; // JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
if (!SetInformationJobObject(job, 9, ref limits,
(uint)Marshal.SizeOf(typeof(ExtendedLimits))))
throw new Win32Exception();
if (!AssignProcessToJobObject(job, GetCurrentProcess()))
throw new Win32Exception();
}
}
'@
[SmokeJob]::OwnProcessTree()
& $env:MCP_SMOKE_NODE $env:MCP_SMOKE_SCRIPT --supervise
exit $LASTEXITCODE