@slack/radar-mcp 1.26.0 → 1.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/dist/mcp/api-paths.d.ts +25 -1
- package/dist/mcp/api-paths.js +85 -9
- package/dist/mcp/index.js +23 -4
- package/dist/mcp/snapshot-cli.d.ts +1 -1
- package/dist/mcp/snapshot-cli.js +16 -1
- package/dist/mcp/snapshot.js +46 -24
- package/dist/mcp/test-runs-tools.d.ts +2 -0
- package/dist/mcp/test-runs-tools.js +58 -5
- package/dist/mcp/tools.js +25 -3
- package/dist/shared/android.d.ts +15 -4
- package/dist/shared/android.js +102 -12
- package/dist/shared/constants.d.ts +6 -5
- package/dist/shared/constants.js +6 -5
- package/dist/shared/switchboard-note.js +2 -1
- package/dist/shared/switchboard-report.js +1 -1
- package/dist/shared/test-case-capture.d.ts +15 -0
- package/dist/shared/test-case-capture.js +235 -0
- package/dist/shared/test-case-store.d.ts +54 -0
- package/dist/shared/test-case-store.js +208 -0
- package/dist/shared/transport.d.ts +9 -1
- package/dist/web/install-app.js +1 -1
- package/dist/web/public/index.html +1 -0
- package/dist/web/public/next/app.js +12 -1
- package/dist/web/public/next/feed.js +17 -2
- package/dist/web/public/next/filters.js +5 -5
- package/dist/web/public/next/registry.js +3 -2
- package/dist/web/public/next/save-case.js +92 -0
- package/dist/web/public/next/store.js +3 -1
- package/dist/web/public/next/switchboard-note.js +2 -1
- package/dist/web/public/next/test-cases.js +328 -0
- package/dist/web/public/next/voice.js +1 -1
- package/dist/web/server.d.ts +1 -0
- package/dist/web/server.js +214 -2
- package/dist/web/spec.d.ts +3 -2
- package/dist/web/spec.js +10 -9
- package/package.json +1 -1
- package/dist/mcp/test-cases.d.ts +0 -14
- package/dist/mcp/test-cases.js +0 -77
- /package/dist/web/public/icons/{radar-1024.png → icon-1024.png} +0 -0
- /package/dist/web/public/icons/{radar.svg → icon.svg} +0 -0
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
// The Test cases tab: pick a built-in or saved RTM case, replay it on the device and read the timings.
|
|
2
|
+
// Like DB and Prefs it skips the store, so a tab with no live feed runs no stream engine.
|
|
3
|
+
import { html } from "./html.js";
|
|
4
|
+
import { useState, useEffect, useRef } from "preact/hooks";
|
|
5
|
+
const HEADERS = { "X-Radar-Dashboard": "1" };
|
|
6
|
+
const JSON_HEADERS = { ...HEADERS, "Content-Type": "application/json" };
|
|
7
|
+
let pollMs = 1000;
|
|
8
|
+
// The tool's run id rule: an id from the device ends up in a URL path, so anything else is never followed.
|
|
9
|
+
const isRunId = (id) => typeof id === "string" && /^[A-Za-z0-9_-]{1,64}$/.test(id);
|
|
10
|
+
/** Test hook: the progress poll gap, so a test does not wait a real second. */
|
|
11
|
+
export function _setPollMsForTest(ms) {
|
|
12
|
+
pollMs = ms;
|
|
13
|
+
}
|
|
14
|
+
const typeCounts = (types) => Object.entries((types ?? {})).map(([k, n]) => `${k} ${n}`).join(", ");
|
|
15
|
+
const pct = (v) => v == null
|
|
16
|
+
? html `<td title="fewer than 100 counted events (ok plus failed) so far; raise repeat if the run is done">-</td>`
|
|
17
|
+
: html `<td>${String(v)}</td>`;
|
|
18
|
+
function Summary({ run }) {
|
|
19
|
+
const s = run.summary ?? {};
|
|
20
|
+
const settled = run.settled === true;
|
|
21
|
+
const rows = Object.entries((s.by_type ?? {}));
|
|
22
|
+
return html `
|
|
23
|
+
<div class="dbmeta">
|
|
24
|
+
ok ${s.ok ?? 0}, failed ${s.failed ?? 0}, ignored ${s.ignored ?? 0}${settled ? "" : `, pending ${s.pending ?? 0}`}
|
|
25
|
+
${settled ? null : html ` <b>not settled yet, counts can still change</b>`}
|
|
26
|
+
</div>
|
|
27
|
+
<div class="dbout"><table>
|
|
28
|
+
<thead><tr><th>type</th><th>sent</th><th>ok</th><th>failed</th><th>p50 ms</th><th>p90 ms</th><th>p99 ms</th><th>max ms</th></tr></thead>
|
|
29
|
+
<tbody>${rows.map(([type, t]) => html `<tr>
|
|
30
|
+
<td>${type}</td><td>${t.sent}</td><td>${t.ok}</td><td>${t.failed}</td>${pct(t.p50_ms)}${pct(t.p90_ms)}${pct(t.p99_ms)}<td>${t.max_ms ?? "-"}</td>
|
|
31
|
+
</tr>`)}</tbody>
|
|
32
|
+
</table></div>`;
|
|
33
|
+
}
|
|
34
|
+
export function TestCases() {
|
|
35
|
+
const [cases, setCases] = useState(null);
|
|
36
|
+
const [listError, setListError] = useState("");
|
|
37
|
+
const [picked, setPicked] = useState("");
|
|
38
|
+
const [repeat, setRepeat] = useState("");
|
|
39
|
+
const [rate, setRate] = useState("");
|
|
40
|
+
const [runCount, setRunCount] = useState(null);
|
|
41
|
+
const [tracked, setTracked] = useState("");
|
|
42
|
+
const [elsewhere, setElsewhere] = useState(false);
|
|
43
|
+
// The start handler outlives its render, so it reads what is followed from a ref, not from state.
|
|
44
|
+
const trackedRef = useRef("");
|
|
45
|
+
// The last state read for the followed run: a 404 right after "starting" means the device refused the frames.
|
|
46
|
+
const lastStateRef = useRef(null);
|
|
47
|
+
// The run a "may have started" answer named. It is followed as our own, and its note stays until the device answers for it.
|
|
48
|
+
const unconfirmedRef = useRef("");
|
|
49
|
+
// The case the followed run was started with; a run picked up from the device has none.
|
|
50
|
+
const caseRef = useRef(null);
|
|
51
|
+
// A number field holding text the browser cannot read reports "", which would quietly fall back to the case's rate.
|
|
52
|
+
const repeatRef = useRef(null);
|
|
53
|
+
const rateRef = useRef(null);
|
|
54
|
+
const [run, setRun] = useState(null);
|
|
55
|
+
const [note, setNote] = useState("");
|
|
56
|
+
const [pollNote, setPollNote] = useState("");
|
|
57
|
+
const [busy, setBusy] = useState(false);
|
|
58
|
+
const [copied, setCopied] = useState(false);
|
|
59
|
+
// The saved case a Delete click is asking about, and whether its request is out.
|
|
60
|
+
const [confirming, setConfirming] = useState("");
|
|
61
|
+
const [deleting, setDeleting] = useState(false);
|
|
62
|
+
// State lags a second click in the same frame, so the request guard reads a ref.
|
|
63
|
+
const deletingRef = useRef(false);
|
|
64
|
+
const copiedTimer = useRef(undefined);
|
|
65
|
+
// `startedElsewhere` marks a run read from the device, not from our own start answer.
|
|
66
|
+
const track = (id, snapshot = null, startedElsewhere = false, caseName = null) => {
|
|
67
|
+
if (!isRunId(id))
|
|
68
|
+
return;
|
|
69
|
+
trackedRef.current = id;
|
|
70
|
+
caseRef.current = caseName;
|
|
71
|
+
unconfirmedRef.current = "";
|
|
72
|
+
setTracked(id);
|
|
73
|
+
setElsewhere(startedElsewhere);
|
|
74
|
+
setRun(snapshot);
|
|
75
|
+
lastStateRef.current = snapshot?.state ?? null;
|
|
76
|
+
setPollNote("");
|
|
77
|
+
};
|
|
78
|
+
// Reads the device's run list for the counter. Returns the active run id so mount can resume it.
|
|
79
|
+
const loadRuns = async () => {
|
|
80
|
+
try {
|
|
81
|
+
const body = await (await fetch("/api/test_runs", { headers: HEADERS })).json();
|
|
82
|
+
if (Array.isArray(body.runs))
|
|
83
|
+
setRunCount(body.runs.length);
|
|
84
|
+
return isRunId(body.active_run_id) ? body.active_run_id : "";
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return "";
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
// A sequence number drops an older answer that lands after a newer read, e.g. two quick focus events.
|
|
91
|
+
const listSeqRef = useRef(0);
|
|
92
|
+
const deadRef = useRef(false);
|
|
93
|
+
const loadCases = () => {
|
|
94
|
+
const seq = ++listSeqRef.current;
|
|
95
|
+
const stale = () => deadRef.current || seq !== listSeqRef.current;
|
|
96
|
+
return fetch("/test-cases", { headers: HEADERS }).then((r) => r.json()).then((b) => {
|
|
97
|
+
if (stale())
|
|
98
|
+
return;
|
|
99
|
+
if (Array.isArray(b.cases)) {
|
|
100
|
+
setCases(b.cases);
|
|
101
|
+
// A prompt for a case the list no longer shows as deletable is cancelled, so it cannot come back on a later re-read.
|
|
102
|
+
setConfirming((c) => b.cases.some((x) => x.name === c && x.built_in !== true) ? c : "");
|
|
103
|
+
setListError("");
|
|
104
|
+
}
|
|
105
|
+
else
|
|
106
|
+
setListError(String(b.error ?? "could not list test cases"));
|
|
107
|
+
}).catch(() => { if (!stale())
|
|
108
|
+
setListError("could not list test cases"); });
|
|
109
|
+
};
|
|
110
|
+
// An active run (after a reload, or one started from Claude) is followed so Stop still works, unless one is already followed.
|
|
111
|
+
const pickUpActive = () => loadRuns().then((active) => { if (!deadRef.current && active && !trackedRef.current)
|
|
112
|
+
track(active, null, true); });
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
deadRef.current = false;
|
|
115
|
+
void loadCases();
|
|
116
|
+
// A save made in another window or by Claude shows up when the user comes back to this one.
|
|
117
|
+
const onFocus = () => { void loadCases(); void pickUpActive(); };
|
|
118
|
+
window.addEventListener("focus", onFocus);
|
|
119
|
+
void pickUpActive();
|
|
120
|
+
return () => { deadRef.current = true; window.removeEventListener("focus", onFocus); clearTimeout(copiedTimer.current); };
|
|
121
|
+
}, []);
|
|
122
|
+
// One chained timeout per tracked run; a new id or an unmount cancels it, so no fetch outlives the tab.
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (!tracked)
|
|
125
|
+
return;
|
|
126
|
+
let dead = false;
|
|
127
|
+
let timer;
|
|
128
|
+
const tick = async () => {
|
|
129
|
+
try {
|
|
130
|
+
const res = await fetch(`/api/test_runs/${encodeURIComponent(tracked)}`, { headers: HEADERS });
|
|
131
|
+
const body = await res.json();
|
|
132
|
+
if (dead)
|
|
133
|
+
return;
|
|
134
|
+
if (res.status === 404) {
|
|
135
|
+
const neverStarted = unconfirmedRef.current === tracked;
|
|
136
|
+
unconfirmedRef.current = "";
|
|
137
|
+
if (neverStarted)
|
|
138
|
+
setNote("");
|
|
139
|
+
setPollNote(neverStarted
|
|
140
|
+
? `run ${tracked} did not start. Press Run again`
|
|
141
|
+
: lastStateRef.current === "starting"
|
|
142
|
+
? `the device refused run ${tracked} while checking its frames; Run it again to see the reason`
|
|
143
|
+
: `the device no longer holds run ${tracked}`);
|
|
144
|
+
// Dropping the run hides Stop, which has nothing left to stop.
|
|
145
|
+
trackedRef.current = "";
|
|
146
|
+
setTracked("");
|
|
147
|
+
setRun(null);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (res.status >= 400) {
|
|
151
|
+
setPollNote(String(body.error ?? `HTTP ${res.status}`));
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
setRun(body);
|
|
155
|
+
lastStateRef.current = body.state ?? null;
|
|
156
|
+
setPollNote("");
|
|
157
|
+
if (unconfirmedRef.current === tracked) {
|
|
158
|
+
unconfirmedRef.current = "";
|
|
159
|
+
setNote("");
|
|
160
|
+
}
|
|
161
|
+
if (body.settled === true) {
|
|
162
|
+
setNote("");
|
|
163
|
+
// Nothing is followed any more, so a later start that times out can pick up the device's active run.
|
|
164
|
+
trackedRef.current = "";
|
|
165
|
+
void loadRuns();
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
if (dead)
|
|
172
|
+
return;
|
|
173
|
+
setPollNote("request failed");
|
|
174
|
+
}
|
|
175
|
+
timer = setTimeout(tick, pollMs);
|
|
176
|
+
};
|
|
177
|
+
void tick();
|
|
178
|
+
return () => { dead = true; clearTimeout(timer); };
|
|
179
|
+
}, [tracked]);
|
|
180
|
+
const start = async () => {
|
|
181
|
+
if (busy || !picked)
|
|
182
|
+
return;
|
|
183
|
+
const unreadable = [[repeatRef, "repeat"], [rateRef, "rate"]].find(([r]) => r.current?.validity?.badInput);
|
|
184
|
+
if (unreadable) {
|
|
185
|
+
setNote(`${unreadable[1]} is not a number`);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
setBusy(true);
|
|
189
|
+
setNote("");
|
|
190
|
+
// Only a filled field goes out; the device answers with its own text when a number is out of range.
|
|
191
|
+
const body = { case: picked };
|
|
192
|
+
const num = (v) => (v.trim() !== "" && Number.isFinite(Number(v)) ? Number(v) : null);
|
|
193
|
+
if (num(repeat) !== null)
|
|
194
|
+
body.repeat = num(repeat);
|
|
195
|
+
if (num(rate) !== null)
|
|
196
|
+
body.rate_per_second = num(rate);
|
|
197
|
+
try {
|
|
198
|
+
const res = await fetch("/test-cases/run", { method: "POST", headers: JSON_HEADERS, body: JSON.stringify(body) });
|
|
199
|
+
const answer = await res.json();
|
|
200
|
+
// The route answers 400 for a refused request; a 200 can still carry a failed run's own error, which is run data.
|
|
201
|
+
if (res.status >= 400) {
|
|
202
|
+
setNote(String(answer.error ?? `HTTP ${res.status}`));
|
|
203
|
+
if (answer.reason === "may_have_started" && isRunId(answer.run_id)) {
|
|
204
|
+
track(answer.run_id, null, false, picked);
|
|
205
|
+
unconfirmedRef.current = answer.run_id;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
// Any other refusal carries the id of a run that never started, so only the active one is tracked.
|
|
209
|
+
track(answer.active_run_id, null, true);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
track(answer.run_id, answer, false, picked);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
setNote("request failed");
|
|
218
|
+
}
|
|
219
|
+
finally {
|
|
220
|
+
setBusy(false);
|
|
221
|
+
// A start that timed out can still have begun; the device's active run is followed if nothing else is.
|
|
222
|
+
void pickUpActive();
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
const stop = async () => {
|
|
226
|
+
try {
|
|
227
|
+
const res = await fetch(`/api/test_runs/${encodeURIComponent(tracked)}`, { method: "DELETE", headers: HEADERS });
|
|
228
|
+
const answer = await res.json();
|
|
229
|
+
if (res.status >= 400)
|
|
230
|
+
setNote(String(answer.error ?? `HTTP ${res.status}`));
|
|
231
|
+
else
|
|
232
|
+
setRun(answer);
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
setNote("request failed");
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
// The whole settled snapshot, with the case it ran, since two pasted summaries are hard to tell apart without it.
|
|
239
|
+
const copySummary = async () => {
|
|
240
|
+
setNote("");
|
|
241
|
+
try {
|
|
242
|
+
await navigator.clipboard.writeText(JSON.stringify({ case: caseRef.current, run }, null, 2));
|
|
243
|
+
setCopied(true);
|
|
244
|
+
clearTimeout(copiedTimer.current);
|
|
245
|
+
copiedTimer.current = setTimeout(() => setCopied(false), 1200);
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
setNote("could not copy the summary");
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
// Asks first in the page, because the file is gone for good; the dock's web view has no confirm dialog.
|
|
252
|
+
// A run being followed keeps going; the case file is not part of it.
|
|
253
|
+
const remove = async () => {
|
|
254
|
+
const name = confirming;
|
|
255
|
+
if (!name || deletingRef.current)
|
|
256
|
+
return;
|
|
257
|
+
deletingRef.current = true;
|
|
258
|
+
setDeleting(true);
|
|
259
|
+
setNote("");
|
|
260
|
+
try {
|
|
261
|
+
const res = await fetch(`/test-cases?name=${encodeURIComponent(name)}`, { method: "DELETE", headers: HEADERS });
|
|
262
|
+
// The status decides; a good answer with an odd body still deleted the file.
|
|
263
|
+
const answer = ((await res.json().catch(() => null)) ?? {});
|
|
264
|
+
if (res.status >= 400)
|
|
265
|
+
setNote(String(answer.error ?? `HTTP ${res.status}`));
|
|
266
|
+
else
|
|
267
|
+
setPicked((p) => (p === name ? "" : p));
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
setNote("request failed");
|
|
271
|
+
}
|
|
272
|
+
finally {
|
|
273
|
+
setConfirming("");
|
|
274
|
+
deletingRef.current = false;
|
|
275
|
+
setDeleting(false);
|
|
276
|
+
}
|
|
277
|
+
void loadCases();
|
|
278
|
+
};
|
|
279
|
+
// An error row is pickable so a broken file can be deleted.
|
|
280
|
+
const item = (c) => html `<div
|
|
281
|
+
class=${"dbitem" + (c.name === picked ? " sel" : "") + (c.error ? " bad" : "")}
|
|
282
|
+
title=${c.error ? String(c.error) : undefined}
|
|
283
|
+
onClick=${() => { setPicked(c.name); setConfirming(""); }}
|
|
284
|
+
>${c.name}${c.error ? " (cannot load)" : ""}</div>`;
|
|
285
|
+
const current = cases?.find((c) => c.name === picked);
|
|
286
|
+
const active = tracked !== "" && run?.settled !== true;
|
|
287
|
+
// Delete and its prompt share this, so a re-read that turns the row back into its built-in drops both.
|
|
288
|
+
const deletable = current !== undefined && current.built_in !== true;
|
|
289
|
+
return html `
|
|
290
|
+
<div class="dbview">
|
|
291
|
+
<div class="dbside">
|
|
292
|
+
<div class="dbsec">built in</div>
|
|
293
|
+
${cases == null ? html `<div class="msg ${listError ? "err" : ""}">${listError || "loading…"}</div>` : cases.filter((c) => c.built_in === true).map(item)}
|
|
294
|
+
${cases != null && listError ? html `<div class="msg err">${listError}; the list may be out of date</div>` : null}
|
|
295
|
+
${cases?.some((c) => c.built_in !== true) ? html `<div class="dbsec">saved</div>${cases.filter((c) => c.built_in !== true).map(item)}` : null}
|
|
296
|
+
</div>
|
|
297
|
+
<div class="dbmain">
|
|
298
|
+
<div class="dbmeta">${current?.error
|
|
299
|
+
? `cannot load: ${current.error}`
|
|
300
|
+
: current
|
|
301
|
+
? `${current.events} events (${typeCounts(current.types)}), default repeat ${current.repeat}, rate ${current.rate_per_second ?? "burst"}`
|
|
302
|
+
: "pick a case"}</div>
|
|
303
|
+
${confirming && confirming === picked && deletable ? html `<div class="dbmeta" role="alert">
|
|
304
|
+
Delete the saved case ${confirming}? This removes its file${current?.replaces_built_in ? `, and the built-in ${confirming} comes back` : ""}.
|
|
305
|
+
<button type="button" disabled=${deleting} onClick=${remove}>Yes, delete</button>
|
|
306
|
+
<button type="button" disabled=${deleting} onClick=${() => setConfirming("")}>Cancel</button>
|
|
307
|
+
</div>` : null}
|
|
308
|
+
<div class="dbqbar">
|
|
309
|
+
<input type="number" aria-label="repeat" ref=${repeatRef} placeholder=${current && !current.error ? `repeat ${current.repeat}` : "repeat"} value=${repeat}
|
|
310
|
+
onInput=${(e) => setRepeat(e.currentTarget.value)} />
|
|
311
|
+
<input type="number" aria-label="rate per second" ref=${rateRef} placeholder=${current && !current.error ? `rate/s ${current.rate_per_second ?? "burst"}` : "rate/s"} value=${rate}
|
|
312
|
+
onInput=${(e) => setRate(e.currentTarget.value)} />
|
|
313
|
+
<button type="button" disabled=${!current || current.error || busy} onClick=${start}>Run</button>
|
|
314
|
+
${deletable && confirming !== picked ? html `<button type="button" onClick=${() => setConfirming(picked)}>Delete</button>` : null}
|
|
315
|
+
${active ? html `<button type="button" onClick=${stop}>Stop</button>` : null}
|
|
316
|
+
${run?.settled === true ? html `<button type="button" onClick=${copySummary}>${copied ? "copied" : "Copy summary"}</button>` : null}
|
|
317
|
+
</div>
|
|
318
|
+
${note ? html `<div class="msg err" role="status">${note}</div>` : null}
|
|
319
|
+
<div class="dbmeta">${runCount == null ? "" : `runs on the device: ${runCount}`}</div>
|
|
320
|
+
${run ? html `
|
|
321
|
+
<div class="dbmeta">
|
|
322
|
+
run ${tracked}${elsewhere ? " (picked up from the device)" : ""}: ${run.state}, ${run.sent} of ${run.frames} sent${typeof run.achieved_rate === "number" ? `, ${run.achieved_rate.toFixed(1)}/s` : ""}${run.stop_reason ? `, stopped: ${run.stop_reason}` : ""}${run.summary?.failed_label ? `, failed: ${run.summary.failed_label}` : ""}
|
|
323
|
+
</div>
|
|
324
|
+
<${Summary} run=${run} />` : null}
|
|
325
|
+
${pollNote ? html `<div class="msg err">${pollNote}</div>` : null}
|
|
326
|
+
</div>
|
|
327
|
+
</div>`;
|
|
328
|
+
}
|
|
@@ -589,7 +589,7 @@ function cardsTitle(m) {
|
|
|
589
589
|
: "";
|
|
590
590
|
if (open.length === 0)
|
|
591
591
|
return m.cardsPartial ? partial.trim() : "no card is waiting";
|
|
592
|
-
return `${partial}shown or carried
|
|
592
|
+
return `${partial}shown or carried and not taken down since: ${open.map((c) => `${cardKindWord(c.kind)} ${c.id}`).join("; ")}`;
|
|
593
593
|
}
|
|
594
594
|
function StatCards({ m }) {
|
|
595
595
|
const s = m.stats;
|
package/dist/web/server.d.ts
CHANGED
|
@@ -344,6 +344,7 @@ export declare function fetchSwitchboardBackfill(limit: number, deadlineMs: numb
|
|
|
344
344
|
event: Record<string, unknown>;
|
|
345
345
|
}[]>;
|
|
346
346
|
export declare const _switchboardExportGetForTest: SwitchboardExportGet;
|
|
347
|
+
export declare function _setSaveCaseTotalMsForTest(ms: number): void;
|
|
347
348
|
export declare function _setSwitchboardExportStaleMsForTest(ms: number): void;
|
|
348
349
|
/**
|
|
349
350
|
* Finish a /detail proxy response after an upstream error or timeout. The success
|
package/dist/web/server.js
CHANGED
|
@@ -12,8 +12,13 @@ import { resolveAdbPath } from "../shared/android.js";
|
|
|
12
12
|
import { createTransport } from "../shared/platform.js";
|
|
13
13
|
import { planReconnect } from "../shared/stream.js";
|
|
14
14
|
import { createDashboardScreenController, } from "../shared/dashboard-screen.js";
|
|
15
|
-
import { ENABLE_PING_WAITS_MS, RADAR_HOST, RADAR_PORT, RADAR_VERSION, WEB_PORT_DEFAULT, resetSlackDebugPackage } from "../shared/constants.js";
|
|
15
|
+
import { ENABLE_PING_WAITS_MS, MAX_RADAR_RESPONSE_BYTES, RADAR_HOST, RADAR_PORT, RADAR_VERSION, WEB_PORT_DEFAULT, resetSlackDebugPackage } from "../shared/constants.js";
|
|
16
16
|
import { radarRequestRaw } from "../shared/radar-request-raw.js";
|
|
17
|
+
// The handler writes the case file, but importing it has no side effects, so both surfaces share it.
|
|
18
|
+
import { handleRunTestCase, handleSaveTestCase } from "../mcp/test-runs-tools.js";
|
|
19
|
+
import { radarHttpRequest, REQUEST_TIMED_OUT } from "../mcp/radar-http.js";
|
|
20
|
+
import { unauthorizedResponse } from "../mcp/radar-response.js";
|
|
21
|
+
import { caseStem, deleteCase, listCases, testCaseDir } from "../shared/test-case-store.js";
|
|
17
22
|
import { TokenFileError, clearRadarTokenCache, radarTokenHeaderFor, tokenFileMessage, unauthorizedMessageFor } from "../shared/radar-token.js";
|
|
18
23
|
import { friendlyFeatureFlagError } from "../shared/feature-flags.js";
|
|
19
24
|
import { deviceServerSilentError, foreignRadarOwnerMessage, BareEnableError, readProcessState, } from "../shared/enable-diagnosis.js";
|
|
@@ -1131,8 +1136,17 @@ export function createServer(onShutdown) {
|
|
|
1131
1136
|
handleStream(req, res);
|
|
1132
1137
|
return;
|
|
1133
1138
|
}
|
|
1139
|
+
// Listing cases reads only local files, so it skips the device checks below.
|
|
1140
|
+
if (urlPath === "/test-cases" && req.method === "GET") {
|
|
1141
|
+
handleListTestCasesRoute(res);
|
|
1142
|
+
return;
|
|
1143
|
+
}
|
|
1144
|
+
if (urlPath === "/test-cases" && req.method === "DELETE") {
|
|
1145
|
+
handleDeleteTestCaseRoute(req, res);
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1134
1148
|
const radarHttpRoute = url.startsWith("/backfill") || url.startsWith("/detail") ||
|
|
1135
|
-
url.startsWith("/api/") || url.startsWith("/flags");
|
|
1149
|
+
url.startsWith("/api/") || url.startsWith("/flags") || urlPath === "/test-cases" || urlPath === "/test-cases/run";
|
|
1136
1150
|
if (radarHttpRoute) {
|
|
1137
1151
|
if (!transport.supportsRadarHttpTools) {
|
|
1138
1152
|
sendJson(res, 400, { error: `Radar HTTP tools are not supported on ${transport.platform}` });
|
|
@@ -1239,6 +1253,32 @@ function routeRadarHttp(req, res, url, urlPath) {
|
|
|
1239
1253
|
handleDetail(req, res);
|
|
1240
1254
|
return;
|
|
1241
1255
|
}
|
|
1256
|
+
if (urlPath === "/test-cases") {
|
|
1257
|
+
if (req.method === "POST") {
|
|
1258
|
+
void handleSaveTestCaseRoute(req, res).catch((e) => {
|
|
1259
|
+
if (!res.headersSent && !res.writableEnded) {
|
|
1260
|
+
sendJson(res, 500, { error: e?.message || "internal error" });
|
|
1261
|
+
}
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
else {
|
|
1265
|
+
sendJson(res, 405, { error: "GET, POST or DELETE only" });
|
|
1266
|
+
}
|
|
1267
|
+
return;
|
|
1268
|
+
}
|
|
1269
|
+
if (urlPath === "/test-cases/run") {
|
|
1270
|
+
if (req.method === "POST") {
|
|
1271
|
+
void handleRunTestCaseRoute(req, res).catch((e) => {
|
|
1272
|
+
if (!res.headersSent && !res.writableEnded) {
|
|
1273
|
+
sendJson(res, 500, { error: e?.message || "internal error" });
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
else {
|
|
1278
|
+
sendJson(res, 405, { error: "POST only" });
|
|
1279
|
+
}
|
|
1280
|
+
return;
|
|
1281
|
+
}
|
|
1242
1282
|
if (url.startsWith("/flags")) {
|
|
1243
1283
|
if (req.method === "GET") {
|
|
1244
1284
|
handleFlags(req, res);
|
|
@@ -2300,6 +2340,178 @@ const switchboardExportGetFor = (forwarded) => (apiPath, capBytes = SWITCHBOARD_
|
|
|
2300
2340
|
return radarRequestRaw(RADAR_HOST, RADAR_PORT, apiPath, idleMs, overallMs, capBytes, deadline, forwarded ? transport : null, "dashboard");
|
|
2301
2341
|
};
|
|
2302
2342
|
export const _switchboardExportGetForTest = switchboardExportGetFor(true);
|
|
2343
|
+
const SAVE_CASE_BODY_MAX_BYTES = 16 * 1024;
|
|
2344
|
+
const SAVE_CASE_READ_MS = 4000;
|
|
2345
|
+
// Reads go one at a time, so 200 slow ones would keep the page busy for minutes without a cap on the whole save.
|
|
2346
|
+
let saveCaseTotalMs = 30_000;
|
|
2347
|
+
export function _setSaveCaseTotalMsForTest(ms) {
|
|
2348
|
+
saveCaseTotalMs = ms;
|
|
2349
|
+
}
|
|
2350
|
+
/** Reads a JSON object body, or answers 413 or 400 itself and gives null. */
|
|
2351
|
+
async function readJsonObjectBody(req, res, maxBytes, usage) {
|
|
2352
|
+
const tooLarge = () => sendJson(res, 413, { error: "request body too large" }, { Connection: "close" });
|
|
2353
|
+
const contentLength = Number(req.headers["content-length"]);
|
|
2354
|
+
if (Number.isFinite(contentLength) && contentLength > maxBytes) {
|
|
2355
|
+
tooLarge();
|
|
2356
|
+
return null;
|
|
2357
|
+
}
|
|
2358
|
+
let body;
|
|
2359
|
+
try {
|
|
2360
|
+
body = await readBody(req, maxBytes);
|
|
2361
|
+
}
|
|
2362
|
+
catch (e) {
|
|
2363
|
+
if (e instanceof BodyTooLargeError) {
|
|
2364
|
+
tooLarge();
|
|
2365
|
+
return null;
|
|
2366
|
+
}
|
|
2367
|
+
throw e;
|
|
2368
|
+
}
|
|
2369
|
+
let parsed;
|
|
2370
|
+
try {
|
|
2371
|
+
parsed = JSON.parse(body);
|
|
2372
|
+
}
|
|
2373
|
+
catch {
|
|
2374
|
+
parsed = null;
|
|
2375
|
+
}
|
|
2376
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
2377
|
+
sendJson(res, 400, { error: usage });
|
|
2378
|
+
return null;
|
|
2379
|
+
}
|
|
2380
|
+
return parsed;
|
|
2381
|
+
}
|
|
2382
|
+
/** `POST /test-cases`: body `{name, ids, timestamps?}`; saves the listed RTM events as a replayable case. */
|
|
2383
|
+
async function handleSaveTestCaseRoute(req, res) {
|
|
2384
|
+
const parsed = await readJsonObjectBody(req, res, SAVE_CASE_BODY_MAX_BYTES, "body must be JSON {name, ids}");
|
|
2385
|
+
if (!parsed)
|
|
2386
|
+
return;
|
|
2387
|
+
const { name, ids, timestamps } = parsed;
|
|
2388
|
+
// The device restarts its RTM ids with each app process and the page keeps rows for an hour, so a
|
|
2389
|
+
// row's id alone can name a newer event. The page sends each row's timestamp and a mismatch counts as missing.
|
|
2390
|
+
if (timestamps !== undefined && (!Array.isArray(ids) || !Array.isArray(timestamps) || timestamps.length !== ids.length || !timestamps.every((t) => typeof t === "number"))) {
|
|
2391
|
+
sendJson(res, 400, { error: "timestamps must be numbers, one per id" });
|
|
2392
|
+
return;
|
|
2393
|
+
}
|
|
2394
|
+
// An id sent twice with different timestamps can match no single device event, so it counts as missing.
|
|
2395
|
+
const expected = new Map();
|
|
2396
|
+
if (Array.isArray(timestamps)) {
|
|
2397
|
+
ids.forEach((id, i) => {
|
|
2398
|
+
const t = timestamps[i];
|
|
2399
|
+
expected.set(id, expected.has(id) && expected.get(id) !== t ? null : t);
|
|
2400
|
+
});
|
|
2401
|
+
}
|
|
2402
|
+
const forwarded = forwardForRead();
|
|
2403
|
+
const deadline = Date.now() + saveCaseTotalMs;
|
|
2404
|
+
const tooSlow = { error: "the device answered too slowly; nothing was saved, try fewer rows" };
|
|
2405
|
+
const call = async (apiPath) => {
|
|
2406
|
+
if (Date.now() >= deadline)
|
|
2407
|
+
return tooSlow;
|
|
2408
|
+
// Read before the call: a timer can fire a hair early, so the clock after it cannot say the deadline cut it off.
|
|
2409
|
+
const cutByDeadline = deadline - Date.now() < SAVE_CASE_READ_MS;
|
|
2410
|
+
const r = await radarRequestRaw(RADAR_HOST, RADAR_PORT, apiPath, SAVE_CASE_READ_MS, SAVE_CASE_READ_MS, MAX_RADAR_RESPONSE_BYTES, deadline, forwarded ? transport : null, "dashboard");
|
|
2411
|
+
if (r.status === 0 && r.capped)
|
|
2412
|
+
return { error: "an event is too large to save" };
|
|
2413
|
+
if (r.status === 0 && cutByDeadline)
|
|
2414
|
+
return tooSlow;
|
|
2415
|
+
if (r.status === 0)
|
|
2416
|
+
return { error: "Device unreachable. Is Radar armed?" };
|
|
2417
|
+
if (r.status === 401)
|
|
2418
|
+
return { error: unauthorizedMessageFor(forwarded ? transport : null, "dashboard"), http_status: 401 };
|
|
2419
|
+
if (r.status >= 400)
|
|
2420
|
+
return { ...(r.body ?? {}), http_status: r.status };
|
|
2421
|
+
const want = expected.get(Number(apiPath.slice(apiPath.lastIndexOf("/") + 1)));
|
|
2422
|
+
if (want !== undefined && (want === null || r.body?.timestamp !== want))
|
|
2423
|
+
return { http_status: 404 };
|
|
2424
|
+
return r.body ?? {};
|
|
2425
|
+
};
|
|
2426
|
+
// Only name and ids go through, so repeat and rate stay at their defaults and a taken name is refused.
|
|
2427
|
+
const out = await handleSaveTestCase({ name, ids }, call);
|
|
2428
|
+
if (out.isError) {
|
|
2429
|
+
// The handler words errors for the model; the page gets plain lines for the ones it can cause.
|
|
2430
|
+
const data = out.data;
|
|
2431
|
+
const reason = data.reason;
|
|
2432
|
+
if (reason === "name_taken") {
|
|
2433
|
+
sendJson(res, 400, { ...data, error: `${typeof name === "string" ? caseStem(name) : "that name"} is taken; pick another name` });
|
|
2434
|
+
return;
|
|
2435
|
+
}
|
|
2436
|
+
if (reason === "bad_ids") {
|
|
2437
|
+
sendJson(res, 400, { ...data, error: "select 1 to 200 rows" });
|
|
2438
|
+
return;
|
|
2439
|
+
}
|
|
2440
|
+
if (reason === "store_failed") {
|
|
2441
|
+
sendJson(res, 400, { ...data, error: "the case file could not be written; nothing was saved" });
|
|
2442
|
+
return;
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
sendJson(res, out.isError ? 400 : 200, out.data);
|
|
2446
|
+
}
|
|
2447
|
+
// A broken file's error names the file by its full path, and a dangling link names the folder bare
|
|
2448
|
+
// ("... In <dir>: ..."); the page gets the file name only.
|
|
2449
|
+
function stripCaseFolder(text, dir) {
|
|
2450
|
+
return text.split(dir + path.sep).join("").split(dir).join("the test-cases folder");
|
|
2451
|
+
}
|
|
2452
|
+
/** `GET /test-cases`: the built-in and saved cases, without the store's file paths. */
|
|
2453
|
+
function handleListTestCasesRoute(res) {
|
|
2454
|
+
const { dir, cases: listed } = listCases();
|
|
2455
|
+
const cases = listed.map(({ path: _path, ...rest }) => (typeof rest.error === "string" ? { ...rest, error: stripCaseFolder(rest.error, dir) } : rest));
|
|
2456
|
+
sendJson(res, 200, { cases });
|
|
2457
|
+
}
|
|
2458
|
+
/** `DELETE /test-cases?name=<case>`: removes a saved case file. */
|
|
2459
|
+
function handleDeleteTestCaseRoute(req, res) {
|
|
2460
|
+
const name = new URL(req.url ?? "", "http://localhost").searchParams.get("name") ?? "";
|
|
2461
|
+
const out = deleteCase(name, testCaseDir());
|
|
2462
|
+
sendJson(res, "error" in out ? 400 : 200, "error" in out ? { error: stripCaseFolder(out.error, testCaseDir()) } : out);
|
|
2463
|
+
}
|
|
2464
|
+
const RUN_CASE_BODY_MAX_BYTES = 4096;
|
|
2465
|
+
/** `POST /test-cases/run`: body `{case, repeat?, rate_per_second?}`; starts the run the way the `run_test_case` tool does. */
|
|
2466
|
+
async function handleRunTestCaseRoute(req, res) {
|
|
2467
|
+
const parsed = await readJsonObjectBody(req, res, RUN_CASE_BODY_MAX_BYTES, "body must be JSON {case, repeat?, rate_per_second?}");
|
|
2468
|
+
if (!parsed)
|
|
2469
|
+
return;
|
|
2470
|
+
const input = parsed;
|
|
2471
|
+
const args = { case: input.case };
|
|
2472
|
+
// A null or non-number rate would start a burst, so a value that is sent must be a real number;
|
|
2473
|
+
// leaving it out keeps the case's own value.
|
|
2474
|
+
for (const key of ["repeat", "rate_per_second"]) {
|
|
2475
|
+
const v = input[key];
|
|
2476
|
+
if (v === undefined)
|
|
2477
|
+
continue;
|
|
2478
|
+
if (typeof v !== "number" || !Number.isFinite(v)) {
|
|
2479
|
+
sendJson(res, 400, { error: `${key === "repeat" ? "repeat" : "rate"} must be a number` });
|
|
2480
|
+
return;
|
|
2481
|
+
}
|
|
2482
|
+
args[key] = v;
|
|
2483
|
+
}
|
|
2484
|
+
const forwarded = forwardForRead();
|
|
2485
|
+
const out = await handleRunTestCase(args, async (apiPath, init) => {
|
|
2486
|
+
try {
|
|
2487
|
+
return unauthorizedResponse(await radarHttpRequest({
|
|
2488
|
+
host: RADAR_HOST, port: RADAR_PORT, path: apiPath, method: init?.method, body: init?.body,
|
|
2489
|
+
timeoutMs: init?.timeoutMs, deadlineMs: init?.deadlineMs, transport: forwarded ? transport : null,
|
|
2490
|
+
}), forwarded ? transport : null, "dashboard");
|
|
2491
|
+
}
|
|
2492
|
+
catch (e) {
|
|
2493
|
+
// Only a timeout is read back; a reset after the send is left to the tab's active-run pick-up.
|
|
2494
|
+
if (init?.reportLost && e.message === REQUEST_TIMED_OUT) {
|
|
2495
|
+
return { error: `Device unreachable or too slow: ${REQUEST_TIMED_OUT}`, request_lost: true };
|
|
2496
|
+
}
|
|
2497
|
+
return { error: "Device unreachable. Is Radar armed?" };
|
|
2498
|
+
}
|
|
2499
|
+
});
|
|
2500
|
+
const data = out.data;
|
|
2501
|
+
sendJson(res, out.isError ? 400 : 200, typeof data.error === "string" ? { ...data, error: dashboardRunError(data) } : data);
|
|
2502
|
+
}
|
|
2503
|
+
// The shared handler words its errors for the model ("Call get_test_run ..."); the tab has a Run button and
|
|
2504
|
+
// picks up a running run by itself, and the case folder path stays off the page.
|
|
2505
|
+
function dashboardRunError(data) {
|
|
2506
|
+
if (data.reason === "may_have_started") {
|
|
2507
|
+
return `run ${String(data.run_id)} may have started, but the device did not answer. If it is running it shows here; otherwise press Run again`;
|
|
2508
|
+
}
|
|
2509
|
+
if (data.reason === "frame_check")
|
|
2510
|
+
return "the device refused the run while checking its frames. Press Run again to see the reason";
|
|
2511
|
+
if (data.reason === "not_listed")
|
|
2512
|
+
return "the device did not start the run. Press Run again";
|
|
2513
|
+
return stripCaseFolder(String(data.error), testCaseDir());
|
|
2514
|
+
}
|
|
2303
2515
|
// The body is at most `{id?}`.
|
|
2304
2516
|
const SWITCHBOARD_EXPORT_BODY_MAX_BYTES = 4096;
|
|
2305
2517
|
/**
|
package/dist/web/spec.d.ts
CHANGED
|
@@ -12,12 +12,13 @@
|
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
14
|
* Sources the dashboard can read. The first five plus "switchboard" are live streams; "all" is
|
|
15
|
-
* their unified timeline. "db", "prefs", and "
|
|
15
|
+
* their unified timeline. "db", "prefs", "flags", and "testcases" are point-in-time browsers (not
|
|
16
16
|
* streams) and are each handled as a distinct view. "switchboard" is the Slackbot voice transport's
|
|
17
17
|
* own event stream (session / state / frame / phase / player / levels / turn / saved_turn / card records),
|
|
18
18
|
* device-produced like rtm.
|
|
19
19
|
*/
|
|
20
|
-
export declare const SOURCES: readonly ["rtm", "network", "clog", "trace", "log", "switchboard", "all", "db", "prefs", "flags"];
|
|
20
|
+
export declare const SOURCES: readonly ["rtm", "network", "clog", "trace", "log", "switchboard", "all", "db", "prefs", "flags", "testcases"];
|
|
21
|
+
export declare const STATE_SOURCES: ReadonlySet<string>;
|
|
21
22
|
export type Source = (typeof SOURCES)[number];
|
|
22
23
|
/** Widgets a spec may compose. */
|
|
23
24
|
export declare const VIZ: readonly ["counter", "rate", "sparkline", "feed", "inspector", "graph", "voice"];
|
package/dist/web/spec.js
CHANGED
|
@@ -12,12 +12,15 @@
|
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
14
|
* Sources the dashboard can read. The first five plus "switchboard" are live streams; "all" is
|
|
15
|
-
* their unified timeline. "db", "prefs", and "
|
|
15
|
+
* their unified timeline. "db", "prefs", "flags", and "testcases" are point-in-time browsers (not
|
|
16
16
|
* streams) and are each handled as a distinct view. "switchboard" is the Slackbot voice transport's
|
|
17
17
|
* own event stream (session / state / frame / phase / player / levels / turn / saved_turn / card records),
|
|
18
18
|
* device-produced like rtm.
|
|
19
19
|
*/
|
|
20
|
-
export const SOURCES = ["rtm", "network", "clog", "trace", "log", "switchboard", "all", "db", "prefs", "flags"];
|
|
20
|
+
export const SOURCES = ["rtm", "network", "clog", "trace", "log", "switchboard", "all", "db", "prefs", "flags", "testcases"];
|
|
21
|
+
// The browser views: no stream rows, so no match, viz, series or exclude to check.
|
|
22
|
+
export const STATE_SOURCES = new Set(["db", "prefs", "flags", "testcases"]);
|
|
23
|
+
const isStateSource = (source) => typeof source === "string" && STATE_SOURCES.has(source);
|
|
21
24
|
/** Widgets a spec may compose. */
|
|
22
25
|
export const VIZ = [
|
|
23
26
|
"counter",
|
|
@@ -90,8 +93,8 @@ export function coerceSpec(input) {
|
|
|
90
93
|
if (s.exclude.length === 0)
|
|
91
94
|
delete s.exclude;
|
|
92
95
|
}
|
|
93
|
-
// The
|
|
94
|
-
if (s.source
|
|
96
|
+
// The state browsers have no match/viz/series to repair; leave as-is.
|
|
97
|
+
if (isStateSource(s.source))
|
|
95
98
|
return s;
|
|
96
99
|
if (typeof s.match === "string") {
|
|
97
100
|
// "all" mixes types whose summary fields differ, so a single field guess
|
|
@@ -168,7 +171,7 @@ export function validateSpec(s) {
|
|
|
168
171
|
if (spec.exclude !== undefined) {
|
|
169
172
|
if (!Array.isArray(spec.exclude))
|
|
170
173
|
return "exclude must be an array of strings";
|
|
171
|
-
if (spec.source
|
|
174
|
+
if (isStateSource(spec.source)) {
|
|
172
175
|
return "exclude applies to stream sources only (log, all, network, rtm, clog, trace, switchboard)";
|
|
173
176
|
}
|
|
174
177
|
if (spec.exclude.length > EXCLUDE_MAX_TERMS)
|
|
@@ -194,11 +197,9 @@ export function validateSpec(s) {
|
|
|
194
197
|
}
|
|
195
198
|
return null;
|
|
196
199
|
}
|
|
197
|
-
// The
|
|
200
|
+
// The state browsers are distinct, self-contained views: no
|
|
198
201
|
// viz/series/match to validate.
|
|
199
|
-
if (spec.source
|
|
200
|
-
return null;
|
|
201
|
-
if (spec.source === "flags")
|
|
202
|
+
if (isStateSource(spec.source))
|
|
202
203
|
return null;
|
|
203
204
|
if (spec.match !== undefined && !isRecord(spec.match)) {
|
|
204
205
|
return "match must be an object";
|