@slack/radar-mcp 1.25.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 +47 -3
- package/dist/mcp/api-paths.d.ts +25 -1
- package/dist/mcp/api-paths.js +85 -9
- package/dist/mcp/dispatch.d.ts +1 -0
- package/dist/mcp/dispatch.js +4 -2
- package/dist/mcp/flags-tools.d.ts +1 -0
- package/dist/mcp/flags-tools.js +1 -1
- package/dist/mcp/index.js +36 -11
- package/dist/mcp/json-rows.d.ts +6 -0
- package/dist/mcp/json-rows.js +10 -0
- package/dist/mcp/radar-response.d.ts +2 -2
- package/dist/mcp/radar-response.js +2 -2
- package/dist/mcp/redact.d.ts +14 -0
- package/dist/mcp/redact.js +71 -0
- package/dist/mcp/session-enable.d.ts +1 -0
- package/dist/mcp/session-enable.js +8 -6
- package/dist/mcp/snapshot-cli.d.ts +52 -0
- package/dist/mcp/snapshot-cli.js +331 -0
- package/dist/mcp/snapshot-summary.d.ts +1 -0
- package/dist/mcp/snapshot-summary.js +254 -0
- package/dist/mcp/snapshot.d.ts +32 -3
- package/dist/mcp/snapshot.js +392 -125
- package/dist/mcp/test-runs-tools.d.ts +2 -0
- package/dist/mcp/test-runs-tools.js +58 -5
- package/dist/mcp/tools.js +32 -6
- package/dist/shared/android.d.ts +40 -4
- package/dist/shared/android.js +199 -12
- package/dist/shared/constants.d.ts +6 -5
- package/dist/shared/constants.js +6 -5
- package/dist/shared/feature-flags.d.ts +14 -5
- package/dist/shared/feature-flags.js +23 -6
- package/dist/shared/radar-token.d.ts +5 -5
- package/dist/shared/radar-token.js +24 -10
- package/dist/shared/switchboard-note.js +2 -1
- package/dist/shared/switchboard-report.js +4 -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 +27 -1
- package/dist/web/install-app.js +1 -1
- package/dist/web/public/index.html +2 -0
- package/dist/web/public/next/app.js +12 -1
- package/dist/web/public/next/feature-flags.js +23 -6
- package/dist/web/public/next/feed.js +19 -4
- package/dist/web/public/next/filters.js +5 -5
- package/dist/web/public/next/flags.js +5 -3
- 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 +4 -2
- 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-model.js +13 -1
- package/dist/web/public/next/voice.js +9 -4
- 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
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";
|
package/package.json
CHANGED
package/dist/mcp/test-cases.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare const CASE_NAME: RegExp;
|
|
2
|
-
export declare const MAX_CASE_FILE_BYTES: number;
|
|
3
|
-
export declare const testCaseDir: () => string;
|
|
4
|
-
export interface TestCase {
|
|
5
|
-
repeat?: number;
|
|
6
|
-
rate_per_second: number | null;
|
|
7
|
-
events: Record<string, unknown>[];
|
|
8
|
-
}
|
|
9
|
-
export declare const BUILTIN_CASES: Map<string, TestCase>;
|
|
10
|
-
export declare function caseStem(name: string): string;
|
|
11
|
-
export declare function loadCase(name: string, dir?: string): TestCase | {
|
|
12
|
-
error: string;
|
|
13
|
-
};
|
|
14
|
-
export declare function buildRunBody(caseDef: TestCase, overrides: Partial<Pick<TestCase, "repeat" | "rate_per_second">>, runId: string): string;
|
package/dist/mcp/test-cases.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import os from "os";
|
|
3
|
-
import path from "path";
|
|
4
|
-
export const CASE_NAME = /^[A-Za-z0-9_-]{1,64}$/;
|
|
5
|
-
export const MAX_CASE_FILE_BYTES = 256 * 1024;
|
|
6
|
-
export const testCaseDir = () => path.join(os.homedir(), ".slack-radar", "test-cases");
|
|
7
|
-
function filler(label) {
|
|
8
|
-
return `${label} {{seq}} ${"made up replay text ".repeat(205)}`;
|
|
9
|
-
}
|
|
10
|
-
const seed = { type: "message", channel: "{{test_channel}}", ts: "{{seq_ts}}", client_msg_id: "{{seq_uuid}}", text: filler("seed"), user: "UZRDR0000001" };
|
|
11
|
-
export const BUILTIN_CASES = new Map([
|
|
12
|
-
["message_changed", { repeat: 100, rate_per_second: 10, events: [seed, {
|
|
13
|
-
type: "message", subtype: "message_changed", channel: "{{test_channel}}",
|
|
14
|
-
message: { ts: "{{seq_ts}}", text: filler("edit"), client_msg_id: "{{seq_uuid}}" },
|
|
15
|
-
}] }],
|
|
16
|
-
["message_replied", { repeat: 100, rate_per_second: 10, events: [seed, {
|
|
17
|
-
type: "message", subtype: "message_replied", channel: "{{test_channel}}",
|
|
18
|
-
message: { ts: "{{seq_ts}}", thread_ts: "{{seq_ts}}", text: filler("reply"), client_msg_id: "{{seq_uuid}}", reply_count: 1, replies: [{ user: "UZRDR0000001", ts: "{{frame_ts}}" }] },
|
|
19
|
-
}] }],
|
|
20
|
-
]);
|
|
21
|
-
export function caseStem(name) {
|
|
22
|
-
return name.replace(/\.json$/, "");
|
|
23
|
-
}
|
|
24
|
-
export function loadCase(name, dir = testCaseDir()) {
|
|
25
|
-
const stem = caseStem(name);
|
|
26
|
-
if (!CASE_NAME.test(stem))
|
|
27
|
-
return { error: "case must match [A-Za-z0-9_-]{1,64}, optionally followed by .json" };
|
|
28
|
-
const filename = path.join(dir, `${stem}.json`);
|
|
29
|
-
let fd;
|
|
30
|
-
try {
|
|
31
|
-
fd = fs.openSync(filename, fs.constants.O_RDONLY | fs.constants.O_NONBLOCK);
|
|
32
|
-
const stat = fs.fstatSync(fd);
|
|
33
|
-
if (!stat.isFile())
|
|
34
|
-
return { error: `${filename} must be a regular file` };
|
|
35
|
-
if (stat.size > MAX_CASE_FILE_BYTES)
|
|
36
|
-
return { error: `${filename} exceeds 256 KB` };
|
|
37
|
-
const text = fs.readFileSync(fd, "utf8");
|
|
38
|
-
let obj;
|
|
39
|
-
try {
|
|
40
|
-
obj = JSON.parse(text.replace(/^\uFEFF/, ""));
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
const message = error.message;
|
|
44
|
-
const line = message.match(/line (\d+) column (\d+)/);
|
|
45
|
-
const position = message.match(/position (\d+)/);
|
|
46
|
-
const location = line ? ` at line ${line[1]} column ${line[2]}` : position ? ` at position ${position[1]}` : "";
|
|
47
|
-
return { error: `${filename} is not valid JSON${location}` };
|
|
48
|
-
}
|
|
49
|
-
if (typeof obj !== "object" || obj === null || Array.isArray(obj) || !Array.isArray(obj.events)) {
|
|
50
|
-
return { error: `${filename} needs an events array in an object` };
|
|
51
|
-
}
|
|
52
|
-
if (!("rate_per_second" in obj))
|
|
53
|
-
return { error: `${filename} needs a rate_per_second key (a number, or null for a burst)` };
|
|
54
|
-
return obj;
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
if (!["ENOENT", "ENOTDIR"].includes(error.code ?? ""))
|
|
58
|
-
return { error: `${filename}: ${error.message}` };
|
|
59
|
-
const builtin = BUILTIN_CASES.get(stem);
|
|
60
|
-
if (builtin)
|
|
61
|
-
return builtin;
|
|
62
|
-
let stems = [];
|
|
63
|
-
try {
|
|
64
|
-
stems = fs.readdirSync(dir).filter((entry) => entry.endsWith(".json")).map(caseStem).sort();
|
|
65
|
-
}
|
|
66
|
-
catch { }
|
|
67
|
-
return { error: `no case named ${stem}. Built in: ${[...BUILTIN_CASES.keys()].join(", ")}. In ${dir}: ${stems.join(", ") || "none"}` };
|
|
68
|
-
}
|
|
69
|
-
finally {
|
|
70
|
-
if (fd !== undefined)
|
|
71
|
-
fs.closeSync(fd);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
export function buildRunBody(caseDef, overrides, runId) {
|
|
75
|
-
return JSON.stringify({ run_id: runId, repeat: overrides.repeat ?? caseDef.repeat ?? 1,
|
|
76
|
-
rate_per_second: "rate_per_second" in overrides ? overrides.rate_per_second : caseDef.rate_per_second, events: caseDef.events });
|
|
77
|
-
}
|
|
File without changes
|
|
File without changes
|