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.
- package/dist/adapter/index.cjs +465 -302
- package/dist/adapter/index.d.cts +93 -6
- package/dist/adapter/index.d.ts +93 -6
- package/dist/adapter/index.js +465 -302
- package/dist/client/connect.cjs +83 -5
- package/dist/client/connect.d.cts +10 -3
- package/dist/client/connect.d.ts +10 -3
- package/dist/client/connect.js +82 -4
- package/dist/client/index.cjs +83 -5
- package/dist/client/index.d.cts +1 -2
- package/dist/client/index.d.ts +1 -2
- package/dist/client/index.js +82 -4
- package/dist/daemon/index.cjs +55 -5
- package/dist/daemon/index.js +54 -4
- package/dist/index.cjs +559 -89
- package/dist/index.d.cts +137 -7
- package/dist/index.d.ts +137 -7
- package/dist/index.js +556 -90
- package/dist/shared/index.cjs +121 -1
- package/dist/shared/index.d.cts +240 -3
- package/dist/shared/index.d.ts +240 -3
- package/dist/shared/index.js +115 -2
- package/dist/{discovery-Dc2LdF8q.d.cts → types-bEGXLBF0.d.cts} +86 -1
- package/dist/{discovery-Dc2LdF8q.d.ts → types-bEGXLBF0.d.ts} +86 -1
- package/package.json +2 -1
- package/dist/protocol-CiwaQFOt.d.ts +0 -239
- package/dist/protocol-xZu-wb0n.d.cts +0 -239
- package/dist/types-BKREdsyr.d.cts +0 -32
- package/dist/types-BKREdsyr.d.ts +0 -32
package/dist/shared/index.js
CHANGED
|
@@ -21,6 +21,27 @@ var __curDirname = (() => {
|
|
|
21
21
|
}
|
|
22
22
|
return process.cwd();
|
|
23
23
|
})();
|
|
24
|
+
function hasValidProjectMarker(dir) {
|
|
25
|
+
try {
|
|
26
|
+
const gitPath = path.join(dir, ".git");
|
|
27
|
+
try {
|
|
28
|
+
const stat = fssync.statSync(gitPath);
|
|
29
|
+
if (stat.isDirectory() || stat.isFile()) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
} catch {
|
|
33
|
+
}
|
|
34
|
+
const pkgPath = path.join(dir, "package.json");
|
|
35
|
+
try {
|
|
36
|
+
fssync.accessSync(pkgPath, fssync.constants.F_OK);
|
|
37
|
+
return true;
|
|
38
|
+
} catch {
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
24
45
|
function resolveProjectRoot(startDir = process.cwd()) {
|
|
25
46
|
let current = path.resolve(startDir);
|
|
26
47
|
const root = path.parse(current).root;
|
|
@@ -155,7 +176,28 @@ function getDaemonEntryPath() {
|
|
|
155
176
|
return path.join(process.cwd(), "dist", "index.js");
|
|
156
177
|
}
|
|
157
178
|
async function ensureDaemonRunning(opts = {}) {
|
|
158
|
-
|
|
179
|
+
let projectRoot = opts.projectRoot ?? resolveProjectRoot();
|
|
180
|
+
if (!hasValidProjectMarker(projectRoot)) {
|
|
181
|
+
const resolved = resolveProjectRoot(projectRoot);
|
|
182
|
+
if (resolved !== projectRoot && hasValidProjectMarker(resolved)) {
|
|
183
|
+
console.error(`[mock-mcp] Warning: projectRoot "${projectRoot}" doesn't look like a project root`);
|
|
184
|
+
console.error(`[mock-mcp] Found .git/package.json at: "${resolved}"`);
|
|
185
|
+
projectRoot = resolved;
|
|
186
|
+
} else {
|
|
187
|
+
console.error(`[mock-mcp] \u26A0\uFE0F WARNING: Could not find a valid project root!`);
|
|
188
|
+
console.error(`[mock-mcp] Current path: "${projectRoot}"`);
|
|
189
|
+
console.error(`[mock-mcp] This path doesn't contain .git or package.json.`);
|
|
190
|
+
console.error(`[mock-mcp] This may cause project mismatch issues.`);
|
|
191
|
+
console.error(`[mock-mcp] `);
|
|
192
|
+
console.error(`[mock-mcp] For MCP adapters, please specify --project-root explicitly:`);
|
|
193
|
+
console.error(`[mock-mcp] mock-mcp adapter --project-root /path/to/your/project`);
|
|
194
|
+
console.error(`[mock-mcp] `);
|
|
195
|
+
console.error(`[mock-mcp] In your MCP client config (Cursor, Claude Desktop, etc.):`);
|
|
196
|
+
console.error(`[mock-mcp] {`);
|
|
197
|
+
console.error(`[mock-mcp] "args": ["-y", "mock-mcp", "adapter", "--project-root", "/path/to/your/project"]`);
|
|
198
|
+
console.error(`[mock-mcp] }`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
159
201
|
const projectId = computeProjectId(projectRoot);
|
|
160
202
|
const { base, registryPath, lockPath, ipcPath } = getPaths(
|
|
161
203
|
projectId,
|
|
@@ -263,6 +305,77 @@ ${daemonStderr}`);
|
|
|
263
305
|
function sleep(ms) {
|
|
264
306
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
265
307
|
}
|
|
308
|
+
function getGlobalIndexPath(cacheDir) {
|
|
309
|
+
const base = path.join(getCacheDir(cacheDir), "mock-mcp");
|
|
310
|
+
return path.join(base, "active-daemons.json");
|
|
311
|
+
}
|
|
312
|
+
async function readGlobalIndex(cacheDir) {
|
|
313
|
+
const indexPath = getGlobalIndexPath(cacheDir);
|
|
314
|
+
try {
|
|
315
|
+
const txt = await fs.readFile(indexPath, "utf-8");
|
|
316
|
+
return JSON.parse(txt);
|
|
317
|
+
} catch {
|
|
318
|
+
return { daemons: [], updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
async function writeGlobalIndex(index, cacheDir) {
|
|
322
|
+
const indexPath = getGlobalIndexPath(cacheDir);
|
|
323
|
+
const base = path.dirname(indexPath);
|
|
324
|
+
await fs.mkdir(base, { recursive: true });
|
|
325
|
+
await fs.writeFile(indexPath, JSON.stringify(index, null, 2), {
|
|
326
|
+
encoding: "utf-8",
|
|
327
|
+
mode: 384
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
async function registerDaemonGlobally(entry, cacheDir) {
|
|
331
|
+
const index = await readGlobalIndex(cacheDir);
|
|
332
|
+
index.daemons = index.daemons.filter((d) => d.projectId !== entry.projectId);
|
|
333
|
+
index.daemons.push(entry);
|
|
334
|
+
index.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
335
|
+
await writeGlobalIndex(index, cacheDir);
|
|
336
|
+
debugLog(`Registered daemon ${entry.projectId} in global index`);
|
|
337
|
+
}
|
|
338
|
+
async function unregisterDaemonGlobally(projectId, cacheDir) {
|
|
339
|
+
const index = await readGlobalIndex(cacheDir);
|
|
340
|
+
index.daemons = index.daemons.filter((d) => d.projectId !== projectId);
|
|
341
|
+
index.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
342
|
+
await writeGlobalIndex(index, cacheDir);
|
|
343
|
+
}
|
|
344
|
+
async function cleanupGlobalIndex(cacheDir) {
|
|
345
|
+
const index = await readGlobalIndex(cacheDir);
|
|
346
|
+
const validDaemons = [];
|
|
347
|
+
for (const entry of index.daemons) {
|
|
348
|
+
try {
|
|
349
|
+
process.kill(entry.pid, 0);
|
|
350
|
+
const healthy = await healthCheck(entry.ipcPath, 1e3);
|
|
351
|
+
if (healthy) {
|
|
352
|
+
validDaemons.push(entry);
|
|
353
|
+
} else {
|
|
354
|
+
debugLog(`Removing unhealthy daemon ${entry.projectId} (pid ${entry.pid})`);
|
|
355
|
+
}
|
|
356
|
+
} catch {
|
|
357
|
+
debugLog(`Removing dead daemon ${entry.projectId} (pid ${entry.pid})`);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (validDaemons.length !== index.daemons.length) {
|
|
361
|
+
index.daemons = validDaemons;
|
|
362
|
+
index.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
363
|
+
await writeGlobalIndex(index, cacheDir);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
async function discoverAllDaemons(cacheDir) {
|
|
367
|
+
await cleanupGlobalIndex(cacheDir);
|
|
368
|
+
const index = await readGlobalIndex(cacheDir);
|
|
369
|
+
const results = [];
|
|
370
|
+
for (const entry of index.daemons) {
|
|
371
|
+
const registry = await readRegistry(entry.registryPath);
|
|
372
|
+
if (registry) {
|
|
373
|
+
const healthy = await healthCheck(entry.ipcPath, 2e3);
|
|
374
|
+
results.push({ registry, healthy });
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return results;
|
|
378
|
+
}
|
|
266
379
|
|
|
267
380
|
// src/shared/protocol.ts
|
|
268
381
|
var HELLO_TEST = "HELLO_TEST";
|
|
@@ -307,4 +420,4 @@ function isJsonRpcRequest(msg) {
|
|
|
307
420
|
return m.jsonrpc === "2.0" && (typeof m.id === "string" || typeof m.id === "number") && typeof m.method === "string";
|
|
308
421
|
}
|
|
309
422
|
|
|
310
|
-
export { BATCH_MOCK_REQUEST, BATCH_MOCK_RESULT, HEARTBEAT, HEARTBEAT_ACK, HELLO_ACK, HELLO_TEST, 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, computeProjectId, ensureDaemonRunning, getCacheDir, getDaemonEntryPath, getPaths, healthCheck, isBatchMockRequestMessage, isHeartbeatMessage, isHelloTestMessage, isJsonRpcRequest, randomToken, readRegistry, releaseLock, resolveProjectRoot, sleep, tryAcquireLock, writeRegistry };
|
|
423
|
+
export { BATCH_MOCK_REQUEST, BATCH_MOCK_RESULT, HEARTBEAT, HEARTBEAT_ACK, HELLO_ACK, HELLO_TEST, 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, cleanupGlobalIndex, computeProjectId, discoverAllDaemons, ensureDaemonRunning, getCacheDir, getDaemonEntryPath, getGlobalIndexPath, getPaths, healthCheck, isBatchMockRequestMessage, isHeartbeatMessage, isHelloTestMessage, isJsonRpcRequest, randomToken, readGlobalIndex, readRegistry, registerDaemonGlobally, releaseLock, resolveProjectRoot, sleep, tryAcquireLock, unregisterDaemonGlobally, writeGlobalIndex, writeRegistry };
|
|
@@ -101,5 +101,90 @@ declare function getDaemonEntryPath(): string;
|
|
|
101
101
|
*/
|
|
102
102
|
declare function ensureDaemonRunning(opts?: EnsureDaemonOptions): Promise<DaemonRegistry>;
|
|
103
103
|
declare function sleep(ms: number): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Entry in the global active daemons index.
|
|
106
|
+
*/
|
|
107
|
+
interface ActiveDaemonEntry {
|
|
108
|
+
projectId: string;
|
|
109
|
+
projectRoot: string;
|
|
110
|
+
ipcPath: string;
|
|
111
|
+
registryPath: string;
|
|
112
|
+
pid: number;
|
|
113
|
+
startedAt: string;
|
|
114
|
+
version: string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Global index of all active daemons.
|
|
118
|
+
*/
|
|
119
|
+
interface ActiveDaemonsIndex {
|
|
120
|
+
daemons: ActiveDaemonEntry[];
|
|
121
|
+
updatedAt: string;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get the path to the global active daemons index file.
|
|
125
|
+
*/
|
|
126
|
+
declare function getGlobalIndexPath(cacheDir?: string): string;
|
|
127
|
+
/**
|
|
128
|
+
* Read the global active daemons index.
|
|
129
|
+
*/
|
|
130
|
+
declare function readGlobalIndex(cacheDir?: string): Promise<ActiveDaemonsIndex>;
|
|
131
|
+
/**
|
|
132
|
+
* Write the global active daemons index.
|
|
133
|
+
*/
|
|
134
|
+
declare function writeGlobalIndex(index: ActiveDaemonsIndex, cacheDir?: string): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Register a daemon in the global index.
|
|
137
|
+
* Called when a daemon starts.
|
|
138
|
+
*/
|
|
139
|
+
declare function registerDaemonGlobally(entry: ActiveDaemonEntry, cacheDir?: string): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Unregister a daemon from the global index.
|
|
142
|
+
* Called when a daemon stops.
|
|
143
|
+
*/
|
|
144
|
+
declare function unregisterDaemonGlobally(projectId: string, cacheDir?: string): Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Clean up stale entries from the global index.
|
|
147
|
+
* Removes entries where the daemon is no longer running.
|
|
148
|
+
*/
|
|
149
|
+
declare function cleanupGlobalIndex(cacheDir?: string): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Discover all active daemons.
|
|
152
|
+
* Returns list of daemons with their connection info.
|
|
153
|
+
*/
|
|
154
|
+
declare function discoverAllDaemons(cacheDir?: string): Promise<{
|
|
155
|
+
registry: DaemonRegistry;
|
|
156
|
+
healthy: boolean;
|
|
157
|
+
}[]>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Core types for mock-mcp.
|
|
161
|
+
*/
|
|
162
|
+
/**
|
|
163
|
+
* Shape of a mock request emitted by the test process.
|
|
164
|
+
*/
|
|
165
|
+
interface MockRequestDescriptor {
|
|
166
|
+
requestId: string;
|
|
167
|
+
endpoint: string;
|
|
168
|
+
method: string;
|
|
169
|
+
body?: unknown;
|
|
170
|
+
headers?: Record<string, string>;
|
|
171
|
+
metadata?: Record<string, unknown>;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Shape of the mock data that needs to be returned for a request.
|
|
175
|
+
*/
|
|
176
|
+
interface MockResponseDescriptor {
|
|
177
|
+
requestId: string;
|
|
178
|
+
data: unknown;
|
|
179
|
+
status?: number;
|
|
180
|
+
headers?: Record<string, string>;
|
|
181
|
+
delayMs?: number;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Resolved mock with typed data.
|
|
185
|
+
*/
|
|
186
|
+
interface ResolvedMock<T = unknown> extends Omit<MockResponseDescriptor, "data"> {
|
|
187
|
+
data: T;
|
|
188
|
+
}
|
|
104
189
|
|
|
105
|
-
export { type DaemonRegistry as D, type EnsureDaemonOptions as E,
|
|
190
|
+
export { type ActiveDaemonEntry as A, type DaemonRegistry as D, type EnsureDaemonOptions as E, type MockResponseDescriptor as M, type ResolvedMock as R, type MockRequestDescriptor as a, getPaths as b, computeProjectId as c, readRegistry as d, releaseLock as e, randomToken as f, getCacheDir as g, healthCheck as h, getDaemonEntryPath as i, ensureDaemonRunning as j, getGlobalIndexPath as k, readGlobalIndex as l, writeGlobalIndex as m, registerDaemonGlobally as n, cleanupGlobalIndex as o, discoverAllDaemons as p, type DaemonPaths as q, resolveProjectRoot as r, sleep as s, tryAcquireLock as t, unregisterDaemonGlobally as u, type ActiveDaemonsIndex as v, writeRegistry as w };
|
|
@@ -101,5 +101,90 @@ declare function getDaemonEntryPath(): string;
|
|
|
101
101
|
*/
|
|
102
102
|
declare function ensureDaemonRunning(opts?: EnsureDaemonOptions): Promise<DaemonRegistry>;
|
|
103
103
|
declare function sleep(ms: number): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Entry in the global active daemons index.
|
|
106
|
+
*/
|
|
107
|
+
interface ActiveDaemonEntry {
|
|
108
|
+
projectId: string;
|
|
109
|
+
projectRoot: string;
|
|
110
|
+
ipcPath: string;
|
|
111
|
+
registryPath: string;
|
|
112
|
+
pid: number;
|
|
113
|
+
startedAt: string;
|
|
114
|
+
version: string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Global index of all active daemons.
|
|
118
|
+
*/
|
|
119
|
+
interface ActiveDaemonsIndex {
|
|
120
|
+
daemons: ActiveDaemonEntry[];
|
|
121
|
+
updatedAt: string;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get the path to the global active daemons index file.
|
|
125
|
+
*/
|
|
126
|
+
declare function getGlobalIndexPath(cacheDir?: string): string;
|
|
127
|
+
/**
|
|
128
|
+
* Read the global active daemons index.
|
|
129
|
+
*/
|
|
130
|
+
declare function readGlobalIndex(cacheDir?: string): Promise<ActiveDaemonsIndex>;
|
|
131
|
+
/**
|
|
132
|
+
* Write the global active daemons index.
|
|
133
|
+
*/
|
|
134
|
+
declare function writeGlobalIndex(index: ActiveDaemonsIndex, cacheDir?: string): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Register a daemon in the global index.
|
|
137
|
+
* Called when a daemon starts.
|
|
138
|
+
*/
|
|
139
|
+
declare function registerDaemonGlobally(entry: ActiveDaemonEntry, cacheDir?: string): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Unregister a daemon from the global index.
|
|
142
|
+
* Called when a daemon stops.
|
|
143
|
+
*/
|
|
144
|
+
declare function unregisterDaemonGlobally(projectId: string, cacheDir?: string): Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Clean up stale entries from the global index.
|
|
147
|
+
* Removes entries where the daemon is no longer running.
|
|
148
|
+
*/
|
|
149
|
+
declare function cleanupGlobalIndex(cacheDir?: string): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Discover all active daemons.
|
|
152
|
+
* Returns list of daemons with their connection info.
|
|
153
|
+
*/
|
|
154
|
+
declare function discoverAllDaemons(cacheDir?: string): Promise<{
|
|
155
|
+
registry: DaemonRegistry;
|
|
156
|
+
healthy: boolean;
|
|
157
|
+
}[]>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Core types for mock-mcp.
|
|
161
|
+
*/
|
|
162
|
+
/**
|
|
163
|
+
* Shape of a mock request emitted by the test process.
|
|
164
|
+
*/
|
|
165
|
+
interface MockRequestDescriptor {
|
|
166
|
+
requestId: string;
|
|
167
|
+
endpoint: string;
|
|
168
|
+
method: string;
|
|
169
|
+
body?: unknown;
|
|
170
|
+
headers?: Record<string, string>;
|
|
171
|
+
metadata?: Record<string, unknown>;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Shape of the mock data that needs to be returned for a request.
|
|
175
|
+
*/
|
|
176
|
+
interface MockResponseDescriptor {
|
|
177
|
+
requestId: string;
|
|
178
|
+
data: unknown;
|
|
179
|
+
status?: number;
|
|
180
|
+
headers?: Record<string, string>;
|
|
181
|
+
delayMs?: number;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Resolved mock with typed data.
|
|
185
|
+
*/
|
|
186
|
+
interface ResolvedMock<T = unknown> extends Omit<MockResponseDescriptor, "data"> {
|
|
187
|
+
data: T;
|
|
188
|
+
}
|
|
104
189
|
|
|
105
|
-
export { type DaemonRegistry as D, type EnsureDaemonOptions as E,
|
|
190
|
+
export { type ActiveDaemonEntry as A, type DaemonRegistry as D, type EnsureDaemonOptions as E, type MockResponseDescriptor as M, type ResolvedMock as R, type MockRequestDescriptor as a, getPaths as b, computeProjectId as c, readRegistry as d, releaseLock as e, randomToken as f, getCacheDir as g, healthCheck as h, getDaemonEntryPath as i, ensureDaemonRunning as j, getGlobalIndexPath as k, readGlobalIndex as l, writeGlobalIndex as m, registerDaemonGlobally as n, cleanupGlobalIndex as o, discoverAllDaemons as p, type DaemonPaths as q, resolveProjectRoot as r, sleep as s, tryAcquireLock as t, unregisterDaemonGlobally as u, type ActiveDaemonsIndex as v, writeRegistry as w };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mock-mcp",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "An MCP server enabling LLMs to write integration tests through live test environment interaction",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -94,6 +94,7 @@
|
|
|
94
94
|
"@vitest/coverage-v8": "^3.2.4",
|
|
95
95
|
"commitizen": "^4.3.1",
|
|
96
96
|
"eslint": "^9.31.0",
|
|
97
|
+
"fetch-mock": "^12.6.0",
|
|
97
98
|
"node-fetch": "^3.3.2",
|
|
98
99
|
"rimraf": "^6.1.2",
|
|
99
100
|
"tsup": "^8.5.0",
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import { M as MockRequestDescriptor, a as MockResponseDescriptor } from './types-BKREdsyr.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Protocol definitions for mock-mcp Daemon communication.
|
|
5
|
-
*
|
|
6
|
-
* Defines message types for:
|
|
7
|
-
* - Test channel (WebSocket /test): Test process ↔ Daemon
|
|
8
|
-
* - Control channel (HTTP /control): Adapter ↔ Daemon (JSON-RPC)
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
declare const HELLO_TEST: "HELLO_TEST";
|
|
12
|
-
declare const HELLO_ACK: "HELLO_ACK";
|
|
13
|
-
declare const BATCH_MOCK_REQUEST: "BATCH_MOCK_REQUEST";
|
|
14
|
-
declare const BATCH_MOCK_RESULT: "BATCH_MOCK_RESULT";
|
|
15
|
-
declare const HEARTBEAT: "HEARTBEAT";
|
|
16
|
-
declare const HEARTBEAT_ACK: "HEARTBEAT_ACK";
|
|
17
|
-
declare const RPC_GET_STATUS: "getStatus";
|
|
18
|
-
declare const RPC_LIST_RUNS: "listRuns";
|
|
19
|
-
declare const RPC_CLAIM_NEXT_BATCH: "claimNextBatch";
|
|
20
|
-
declare const RPC_PROVIDE_BATCH: "provideBatch";
|
|
21
|
-
declare const RPC_RELEASE_BATCH: "releaseBatch";
|
|
22
|
-
declare const RPC_GET_BATCH: "getBatch";
|
|
23
|
-
/**
|
|
24
|
-
* HELLO message from test process to daemon.
|
|
25
|
-
* Must be the first message after WebSocket connection.
|
|
26
|
-
*/
|
|
27
|
-
interface HelloTestMessage {
|
|
28
|
-
type: typeof HELLO_TEST;
|
|
29
|
-
token: string;
|
|
30
|
-
runId: string;
|
|
31
|
-
pid: number;
|
|
32
|
-
cwd: string;
|
|
33
|
-
testMeta?: {
|
|
34
|
-
testFile?: string;
|
|
35
|
-
testName?: string;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Acknowledgment of HELLO from daemon.
|
|
40
|
-
*/
|
|
41
|
-
interface HelloAckMessage {
|
|
42
|
-
type: typeof HELLO_ACK;
|
|
43
|
-
runId: string;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Batch mock request from test process.
|
|
47
|
-
*/
|
|
48
|
-
interface BatchMockRequestMessage {
|
|
49
|
-
type: typeof BATCH_MOCK_REQUEST;
|
|
50
|
-
runId: string;
|
|
51
|
-
requests: MockRequestDescriptor[];
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Batch mock result from daemon to test process.
|
|
55
|
-
*/
|
|
56
|
-
interface BatchMockResultMessage {
|
|
57
|
-
type: typeof BATCH_MOCK_RESULT;
|
|
58
|
-
batchId: string;
|
|
59
|
-
mocks: MockResponseDescriptor[];
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Heartbeat from test process.
|
|
63
|
-
*/
|
|
64
|
-
interface HeartbeatMessage {
|
|
65
|
-
type: typeof HEARTBEAT;
|
|
66
|
-
runId: string;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Heartbeat acknowledgment from daemon.
|
|
70
|
-
*/
|
|
71
|
-
interface HeartbeatAckMessage {
|
|
72
|
-
type: typeof HEARTBEAT_ACK;
|
|
73
|
-
runId: string;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Union type for all test channel messages (from test process).
|
|
77
|
-
*/
|
|
78
|
-
type TestChannelIncomingMessage = HelloTestMessage | BatchMockRequestMessage | HeartbeatMessage;
|
|
79
|
-
/**
|
|
80
|
-
* Union type for all test channel messages (from daemon).
|
|
81
|
-
*/
|
|
82
|
-
type TestChannelOutgoingMessage = HelloAckMessage | BatchMockResultMessage | HeartbeatAckMessage;
|
|
83
|
-
/**
|
|
84
|
-
* JSON-RPC 2.0 request structure.
|
|
85
|
-
*/
|
|
86
|
-
interface JsonRpcRequest {
|
|
87
|
-
jsonrpc: "2.0";
|
|
88
|
-
id: string | number;
|
|
89
|
-
method: string;
|
|
90
|
-
params?: Record<string, unknown>;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* JSON-RPC 2.0 response structure.
|
|
94
|
-
*/
|
|
95
|
-
interface JsonRpcResponse {
|
|
96
|
-
jsonrpc: "2.0";
|
|
97
|
-
id: string | number;
|
|
98
|
-
result?: unknown;
|
|
99
|
-
error?: JsonRpcError;
|
|
100
|
-
}
|
|
101
|
-
interface JsonRpcError {
|
|
102
|
-
code: number;
|
|
103
|
-
message: string;
|
|
104
|
-
data?: unknown;
|
|
105
|
-
}
|
|
106
|
-
declare const RPC_ERROR_PARSE = -32700;
|
|
107
|
-
declare const RPC_ERROR_INVALID_REQUEST = -32600;
|
|
108
|
-
declare const RPC_ERROR_METHOD_NOT_FOUND = -32601;
|
|
109
|
-
declare const RPC_ERROR_INVALID_PARAMS = -32602;
|
|
110
|
-
declare const RPC_ERROR_INTERNAL = -32603;
|
|
111
|
-
declare const RPC_ERROR_NOT_FOUND = -32000;
|
|
112
|
-
declare const RPC_ERROR_UNAUTHORIZED = -32001;
|
|
113
|
-
declare const RPC_ERROR_CONFLICT = -32002;
|
|
114
|
-
declare const RPC_ERROR_EXPIRED = -32003;
|
|
115
|
-
/**
|
|
116
|
-
* Parameters for claimNextBatch RPC.
|
|
117
|
-
*/
|
|
118
|
-
interface ClaimNextBatchParams {
|
|
119
|
-
adapterId: string;
|
|
120
|
-
runId?: string;
|
|
121
|
-
leaseMs?: number;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Result of claimNextBatch RPC.
|
|
125
|
-
*/
|
|
126
|
-
interface ClaimNextBatchResult {
|
|
127
|
-
batchId: string;
|
|
128
|
-
runId: string;
|
|
129
|
-
requests: MockRequestDescriptor[];
|
|
130
|
-
claimToken: string;
|
|
131
|
-
leaseUntil: number;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Parameters for provideBatch RPC.
|
|
135
|
-
*/
|
|
136
|
-
interface ProvideBatchParams {
|
|
137
|
-
adapterId: string;
|
|
138
|
-
batchId: string;
|
|
139
|
-
claimToken: string;
|
|
140
|
-
mocks: MockResponseDescriptor[];
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Result of provideBatch RPC.
|
|
144
|
-
*/
|
|
145
|
-
interface ProvideBatchResult {
|
|
146
|
-
ok: boolean;
|
|
147
|
-
message?: string;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Parameters for releaseBatch RPC.
|
|
151
|
-
*/
|
|
152
|
-
interface ReleaseBatchParams {
|
|
153
|
-
adapterId: string;
|
|
154
|
-
batchId: string;
|
|
155
|
-
claimToken: string;
|
|
156
|
-
reason?: string;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Parameters for getBatch RPC.
|
|
160
|
-
*/
|
|
161
|
-
interface GetBatchParams {
|
|
162
|
-
batchId: string;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Result of getStatus RPC.
|
|
166
|
-
*/
|
|
167
|
-
interface GetStatusResult {
|
|
168
|
-
version: string;
|
|
169
|
-
projectId: string;
|
|
170
|
-
projectRoot: string;
|
|
171
|
-
pid: number;
|
|
172
|
-
uptime: number;
|
|
173
|
-
runs: number;
|
|
174
|
-
pending: number;
|
|
175
|
-
claimed: number;
|
|
176
|
-
totalBatches: number;
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Result of listRuns RPC.
|
|
180
|
-
*/
|
|
181
|
-
interface ListRunsResult {
|
|
182
|
-
runs: RunInfo[];
|
|
183
|
-
}
|
|
184
|
-
interface RunInfo {
|
|
185
|
-
runId: string;
|
|
186
|
-
pid: number;
|
|
187
|
-
cwd: string;
|
|
188
|
-
startedAt: string;
|
|
189
|
-
lastSeen: number;
|
|
190
|
-
pendingBatches: number;
|
|
191
|
-
testMeta?: {
|
|
192
|
-
testFile?: string;
|
|
193
|
-
testName?: string;
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Result of getBatch RPC.
|
|
198
|
-
*/
|
|
199
|
-
interface GetBatchResult {
|
|
200
|
-
batchId: string;
|
|
201
|
-
runId: string;
|
|
202
|
-
requests: MockRequestDescriptor[];
|
|
203
|
-
status: BatchStatus;
|
|
204
|
-
createdAt: number;
|
|
205
|
-
claim?: {
|
|
206
|
-
adapterId: string;
|
|
207
|
-
leaseUntil: number;
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
type BatchStatus = "pending" | "claimed" | "fulfilled" | "expired";
|
|
211
|
-
interface RunRecord {
|
|
212
|
-
runId: string;
|
|
213
|
-
pid: number;
|
|
214
|
-
cwd: string;
|
|
215
|
-
startedAt: string;
|
|
216
|
-
lastSeen: number;
|
|
217
|
-
testMeta?: {
|
|
218
|
-
testFile?: string;
|
|
219
|
-
testName?: string;
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
interface BatchRecord {
|
|
223
|
-
batchId: string;
|
|
224
|
-
runId: string;
|
|
225
|
-
requests: MockRequestDescriptor[];
|
|
226
|
-
createdAt: number;
|
|
227
|
-
status: BatchStatus;
|
|
228
|
-
claim?: {
|
|
229
|
-
adapterId: string;
|
|
230
|
-
claimToken: string;
|
|
231
|
-
leaseUntil: number;
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
declare function isHelloTestMessage(msg: unknown): msg is HelloTestMessage;
|
|
235
|
-
declare function isBatchMockRequestMessage(msg: unknown): msg is BatchMockRequestMessage;
|
|
236
|
-
declare function isHeartbeatMessage(msg: unknown): msg is HeartbeatMessage;
|
|
237
|
-
declare function isJsonRpcRequest(msg: unknown): msg is JsonRpcRequest;
|
|
238
|
-
|
|
239
|
-
export { type HeartbeatMessage as A, BATCH_MOCK_REQUEST as B, type HeartbeatAckMessage as C, type TestChannelOutgoingMessage as D, type JsonRpcResponse as E, type JsonRpcError as F, type ClaimNextBatchParams as G, HELLO_TEST as H, type ClaimNextBatchResult as I, type JsonRpcRequest as J, type ProvideBatchResult as K, type ReleaseBatchParams as L, type GetBatchParams as M, type GetStatusResult as N, type ListRunsResult as O, type ProvideBatchParams as P, type RunInfo as Q, RPC_GET_STATUS as R, type GetBatchResult as S, type TestChannelIncomingMessage as T, type BatchStatus as U, type RunRecord as V, type BatchRecord as W, HELLO_ACK as a, BATCH_MOCK_RESULT as b, HEARTBEAT as c, HEARTBEAT_ACK as d, RPC_LIST_RUNS as e, RPC_CLAIM_NEXT_BATCH as f, RPC_PROVIDE_BATCH as g, RPC_RELEASE_BATCH as h, RPC_GET_BATCH as i, RPC_ERROR_PARSE as j, RPC_ERROR_INVALID_REQUEST as k, RPC_ERROR_METHOD_NOT_FOUND as l, RPC_ERROR_INVALID_PARAMS as m, RPC_ERROR_INTERNAL as n, RPC_ERROR_NOT_FOUND as o, RPC_ERROR_UNAUTHORIZED as p, RPC_ERROR_CONFLICT as q, RPC_ERROR_EXPIRED as r, isHelloTestMessage as s, isBatchMockRequestMessage as t, isHeartbeatMessage as u, isJsonRpcRequest as v, type HelloTestMessage as w, type HelloAckMessage as x, type BatchMockRequestMessage as y, type BatchMockResultMessage as z };
|