mock-mcp 0.5.0 → 0.5.1

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.
@@ -60,6 +60,27 @@ var __curDirname = (() => {
60
60
  }
61
61
  return process.cwd();
62
62
  })();
63
+ function hasValidProjectMarker(dir) {
64
+ try {
65
+ const gitPath = path__default.default.join(dir, ".git");
66
+ try {
67
+ const stat = fssync__default.default.statSync(gitPath);
68
+ if (stat.isDirectory() || stat.isFile()) {
69
+ return true;
70
+ }
71
+ } catch {
72
+ }
73
+ const pkgPath = path__default.default.join(dir, "package.json");
74
+ try {
75
+ fssync__default.default.accessSync(pkgPath, fssync__default.default.constants.F_OK);
76
+ return true;
77
+ } catch {
78
+ }
79
+ return false;
80
+ } catch {
81
+ return false;
82
+ }
83
+ }
63
84
  function resolveProjectRoot(startDir = process.cwd()) {
64
85
  let current = path__default.default.resolve(startDir);
65
86
  const root = path__default.default.parse(current).root;
@@ -194,7 +215,28 @@ function getDaemonEntryPath() {
194
215
  return path__default.default.join(process.cwd(), "dist", "index.js");
195
216
  }
196
217
  async function ensureDaemonRunning(opts = {}) {
197
- const projectRoot = opts.projectRoot ?? resolveProjectRoot();
218
+ let projectRoot = opts.projectRoot ?? resolveProjectRoot();
219
+ if (!hasValidProjectMarker(projectRoot)) {
220
+ const resolved = resolveProjectRoot(projectRoot);
221
+ if (resolved !== projectRoot && hasValidProjectMarker(resolved)) {
222
+ console.error(`[mock-mcp] Warning: projectRoot "${projectRoot}" doesn't look like a project root`);
223
+ console.error(`[mock-mcp] Found .git/package.json at: "${resolved}"`);
224
+ projectRoot = resolved;
225
+ } else {
226
+ console.error(`[mock-mcp] \u26A0\uFE0F WARNING: Could not find a valid project root!`);
227
+ console.error(`[mock-mcp] Current path: "${projectRoot}"`);
228
+ console.error(`[mock-mcp] This path doesn't contain .git or package.json.`);
229
+ console.error(`[mock-mcp] This may cause project mismatch issues.`);
230
+ console.error(`[mock-mcp] `);
231
+ console.error(`[mock-mcp] For MCP adapters, please specify --project-root explicitly:`);
232
+ console.error(`[mock-mcp] mock-mcp adapter --project-root /path/to/your/project`);
233
+ console.error(`[mock-mcp] `);
234
+ console.error(`[mock-mcp] In your MCP client config (Cursor, Claude Desktop, etc.):`);
235
+ console.error(`[mock-mcp] {`);
236
+ console.error(`[mock-mcp] "args": ["-y", "mock-mcp", "adapter", "--project-root", "/path/to/your/project"]`);
237
+ console.error(`[mock-mcp] }`);
238
+ }
239
+ }
198
240
  const projectId = computeProjectId(projectRoot);
199
241
  const { base, registryPath, lockPath, ipcPath } = getPaths(
200
242
  projectId,
@@ -302,6 +344,77 @@ ${daemonStderr}`);
302
344
  function sleep(ms) {
303
345
  return new Promise((resolve) => setTimeout(resolve, ms));
304
346
  }
347
+ function getGlobalIndexPath(cacheDir) {
348
+ const base = path__default.default.join(getCacheDir(cacheDir), "mock-mcp");
349
+ return path__default.default.join(base, "active-daemons.json");
350
+ }
351
+ async function readGlobalIndex(cacheDir) {
352
+ const indexPath = getGlobalIndexPath(cacheDir);
353
+ try {
354
+ const txt = await fs__default.default.readFile(indexPath, "utf-8");
355
+ return JSON.parse(txt);
356
+ } catch {
357
+ return { daemons: [], updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
358
+ }
359
+ }
360
+ async function writeGlobalIndex(index, cacheDir) {
361
+ const indexPath = getGlobalIndexPath(cacheDir);
362
+ const base = path__default.default.dirname(indexPath);
363
+ await fs__default.default.mkdir(base, { recursive: true });
364
+ await fs__default.default.writeFile(indexPath, JSON.stringify(index, null, 2), {
365
+ encoding: "utf-8",
366
+ mode: 384
367
+ });
368
+ }
369
+ async function registerDaemonGlobally(entry, cacheDir) {
370
+ const index = await readGlobalIndex(cacheDir);
371
+ index.daemons = index.daemons.filter((d) => d.projectId !== entry.projectId);
372
+ index.daemons.push(entry);
373
+ index.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
374
+ await writeGlobalIndex(index, cacheDir);
375
+ debugLog(`Registered daemon ${entry.projectId} in global index`);
376
+ }
377
+ async function unregisterDaemonGlobally(projectId, cacheDir) {
378
+ const index = await readGlobalIndex(cacheDir);
379
+ index.daemons = index.daemons.filter((d) => d.projectId !== projectId);
380
+ index.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
381
+ await writeGlobalIndex(index, cacheDir);
382
+ }
383
+ async function cleanupGlobalIndex(cacheDir) {
384
+ const index = await readGlobalIndex(cacheDir);
385
+ const validDaemons = [];
386
+ for (const entry of index.daemons) {
387
+ try {
388
+ process.kill(entry.pid, 0);
389
+ const healthy = await healthCheck(entry.ipcPath, 1e3);
390
+ if (healthy) {
391
+ validDaemons.push(entry);
392
+ } else {
393
+ debugLog(`Removing unhealthy daemon ${entry.projectId} (pid ${entry.pid})`);
394
+ }
395
+ } catch {
396
+ debugLog(`Removing dead daemon ${entry.projectId} (pid ${entry.pid})`);
397
+ }
398
+ }
399
+ if (validDaemons.length !== index.daemons.length) {
400
+ index.daemons = validDaemons;
401
+ index.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
402
+ await writeGlobalIndex(index, cacheDir);
403
+ }
404
+ }
405
+ async function discoverAllDaemons(cacheDir) {
406
+ await cleanupGlobalIndex(cacheDir);
407
+ const index = await readGlobalIndex(cacheDir);
408
+ const results = [];
409
+ for (const entry of index.daemons) {
410
+ const registry = await readRegistry(entry.registryPath);
411
+ if (registry) {
412
+ const healthy = await healthCheck(entry.ipcPath, 2e3);
413
+ results.push({ registry, healthy });
414
+ }
415
+ }
416
+ return results;
417
+ }
305
418
 
306
419
  // src/shared/protocol.ts
307
420
  var HELLO_TEST = "HELLO_TEST";
@@ -367,10 +480,13 @@ exports.RPC_GET_STATUS = RPC_GET_STATUS;
367
480
  exports.RPC_LIST_RUNS = RPC_LIST_RUNS;
368
481
  exports.RPC_PROVIDE_BATCH = RPC_PROVIDE_BATCH;
369
482
  exports.RPC_RELEASE_BATCH = RPC_RELEASE_BATCH;
483
+ exports.cleanupGlobalIndex = cleanupGlobalIndex;
370
484
  exports.computeProjectId = computeProjectId;
485
+ exports.discoverAllDaemons = discoverAllDaemons;
371
486
  exports.ensureDaemonRunning = ensureDaemonRunning;
372
487
  exports.getCacheDir = getCacheDir;
373
488
  exports.getDaemonEntryPath = getDaemonEntryPath;
489
+ exports.getGlobalIndexPath = getGlobalIndexPath;
374
490
  exports.getPaths = getPaths;
375
491
  exports.healthCheck = healthCheck;
376
492
  exports.isBatchMockRequestMessage = isBatchMockRequestMessage;
@@ -378,9 +494,13 @@ exports.isHeartbeatMessage = isHeartbeatMessage;
378
494
  exports.isHelloTestMessage = isHelloTestMessage;
379
495
  exports.isJsonRpcRequest = isJsonRpcRequest;
380
496
  exports.randomToken = randomToken;
497
+ exports.readGlobalIndex = readGlobalIndex;
381
498
  exports.readRegistry = readRegistry;
499
+ exports.registerDaemonGlobally = registerDaemonGlobally;
382
500
  exports.releaseLock = releaseLock;
383
501
  exports.resolveProjectRoot = resolveProjectRoot;
384
502
  exports.sleep = sleep;
385
503
  exports.tryAcquireLock = tryAcquireLock;
504
+ exports.unregisterDaemonGlobally = unregisterDaemonGlobally;
505
+ exports.writeGlobalIndex = writeGlobalIndex;
386
506
  exports.writeRegistry = writeRegistry;
@@ -1,4 +1,241 @@
1
- export { j as DaemonPaths, D as DaemonRegistry, E as EnsureDaemonOptions, c as computeProjectId, i as ensureDaemonRunning, g as getCacheDir, f as getDaemonEntryPath, a as getPaths, h as healthCheck, e as randomToken, b as readRegistry, d as releaseLock, r as resolveProjectRoot, s as sleep, t as tryAcquireLock, w as writeRegistry } from '../discovery-Dc2LdF8q.cjs';
2
- export { B as BATCH_MOCK_REQUEST, b as BATCH_MOCK_RESULT, y as BatchMockRequestMessage, z as BatchMockResultMessage, W as BatchRecord, U as BatchStatus, G as ClaimNextBatchParams, I as ClaimNextBatchResult, M as GetBatchParams, S as GetBatchResult, N as GetStatusResult, c as HEARTBEAT, d as HEARTBEAT_ACK, a as HELLO_ACK, H as HELLO_TEST, C as HeartbeatAckMessage, A as HeartbeatMessage, x as HelloAckMessage, w as HelloTestMessage, F as JsonRpcError, J as JsonRpcRequest, E as JsonRpcResponse, O as ListRunsResult, P as ProvideBatchParams, K as ProvideBatchResult, f as RPC_CLAIM_NEXT_BATCH, q as RPC_ERROR_CONFLICT, r as RPC_ERROR_EXPIRED, n as RPC_ERROR_INTERNAL, m as RPC_ERROR_INVALID_PARAMS, k as RPC_ERROR_INVALID_REQUEST, l as RPC_ERROR_METHOD_NOT_FOUND, o as RPC_ERROR_NOT_FOUND, j as RPC_ERROR_PARSE, p as RPC_ERROR_UNAUTHORIZED, i as RPC_GET_BATCH, R as RPC_GET_STATUS, e as RPC_LIST_RUNS, g as RPC_PROVIDE_BATCH, h as RPC_RELEASE_BATCH, L as ReleaseBatchParams, Q as RunInfo, V as RunRecord, T as TestChannelIncomingMessage, D as TestChannelOutgoingMessage, t as isBatchMockRequestMessage, u as isHeartbeatMessage, s as isHelloTestMessage, v as isJsonRpcRequest } from '../protocol-xZu-wb0n.cjs';
1
+ import { a as MockRequestDescriptor, M as MockResponseDescriptor } from '../types-bEGXLBF0.cjs';
2
+ export { A as ActiveDaemonEntry, v as ActiveDaemonsIndex, q as DaemonPaths, D as DaemonRegistry, E as EnsureDaemonOptions, o as cleanupGlobalIndex, c as computeProjectId, p as discoverAllDaemons, j as ensureDaemonRunning, g as getCacheDir, i as getDaemonEntryPath, k as getGlobalIndexPath, b as getPaths, h as healthCheck, f as randomToken, l as readGlobalIndex, d as readRegistry, n as registerDaemonGlobally, e as releaseLock, r as resolveProjectRoot, s as sleep, t as tryAcquireLock, u as unregisterDaemonGlobally, m as writeGlobalIndex, w as writeRegistry } from '../types-bEGXLBF0.cjs';
3
3
  import 'node:fs';
4
- import '../types-BKREdsyr.cjs';
4
+
5
+ /**
6
+ * Protocol definitions for mock-mcp Daemon communication.
7
+ *
8
+ * Defines message types for:
9
+ * - Test channel (WebSocket /test): Test process ↔ Daemon
10
+ * - Control channel (HTTP /control): Adapter ↔ Daemon (JSON-RPC)
11
+ */
12
+
13
+ declare const HELLO_TEST: "HELLO_TEST";
14
+ declare const HELLO_ACK: "HELLO_ACK";
15
+ declare const BATCH_MOCK_REQUEST: "BATCH_MOCK_REQUEST";
16
+ declare const BATCH_MOCK_RESULT: "BATCH_MOCK_RESULT";
17
+ declare const HEARTBEAT: "HEARTBEAT";
18
+ declare const HEARTBEAT_ACK: "HEARTBEAT_ACK";
19
+ declare const RPC_GET_STATUS: "getStatus";
20
+ declare const RPC_LIST_RUNS: "listRuns";
21
+ declare const RPC_CLAIM_NEXT_BATCH: "claimNextBatch";
22
+ declare const RPC_PROVIDE_BATCH: "provideBatch";
23
+ declare const RPC_RELEASE_BATCH: "releaseBatch";
24
+ declare const RPC_GET_BATCH: "getBatch";
25
+ /**
26
+ * HELLO message from test process to daemon.
27
+ * Must be the first message after WebSocket connection.
28
+ */
29
+ interface HelloTestMessage {
30
+ type: typeof HELLO_TEST;
31
+ token: string;
32
+ runId: string;
33
+ pid: number;
34
+ cwd: string;
35
+ testMeta?: {
36
+ testFile?: string;
37
+ testName?: string;
38
+ };
39
+ }
40
+ /**
41
+ * Acknowledgment of HELLO from daemon.
42
+ */
43
+ interface HelloAckMessage {
44
+ type: typeof HELLO_ACK;
45
+ runId: string;
46
+ }
47
+ /**
48
+ * Batch mock request from test process.
49
+ */
50
+ interface BatchMockRequestMessage {
51
+ type: typeof BATCH_MOCK_REQUEST;
52
+ runId: string;
53
+ requests: MockRequestDescriptor[];
54
+ }
55
+ /**
56
+ * Batch mock result from daemon to test process.
57
+ */
58
+ interface BatchMockResultMessage {
59
+ type: typeof BATCH_MOCK_RESULT;
60
+ batchId: string;
61
+ mocks: MockResponseDescriptor[];
62
+ }
63
+ /**
64
+ * Heartbeat from test process.
65
+ */
66
+ interface HeartbeatMessage {
67
+ type: typeof HEARTBEAT;
68
+ runId: string;
69
+ }
70
+ /**
71
+ * Heartbeat acknowledgment from daemon.
72
+ */
73
+ interface HeartbeatAckMessage {
74
+ type: typeof HEARTBEAT_ACK;
75
+ runId: string;
76
+ }
77
+ /**
78
+ * Union type for all test channel messages (from test process).
79
+ */
80
+ type TestChannelIncomingMessage = HelloTestMessage | BatchMockRequestMessage | HeartbeatMessage;
81
+ /**
82
+ * Union type for all test channel messages (from daemon).
83
+ */
84
+ type TestChannelOutgoingMessage = HelloAckMessage | BatchMockResultMessage | HeartbeatAckMessage;
85
+ /**
86
+ * JSON-RPC 2.0 request structure.
87
+ */
88
+ interface JsonRpcRequest {
89
+ jsonrpc: "2.0";
90
+ id: string | number;
91
+ method: string;
92
+ params?: Record<string, unknown>;
93
+ }
94
+ /**
95
+ * JSON-RPC 2.0 response structure.
96
+ */
97
+ interface JsonRpcResponse {
98
+ jsonrpc: "2.0";
99
+ id: string | number;
100
+ result?: unknown;
101
+ error?: JsonRpcError;
102
+ }
103
+ interface JsonRpcError {
104
+ code: number;
105
+ message: string;
106
+ data?: unknown;
107
+ }
108
+ declare const RPC_ERROR_PARSE = -32700;
109
+ declare const RPC_ERROR_INVALID_REQUEST = -32600;
110
+ declare const RPC_ERROR_METHOD_NOT_FOUND = -32601;
111
+ declare const RPC_ERROR_INVALID_PARAMS = -32602;
112
+ declare const RPC_ERROR_INTERNAL = -32603;
113
+ declare const RPC_ERROR_NOT_FOUND = -32000;
114
+ declare const RPC_ERROR_UNAUTHORIZED = -32001;
115
+ declare const RPC_ERROR_CONFLICT = -32002;
116
+ declare const RPC_ERROR_EXPIRED = -32003;
117
+ /**
118
+ * Parameters for claimNextBatch RPC.
119
+ */
120
+ interface ClaimNextBatchParams {
121
+ adapterId: string;
122
+ runId?: string;
123
+ leaseMs?: number;
124
+ }
125
+ /**
126
+ * Result of claimNextBatch RPC.
127
+ */
128
+ interface ClaimNextBatchResult {
129
+ batchId: string;
130
+ runId: string;
131
+ requests: MockRequestDescriptor[];
132
+ claimToken: string;
133
+ leaseUntil: number;
134
+ }
135
+ /**
136
+ * Parameters for provideBatch RPC.
137
+ */
138
+ interface ProvideBatchParams {
139
+ adapterId: string;
140
+ batchId: string;
141
+ claimToken: string;
142
+ mocks: MockResponseDescriptor[];
143
+ }
144
+ /**
145
+ * Result of provideBatch RPC.
146
+ */
147
+ interface ProvideBatchResult {
148
+ ok: boolean;
149
+ message?: string;
150
+ }
151
+ /**
152
+ * Parameters for releaseBatch RPC.
153
+ */
154
+ interface ReleaseBatchParams {
155
+ adapterId: string;
156
+ batchId: string;
157
+ claimToken: string;
158
+ reason?: string;
159
+ }
160
+ /**
161
+ * Parameters for getBatch RPC.
162
+ */
163
+ interface GetBatchParams {
164
+ batchId: string;
165
+ }
166
+ /**
167
+ * Result of getStatus RPC.
168
+ */
169
+ interface GetStatusResult {
170
+ version: string;
171
+ projectId: string;
172
+ projectRoot: string;
173
+ pid: number;
174
+ uptime: number;
175
+ runs: number;
176
+ pending: number;
177
+ claimed: number;
178
+ totalBatches: number;
179
+ }
180
+ /**
181
+ * Result of listRuns RPC.
182
+ */
183
+ interface ListRunsResult {
184
+ runs: RunInfo[];
185
+ }
186
+ interface RunInfo {
187
+ runId: string;
188
+ pid: number;
189
+ cwd: string;
190
+ startedAt: string;
191
+ lastSeen: number;
192
+ pendingBatches: number;
193
+ testMeta?: {
194
+ testFile?: string;
195
+ testName?: string;
196
+ };
197
+ }
198
+ /**
199
+ * Result of getBatch RPC.
200
+ */
201
+ interface GetBatchResult {
202
+ batchId: string;
203
+ runId: string;
204
+ requests: MockRequestDescriptor[];
205
+ status: BatchStatus;
206
+ createdAt: number;
207
+ claim?: {
208
+ adapterId: string;
209
+ leaseUntil: number;
210
+ };
211
+ }
212
+ type BatchStatus = "pending" | "claimed" | "fulfilled" | "expired";
213
+ interface RunRecord {
214
+ runId: string;
215
+ pid: number;
216
+ cwd: string;
217
+ startedAt: string;
218
+ lastSeen: number;
219
+ testMeta?: {
220
+ testFile?: string;
221
+ testName?: string;
222
+ };
223
+ }
224
+ interface BatchRecord {
225
+ batchId: string;
226
+ runId: string;
227
+ requests: MockRequestDescriptor[];
228
+ createdAt: number;
229
+ status: BatchStatus;
230
+ claim?: {
231
+ adapterId: string;
232
+ claimToken: string;
233
+ leaseUntil: number;
234
+ };
235
+ }
236
+ declare function isHelloTestMessage(msg: unknown): msg is HelloTestMessage;
237
+ declare function isBatchMockRequestMessage(msg: unknown): msg is BatchMockRequestMessage;
238
+ declare function isHeartbeatMessage(msg: unknown): msg is HeartbeatMessage;
239
+ declare function isJsonRpcRequest(msg: unknown): msg is JsonRpcRequest;
240
+
241
+ export { BATCH_MOCK_REQUEST, BATCH_MOCK_RESULT, type BatchMockRequestMessage, type BatchMockResultMessage, type BatchRecord, type BatchStatus, type ClaimNextBatchParams, type ClaimNextBatchResult, type GetBatchParams, type GetBatchResult, type GetStatusResult, HEARTBEAT, HEARTBEAT_ACK, HELLO_ACK, HELLO_TEST, type HeartbeatAckMessage, type HeartbeatMessage, type HelloAckMessage, type HelloTestMessage, type JsonRpcError, type JsonRpcRequest, type JsonRpcResponse, type ListRunsResult, type ProvideBatchParams, type ProvideBatchResult, RPC_CLAIM_NEXT_BATCH, RPC_ERROR_CONFLICT, RPC_ERROR_EXPIRED, RPC_ERROR_INTERNAL, RPC_ERROR_INVALID_PARAMS, RPC_ERROR_INVALID_REQUEST, RPC_ERROR_METHOD_NOT_FOUND, RPC_ERROR_NOT_FOUND, RPC_ERROR_PARSE, RPC_ERROR_UNAUTHORIZED, RPC_GET_BATCH, RPC_GET_STATUS, RPC_LIST_RUNS, RPC_PROVIDE_BATCH, RPC_RELEASE_BATCH, type ReleaseBatchParams, type RunInfo, type RunRecord, type TestChannelIncomingMessage, type TestChannelOutgoingMessage, isBatchMockRequestMessage, isHeartbeatMessage, isHelloTestMessage, isJsonRpcRequest };
@@ -1,4 +1,241 @@
1
- export { j as DaemonPaths, D as DaemonRegistry, E as EnsureDaemonOptions, c as computeProjectId, i as ensureDaemonRunning, g as getCacheDir, f as getDaemonEntryPath, a as getPaths, h as healthCheck, e as randomToken, b as readRegistry, d as releaseLock, r as resolveProjectRoot, s as sleep, t as tryAcquireLock, w as writeRegistry } from '../discovery-Dc2LdF8q.js';
2
- export { B as BATCH_MOCK_REQUEST, b as BATCH_MOCK_RESULT, y as BatchMockRequestMessage, z as BatchMockResultMessage, W as BatchRecord, U as BatchStatus, G as ClaimNextBatchParams, I as ClaimNextBatchResult, M as GetBatchParams, S as GetBatchResult, N as GetStatusResult, c as HEARTBEAT, d as HEARTBEAT_ACK, a as HELLO_ACK, H as HELLO_TEST, C as HeartbeatAckMessage, A as HeartbeatMessage, x as HelloAckMessage, w as HelloTestMessage, F as JsonRpcError, J as JsonRpcRequest, E as JsonRpcResponse, O as ListRunsResult, P as ProvideBatchParams, K as ProvideBatchResult, f as RPC_CLAIM_NEXT_BATCH, q as RPC_ERROR_CONFLICT, r as RPC_ERROR_EXPIRED, n as RPC_ERROR_INTERNAL, m as RPC_ERROR_INVALID_PARAMS, k as RPC_ERROR_INVALID_REQUEST, l as RPC_ERROR_METHOD_NOT_FOUND, o as RPC_ERROR_NOT_FOUND, j as RPC_ERROR_PARSE, p as RPC_ERROR_UNAUTHORIZED, i as RPC_GET_BATCH, R as RPC_GET_STATUS, e as RPC_LIST_RUNS, g as RPC_PROVIDE_BATCH, h as RPC_RELEASE_BATCH, L as ReleaseBatchParams, Q as RunInfo, V as RunRecord, T as TestChannelIncomingMessage, D as TestChannelOutgoingMessage, t as isBatchMockRequestMessage, u as isHeartbeatMessage, s as isHelloTestMessage, v as isJsonRpcRequest } from '../protocol-CiwaQFOt.js';
1
+ import { a as MockRequestDescriptor, M as MockResponseDescriptor } from '../types-bEGXLBF0.js';
2
+ export { A as ActiveDaemonEntry, v as ActiveDaemonsIndex, q as DaemonPaths, D as DaemonRegistry, E as EnsureDaemonOptions, o as cleanupGlobalIndex, c as computeProjectId, p as discoverAllDaemons, j as ensureDaemonRunning, g as getCacheDir, i as getDaemonEntryPath, k as getGlobalIndexPath, b as getPaths, h as healthCheck, f as randomToken, l as readGlobalIndex, d as readRegistry, n as registerDaemonGlobally, e as releaseLock, r as resolveProjectRoot, s as sleep, t as tryAcquireLock, u as unregisterDaemonGlobally, m as writeGlobalIndex, w as writeRegistry } from '../types-bEGXLBF0.js';
3
3
  import 'node:fs';
4
- import '../types-BKREdsyr.js';
4
+
5
+ /**
6
+ * Protocol definitions for mock-mcp Daemon communication.
7
+ *
8
+ * Defines message types for:
9
+ * - Test channel (WebSocket /test): Test process ↔ Daemon
10
+ * - Control channel (HTTP /control): Adapter ↔ Daemon (JSON-RPC)
11
+ */
12
+
13
+ declare const HELLO_TEST: "HELLO_TEST";
14
+ declare const HELLO_ACK: "HELLO_ACK";
15
+ declare const BATCH_MOCK_REQUEST: "BATCH_MOCK_REQUEST";
16
+ declare const BATCH_MOCK_RESULT: "BATCH_MOCK_RESULT";
17
+ declare const HEARTBEAT: "HEARTBEAT";
18
+ declare const HEARTBEAT_ACK: "HEARTBEAT_ACK";
19
+ declare const RPC_GET_STATUS: "getStatus";
20
+ declare const RPC_LIST_RUNS: "listRuns";
21
+ declare const RPC_CLAIM_NEXT_BATCH: "claimNextBatch";
22
+ declare const RPC_PROVIDE_BATCH: "provideBatch";
23
+ declare const RPC_RELEASE_BATCH: "releaseBatch";
24
+ declare const RPC_GET_BATCH: "getBatch";
25
+ /**
26
+ * HELLO message from test process to daemon.
27
+ * Must be the first message after WebSocket connection.
28
+ */
29
+ interface HelloTestMessage {
30
+ type: typeof HELLO_TEST;
31
+ token: string;
32
+ runId: string;
33
+ pid: number;
34
+ cwd: string;
35
+ testMeta?: {
36
+ testFile?: string;
37
+ testName?: string;
38
+ };
39
+ }
40
+ /**
41
+ * Acknowledgment of HELLO from daemon.
42
+ */
43
+ interface HelloAckMessage {
44
+ type: typeof HELLO_ACK;
45
+ runId: string;
46
+ }
47
+ /**
48
+ * Batch mock request from test process.
49
+ */
50
+ interface BatchMockRequestMessage {
51
+ type: typeof BATCH_MOCK_REQUEST;
52
+ runId: string;
53
+ requests: MockRequestDescriptor[];
54
+ }
55
+ /**
56
+ * Batch mock result from daemon to test process.
57
+ */
58
+ interface BatchMockResultMessage {
59
+ type: typeof BATCH_MOCK_RESULT;
60
+ batchId: string;
61
+ mocks: MockResponseDescriptor[];
62
+ }
63
+ /**
64
+ * Heartbeat from test process.
65
+ */
66
+ interface HeartbeatMessage {
67
+ type: typeof HEARTBEAT;
68
+ runId: string;
69
+ }
70
+ /**
71
+ * Heartbeat acknowledgment from daemon.
72
+ */
73
+ interface HeartbeatAckMessage {
74
+ type: typeof HEARTBEAT_ACK;
75
+ runId: string;
76
+ }
77
+ /**
78
+ * Union type for all test channel messages (from test process).
79
+ */
80
+ type TestChannelIncomingMessage = HelloTestMessage | BatchMockRequestMessage | HeartbeatMessage;
81
+ /**
82
+ * Union type for all test channel messages (from daemon).
83
+ */
84
+ type TestChannelOutgoingMessage = HelloAckMessage | BatchMockResultMessage | HeartbeatAckMessage;
85
+ /**
86
+ * JSON-RPC 2.0 request structure.
87
+ */
88
+ interface JsonRpcRequest {
89
+ jsonrpc: "2.0";
90
+ id: string | number;
91
+ method: string;
92
+ params?: Record<string, unknown>;
93
+ }
94
+ /**
95
+ * JSON-RPC 2.0 response structure.
96
+ */
97
+ interface JsonRpcResponse {
98
+ jsonrpc: "2.0";
99
+ id: string | number;
100
+ result?: unknown;
101
+ error?: JsonRpcError;
102
+ }
103
+ interface JsonRpcError {
104
+ code: number;
105
+ message: string;
106
+ data?: unknown;
107
+ }
108
+ declare const RPC_ERROR_PARSE = -32700;
109
+ declare const RPC_ERROR_INVALID_REQUEST = -32600;
110
+ declare const RPC_ERROR_METHOD_NOT_FOUND = -32601;
111
+ declare const RPC_ERROR_INVALID_PARAMS = -32602;
112
+ declare const RPC_ERROR_INTERNAL = -32603;
113
+ declare const RPC_ERROR_NOT_FOUND = -32000;
114
+ declare const RPC_ERROR_UNAUTHORIZED = -32001;
115
+ declare const RPC_ERROR_CONFLICT = -32002;
116
+ declare const RPC_ERROR_EXPIRED = -32003;
117
+ /**
118
+ * Parameters for claimNextBatch RPC.
119
+ */
120
+ interface ClaimNextBatchParams {
121
+ adapterId: string;
122
+ runId?: string;
123
+ leaseMs?: number;
124
+ }
125
+ /**
126
+ * Result of claimNextBatch RPC.
127
+ */
128
+ interface ClaimNextBatchResult {
129
+ batchId: string;
130
+ runId: string;
131
+ requests: MockRequestDescriptor[];
132
+ claimToken: string;
133
+ leaseUntil: number;
134
+ }
135
+ /**
136
+ * Parameters for provideBatch RPC.
137
+ */
138
+ interface ProvideBatchParams {
139
+ adapterId: string;
140
+ batchId: string;
141
+ claimToken: string;
142
+ mocks: MockResponseDescriptor[];
143
+ }
144
+ /**
145
+ * Result of provideBatch RPC.
146
+ */
147
+ interface ProvideBatchResult {
148
+ ok: boolean;
149
+ message?: string;
150
+ }
151
+ /**
152
+ * Parameters for releaseBatch RPC.
153
+ */
154
+ interface ReleaseBatchParams {
155
+ adapterId: string;
156
+ batchId: string;
157
+ claimToken: string;
158
+ reason?: string;
159
+ }
160
+ /**
161
+ * Parameters for getBatch RPC.
162
+ */
163
+ interface GetBatchParams {
164
+ batchId: string;
165
+ }
166
+ /**
167
+ * Result of getStatus RPC.
168
+ */
169
+ interface GetStatusResult {
170
+ version: string;
171
+ projectId: string;
172
+ projectRoot: string;
173
+ pid: number;
174
+ uptime: number;
175
+ runs: number;
176
+ pending: number;
177
+ claimed: number;
178
+ totalBatches: number;
179
+ }
180
+ /**
181
+ * Result of listRuns RPC.
182
+ */
183
+ interface ListRunsResult {
184
+ runs: RunInfo[];
185
+ }
186
+ interface RunInfo {
187
+ runId: string;
188
+ pid: number;
189
+ cwd: string;
190
+ startedAt: string;
191
+ lastSeen: number;
192
+ pendingBatches: number;
193
+ testMeta?: {
194
+ testFile?: string;
195
+ testName?: string;
196
+ };
197
+ }
198
+ /**
199
+ * Result of getBatch RPC.
200
+ */
201
+ interface GetBatchResult {
202
+ batchId: string;
203
+ runId: string;
204
+ requests: MockRequestDescriptor[];
205
+ status: BatchStatus;
206
+ createdAt: number;
207
+ claim?: {
208
+ adapterId: string;
209
+ leaseUntil: number;
210
+ };
211
+ }
212
+ type BatchStatus = "pending" | "claimed" | "fulfilled" | "expired";
213
+ interface RunRecord {
214
+ runId: string;
215
+ pid: number;
216
+ cwd: string;
217
+ startedAt: string;
218
+ lastSeen: number;
219
+ testMeta?: {
220
+ testFile?: string;
221
+ testName?: string;
222
+ };
223
+ }
224
+ interface BatchRecord {
225
+ batchId: string;
226
+ runId: string;
227
+ requests: MockRequestDescriptor[];
228
+ createdAt: number;
229
+ status: BatchStatus;
230
+ claim?: {
231
+ adapterId: string;
232
+ claimToken: string;
233
+ leaseUntil: number;
234
+ };
235
+ }
236
+ declare function isHelloTestMessage(msg: unknown): msg is HelloTestMessage;
237
+ declare function isBatchMockRequestMessage(msg: unknown): msg is BatchMockRequestMessage;
238
+ declare function isHeartbeatMessage(msg: unknown): msg is HeartbeatMessage;
239
+ declare function isJsonRpcRequest(msg: unknown): msg is JsonRpcRequest;
240
+
241
+ export { BATCH_MOCK_REQUEST, BATCH_MOCK_RESULT, type BatchMockRequestMessage, type BatchMockResultMessage, type BatchRecord, type BatchStatus, type ClaimNextBatchParams, type ClaimNextBatchResult, type GetBatchParams, type GetBatchResult, type GetStatusResult, HEARTBEAT, HEARTBEAT_ACK, HELLO_ACK, HELLO_TEST, type HeartbeatAckMessage, type HeartbeatMessage, type HelloAckMessage, type HelloTestMessage, type JsonRpcError, type JsonRpcRequest, type JsonRpcResponse, type ListRunsResult, type ProvideBatchParams, type ProvideBatchResult, RPC_CLAIM_NEXT_BATCH, RPC_ERROR_CONFLICT, RPC_ERROR_EXPIRED, RPC_ERROR_INTERNAL, RPC_ERROR_INVALID_PARAMS, RPC_ERROR_INVALID_REQUEST, RPC_ERROR_METHOD_NOT_FOUND, RPC_ERROR_NOT_FOUND, RPC_ERROR_PARSE, RPC_ERROR_UNAUTHORIZED, RPC_GET_BATCH, RPC_GET_STATUS, RPC_LIST_RUNS, RPC_PROVIDE_BATCH, RPC_RELEASE_BATCH, type ReleaseBatchParams, type RunInfo, type RunRecord, type TestChannelIncomingMessage, type TestChannelOutgoingMessage, isBatchMockRequestMessage, isHeartbeatMessage, isHelloTestMessage, isJsonRpcRequest };