-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnative-runners.js
More file actions
334 lines (318 loc) · 10.9 KB
/
native-runners.js
File metadata and controls
334 lines (318 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
"use strict";
const { execFile, spawn } = require("child_process");
const path = require("path");
const { detectNativeBridges } = require("./native-bridges");
const ACK = "START_NATIVE_STRESS";
const MAX_DURATION_SEC = 900;
const PROFILE_DEFINITIONS = [
{
id: "prime95-small-fft",
toolId: "prime95",
label: "Prime95 / mprime Small FFT",
target: "cpu",
risk: "high",
durationDefaultSec: 180,
durationMaxSec: 600,
args: () => ["-t"],
safety: {
maxDurationSec: 600,
recommendedMonitor: "Watch CPU package temperature and VRM temperature. Stop above your platform limit.",
stopBehavior: "RigScope terminates the process tree at the duration cap or when Stop Native is pressed."
},
notes: "Starts Prime95 torture mode. Prime95 chooses the exact torture preset from its local configuration, so treat it as a high-heat CPU test."
},
{
id: "prime95-blend",
toolId: "prime95",
label: "Prime95 / mprime Blend",
target: "cpu-memory",
risk: "high",
durationDefaultSec: 300,
durationMaxSec: 900,
args: () => ["-t"],
safety: {
maxDurationSec: 900,
recommendedMonitor: "Watch CPU temperature, memory temperature where available, and system responsiveness.",
stopBehavior: "RigScope terminates the process tree at the duration cap or when Stop Native is pressed."
},
notes: "Launches Prime95/mprime torture mode for a longer CPU/RAM stability pass. Configure blend mode inside Prime95 if prompted."
},
{
id: "furmark-smoke",
toolId: "furmark",
label: "FurMark GPU Smoke 720p",
target: "gpu",
risk: "high",
durationDefaultSec: 120,
durationMaxSec: 300,
args: (tool, durationSec) => {
const exe = path.basename(tool.executable?.path || "").toLowerCase();
if (process.platform === "win32") {
return exe.includes("furmark2")
? ["--demo", "--fullscreen=0"]
: ["/nogui", "/width=1280", "/height=720", `/max_time=${durationSec * 1000}`];
}
return [];
},
safety: {
maxDurationSec: 300,
recommendedMonitor: "Watch GPU hotspot, memory junction where available, fan speed, and power draw.",
stopBehavior: "RigScope terminates the process tree at the duration cap or when Stop Native is pressed."
},
notes: "Launches FurMark with a conservative 720p windowed smoke profile when supported by the installed build."
},
{
id: "furmark-burn-in-1080p",
toolId: "furmark",
label: "FurMark Burn-in 1080p",
target: "gpu",
risk: "extreme",
durationDefaultSec: 180,
durationMaxSec: 600,
args: (tool, durationSec) => {
const exe = path.basename(tool.executable?.path || "").toLowerCase();
if (process.platform === "win32") {
return exe.includes("furmark2")
? ["--demo", "--fullscreen=0"]
: ["/nogui", "/width=1920", "/height=1080", `/max_time=${durationSec * 1000}`];
}
return [];
},
safety: {
maxDurationSec: 600,
recommendedMonitor: "Use only with active temperature monitoring. Stop immediately on artifacts, throttling, or unstable power.",
stopBehavior: "RigScope terminates the process tree at the duration cap or when Stop Native is pressed."
},
notes: "High-load FurMark profile intended for short validation runs, not unattended overnight testing."
},
{
id: "occt-manual",
toolId: "occt",
label: "OCCT Manual Stability Session",
target: "stability-suite",
risk: "high",
durationDefaultSec: 300,
durationMaxSec: 900,
args: () => [],
safety: {
maxDurationSec: 900,
recommendedMonitor: "Use OCCT's own telemetry and stop on errors, thermal throttling, or PSU instability.",
stopBehavior: "RigScope tracks and terminates the launched OCCT process when requested."
},
notes: "OCCT CLI differs by release, so RigScope launches OCCT and tracks the process; choose CPU, memory, GPU, or PSU inside OCCT."
},
{
id: "occt-psu-manual",
toolId: "occt",
label: "OCCT PSU Manual Session",
target: "psu-system",
risk: "extreme",
durationDefaultSec: 120,
durationMaxSec: 300,
args: () => [],
safety: {
maxDurationSec: 300,
recommendedMonitor: "PSU tests can load CPU and GPU together. Do not run unattended.",
stopBehavior: "RigScope tracks and terminates the launched OCCT process when requested."
},
notes: "Opens OCCT for a short manual PSU validation session. The exact test must be started inside OCCT."
},
{
id: "y-cruncher-manual",
toolId: "y-cruncher",
label: "y-cruncher Manual Session",
target: "cpu-memory",
risk: "high",
durationDefaultSec: 300,
durationMaxSec: 900,
args: () => [],
safety: {
maxDurationSec: 900,
recommendedMonitor: "Watch CPU temperature and memory stability. y-cruncher can expose marginal RAM/IMC instability quickly.",
stopBehavior: "RigScope tracks and terminates the launched y-cruncher process when requested."
},
notes: "Launches y-cruncher for manual stress/benchmark selection and tracks the process."
}
];
const nativeRunner = {
active: false,
id: null,
profileId: null,
toolId: null,
label: null,
pid: null,
startedAt: 0,
durationMs: 0,
timer: null,
child: null,
exitCode: null,
signal: null,
output: [],
report: null
};
function getProfiles() {
const bridges = detectNativeBridges();
const tools = Object.fromEntries(bridges.tools.map((tool) => [tool.id, tool]));
return PROFILE_DEFINITIONS.map((profile) => {
const tool = tools[profile.toolId];
return {
id: profile.id,
toolId: profile.toolId,
label: profile.label,
target: profile.target,
risk: profile.risk,
available: Boolean(tool?.available),
supported: Boolean(tool?.supported),
executable: tool?.executable?.path || null,
durationDefaultSec: profile.durationDefaultSec,
durationMaxSec: profile.durationMaxSec,
acknowledgement: ACK,
safety: profile.safety,
notes: profile.notes
};
});
}
function getStatus(reason = "status") {
const elapsedMs = nativeRunner.startedAt ? Date.now() - nativeRunner.startedAt : 0;
return {
active: nativeRunner.active,
reason,
id: nativeRunner.id,
profileId: nativeRunner.profileId,
toolId: nativeRunner.toolId,
label: nativeRunner.label,
pid: nativeRunner.pid,
startedAt: nativeRunner.startedAt ? new Date(nativeRunner.startedAt).toISOString() : null,
elapsedMs,
durationMs: nativeRunner.durationMs,
exitCode: nativeRunner.exitCode,
signal: nativeRunner.signal,
output: nativeRunner.output.slice(-12),
report: nativeRunner.report
};
}
function buildReport(reason = "status") {
const elapsedMs = nativeRunner.startedAt ? Date.now() - nativeRunner.startedAt : 0;
const completedRatio = nativeRunner.durationMs ? Math.min(1, elapsedMs / nativeRunner.durationMs) : 0;
return {
generatedAt: new Date().toISOString(),
reason,
id: nativeRunner.id,
profileId: nativeRunner.profileId,
label: nativeRunner.label,
target: nativeRunner.target,
risk: nativeRunner.risk,
pid: nativeRunner.pid,
elapsedMs,
durationMs: nativeRunner.durationMs,
completedRatio: Math.round(completedRatio * 100) / 100,
exitCode: nativeRunner.exitCode,
signal: nativeRunner.signal,
verdict: nativeRunner.exitCode === 0 ? "completed" : nativeRunner.signal ? "stopped" : reason,
outputTail: nativeRunner.output.slice(-20),
safety: nativeRunner.safety
};
}
function isChildAlive(child) {
if (!child || !child.pid || child.exitCode !== null || child.signalCode !== null) return false;
try {
process.kill(child.pid, 0);
return true;
} catch {
return false;
}
}
function startProfile(options = {}) {
if (options.acknowledgement !== ACK) {
throw new Error(`Native stress launch requires acknowledgement "${ACK}".`);
}
if (nativeRunner.active && !isChildAlive(nativeRunner.child)) {
nativeRunner.active = false;
nativeRunner.child = null;
}
if (nativeRunner.active) {
throw new Error(`Native runner is already active: ${nativeRunner.profileId}.`);
}
const profile = PROFILE_DEFINITIONS.find((item) => item.id === options.profileId);
if (!profile) throw new Error("Unknown native runner profile.");
const bridges = detectNativeBridges();
const tool = bridges.tools.find((item) => item.id === profile.toolId);
if (!tool?.available || !tool.executable?.path) {
throw new Error(`${profile.label} is not available on this machine.`);
}
const requested = Number(options.durationSec) || profile.durationDefaultSec;
const durationSec = Math.max(10, Math.min(requested, profile.durationMaxSec, MAX_DURATION_SEC));
const args = profile.args(tool, durationSec);
const child = spawn(tool.executable.path, args, {
cwd: path.dirname(tool.executable.path),
windowsHide: false,
stdio: ["ignore", "pipe", "pipe"]
});
Object.assign(nativeRunner, {
active: true,
id: `${profile.id}-${Date.now()}`,
profileId: profile.id,
toolId: profile.toolId,
label: profile.label,
target: profile.target,
risk: profile.risk,
safety: profile.safety,
pid: child.pid,
startedAt: Date.now(),
durationMs: durationSec * 1000,
child,
exitCode: null,
signal: null,
output: [],
report: null
});
const capture = (source, chunk) => {
String(chunk).split(/\r?\n/).filter(Boolean).forEach((line) => {
nativeRunner.output.push(`${source}: ${line.slice(0, 500)}`);
nativeRunner.output = nativeRunner.output.slice(-40);
});
};
child.stdout?.on("data", (chunk) => capture("stdout", chunk));
child.stderr?.on("data", (chunk) => capture("stderr", chunk));
child.on("exit", (code, signal) => {
nativeRunner.active = false;
nativeRunner.exitCode = code;
nativeRunner.signal = signal;
nativeRunner.report = buildReport(signal ? "stopped" : "exited");
nativeRunner.child = null;
clearTimeout(nativeRunner.timer);
});
nativeRunner.timer = setTimeout(() => stopProfile("duration limit"), nativeRunner.durationMs);
nativeRunner.timer.unref();
return getStatus("started");
}
function stopProfile(reason = "stopped") {
const child = nativeRunner.child;
clearTimeout(nativeRunner.timer);
if (!nativeRunner.active || !child) {
nativeRunner.active = false;
nativeRunner.child = null;
nativeRunner.report = buildReport(reason);
return getStatus(reason);
}
nativeRunner.active = false;
nativeRunner.report = buildReport(reason);
if (process.platform === "win32" && child.pid) {
execFile("taskkill.exe", ["/PID", String(child.pid), "/T", "/F"], { windowsHide: true }, () => {});
} else {
try { child.kill("SIGTERM"); } catch {}
setTimeout(() => {
if (!child.killed) {
try { child.kill("SIGKILL"); } catch {}
}
}, 1200).unref();
}
return getStatus(reason);
}
module.exports = {
ACK,
getProfiles,
getStatus,
startProfile,
stopProfile
};