@deepsql/mcp 0.19.0 → 0.21.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.
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+
3
+ const test = require("node:test");
4
+ const assert = require("node:assert/strict");
5
+
6
+ const { parseArgs, buildOpts } = require("../cli");
7
+
8
+ function opts(argv) {
9
+ return buildOpts(parseArgs(argv));
10
+ }
11
+
12
+ function captureStdout() {
13
+ let out = "";
14
+ let err = "";
15
+ return {
16
+ stream: { write: (s) => { out += s; } },
17
+ errStream: { write: (s) => { err += s; } },
18
+ out: () => out,
19
+ err: () => err,
20
+ };
21
+ }
22
+
23
+ function loadWithStubs({ onRequest }) {
24
+ for (const k of [
25
+ require.resolve("../api/client"),
26
+ require.resolve("./_session"),
27
+ require.resolve("./_connections"),
28
+ require.resolve("./connections"),
29
+ ]) {
30
+ delete require.cache[k];
31
+ }
32
+
33
+ const apiKey = require.resolve("../api/client");
34
+ require.cache[apiKey] = {
35
+ id: apiKey, filename: apiKey, loaded: true,
36
+ exports: {
37
+ ApiError: class ApiError extends Error {},
38
+ async request(baseUrl, path, body) {
39
+ return onRequest(baseUrl, path, body);
40
+ },
41
+ setClientContext() {},
42
+ getClientContext() { return null; },
43
+ },
44
+ };
45
+
46
+ const sessKey = require.resolve("./_session");
47
+ require.cache[sessKey] = {
48
+ id: sessKey, filename: sessKey, loaded: true,
49
+ exports: {
50
+ resolveSession: () => ({
51
+ baseUrl: "http://test",
52
+ token: "t",
53
+ defaultConnection: null,
54
+ }),
55
+ },
56
+ };
57
+
58
+ return require("./connections");
59
+ }
60
+
61
+ test("connections test <saved-name> posts only the connection id", async () => {
62
+ const seen = [];
63
+ const connections = loadWithStubs({
64
+ onRequest: (_baseUrl, path, body) => {
65
+ seen.push({ path, body });
66
+ if (path === "/connections") {
67
+ return [{ id: "cid-1", connectionName: "prod", sshPrivateKey: "(masked)" }];
68
+ }
69
+ if (path === "/connections/test") {
70
+ return {
71
+ success: false,
72
+ connectionSuccessful: false,
73
+ message: "Connection failed",
74
+ privileges: [],
75
+ };
76
+ }
77
+ throw new Error(`unexpected path ${path}`);
78
+ },
79
+ });
80
+ const stdout = captureStdout();
81
+ const previousExitCode = process.exitCode;
82
+ process.exitCode = undefined;
83
+ try {
84
+ const code = await connections.run(opts(["test", "prod"]), { stdout: stdout.stream });
85
+
86
+ assert.equal(code, 1);
87
+ assert.equal(process.exitCode, 1);
88
+ assert.deepEqual(seen.at(-1).body.json, { id: "cid-1" });
89
+ assert.match(stdout.out(), /Connection failed/);
90
+ } finally {
91
+ process.exitCode = previousExitCode;
92
+ }
93
+ });
@@ -343,7 +343,7 @@ async function cmdRegressions(opts, { stdout = process.stdout } = {}) {
343
343
  { key: "calls", label: "CALLS" },
344
344
  { key: "sql", label: "QUERY" },
345
345
  ], items.map((r) => ({
346
- fingerprint: trim(r.fingerprint || "", 14),
346
+ fingerprint: trim(r.fingerprint || "", 16),
347
347
  factor: r.regressionFactor != null ? `${r.regressionFactor.toFixed(2)}x` : "?",
348
348
  meanMs: r.meanExecMs != null ? Math.round(r.meanExecMs).toString() : "?",
349
349
  calls: String(r.callsDelta ?? "?"),
@@ -526,7 +526,7 @@ function printTrendRows(stdout, items) {
526
526
  { key: "factor", label: "VS PREV" },
527
527
  { key: "sql", label: "QUERY" },
528
528
  ], items.map((q) => ({
529
- fingerprint: trim(q.fingerprint || "", 14),
529
+ fingerprint: trim(q.fingerprint || "", 16),
530
530
  meanMs: q.meanExecMs != null ? Math.round(q.meanExecMs).toString() : "?",
531
531
  calls: String(q.callsDelta ?? "?"),
532
532
  factor: q.regressionFactor != null ? `${q.regressionFactor.toFixed(2)}x` : "—",