@vellumai/assistant 0.11.2-dev.202608060103.4220693 → 0.11.2-dev.202608060508.a7ab7f7
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/node_modules/@vellumai/ces-client/src/index.ts +1 -0
- package/node_modules/@vellumai/ces-client/src/rpc-client.ts +19 -2
- package/package.json +1 -1
- package/src/__tests__/conversation-error.test.ts +17 -1
- package/src/__tests__/mcp-tool-annotations-risk.test.ts +133 -0
- package/src/__tests__/secret-routes-platform-proxy.test.ts +29 -1
- package/src/__tests__/secure-keys.test.ts +91 -0
- package/src/credential-execution/ces-runtime.ts +3 -0
- package/src/credential-execution/client.ts +22 -1
- package/src/credential-execution/process-manager.test.ts +99 -0
- package/src/credential-execution/process-manager.ts +62 -16
- package/src/daemon/conversation-error.ts +7 -0
- package/src/mcp/client.ts +10 -0
- package/src/providers/__tests__/preflight-resolved-config.test.ts +58 -1
- package/src/providers/connection-resolution.ts +35 -1
- package/src/runtime/routes/secret-routes.ts +40 -23
- package/src/security/credential-backend.ts +51 -4
- package/src/security/encrypted-store.ts +64 -42
- package/src/security/secure-keys.ts +55 -7
- package/src/tools/mcp/mcp-tool-factory.ts +25 -1
|
@@ -69,11 +69,23 @@ interface PendingRequest {
|
|
|
69
69
|
// Client configuration
|
|
70
70
|
// ---------------------------------------------------------------------------
|
|
71
71
|
|
|
72
|
+
/** Minimal logger interface. Callers can supply pino, console, etc. */
|
|
73
|
+
export interface CesRpcLogger {
|
|
74
|
+
info(obj: Record<string, unknown>, msg: string): void;
|
|
75
|
+
info(msg: string): void;
|
|
76
|
+
}
|
|
77
|
+
|
|
72
78
|
export interface CesRpcClientConfig {
|
|
73
79
|
/** Timeout for individual RPC requests (ms). Default: 30 000 */
|
|
74
80
|
requestTimeoutMs?: number;
|
|
75
81
|
/** Timeout for the initial handshake (ms). Default: 10 000 */
|
|
76
82
|
handshakeTimeoutMs?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Optional logger for lifecycle transitions (handshake accepted, close).
|
|
85
|
+
* These transitions are otherwise invisible, which made a stuck credential
|
|
86
|
+
* backend hard to diagnose.
|
|
87
|
+
*/
|
|
88
|
+
logger?: CesRpcLogger;
|
|
77
89
|
}
|
|
78
90
|
|
|
79
91
|
const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
|
|
@@ -154,12 +166,15 @@ export function createCesRpcClient(
|
|
|
154
166
|
config?.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
155
167
|
const handshakeTimeoutMs =
|
|
156
168
|
config?.handshakeTimeoutMs ?? DEFAULT_HANDSHAKE_TIMEOUT_MS;
|
|
169
|
+
const logger = config?.logger;
|
|
157
170
|
|
|
158
171
|
const sessionId = randomUUID();
|
|
159
172
|
let requestCounter = 0;
|
|
160
173
|
let ready = false;
|
|
161
|
-
let inflightHandshake: Promise<{
|
|
162
|
-
|
|
174
|
+
let inflightHandshake: Promise<{
|
|
175
|
+
accepted: boolean;
|
|
176
|
+
reason?: string;
|
|
177
|
+
}> | null = null;
|
|
163
178
|
|
|
164
179
|
const pending = new Map<string, PendingRequest>();
|
|
165
180
|
|
|
@@ -380,6 +395,7 @@ export function createCesRpcClient(
|
|
|
380
395
|
|
|
381
396
|
if (ack.accepted) {
|
|
382
397
|
ready = true;
|
|
398
|
+
logger?.info("CES RPC client handshake accepted; ready for calls");
|
|
383
399
|
}
|
|
384
400
|
|
|
385
401
|
return { accepted: ack.accepted, reason: ack.reason };
|
|
@@ -413,6 +429,7 @@ export function createCesRpcClient(
|
|
|
413
429
|
close(): void {
|
|
414
430
|
rejectAllPending(new CesTransportError("CES client closed"));
|
|
415
431
|
ready = false;
|
|
432
|
+
logger?.info("CES RPC client closed");
|
|
416
433
|
transport.close();
|
|
417
434
|
},
|
|
418
435
|
};
|
package/package.json
CHANGED
|
@@ -1613,7 +1613,7 @@ describe("ConnectionResolutionError classification", () => {
|
|
|
1613
1613
|
expect(result.userMessage).toContain('profile "custom-fast"');
|
|
1614
1614
|
});
|
|
1615
1615
|
|
|
1616
|
-
it("classifies platform_unauthenticated with a log-in fix", () => {
|
|
1616
|
+
it("classifies platform_unauthenticated with a log-in fix on a non-platform install", () => {
|
|
1617
1617
|
const err = new ConnectionResolutionError(
|
|
1618
1618
|
"vellum",
|
|
1619
1619
|
"platform_unauthenticated",
|
|
@@ -1624,6 +1624,22 @@ describe("ConnectionResolutionError classification", () => {
|
|
|
1624
1624
|
expect(result.userMessage).toContain("Log in");
|
|
1625
1625
|
});
|
|
1626
1626
|
|
|
1627
|
+
it("classifies platform_unauthenticated as a re-provision hint on a platform-managed assistant", () => {
|
|
1628
|
+
const err = new ConnectionResolutionError(
|
|
1629
|
+
"vellum",
|
|
1630
|
+
"platform_unauthenticated",
|
|
1631
|
+
"unavailable",
|
|
1632
|
+
);
|
|
1633
|
+
process.env.IS_PLATFORM = "true";
|
|
1634
|
+
try {
|
|
1635
|
+
const result = classifyConversationError(err, errCtx);
|
|
1636
|
+
expect(result.userMessage).toContain("re-provisioned");
|
|
1637
|
+
expect(result.userMessage).not.toContain("Log in");
|
|
1638
|
+
} finally {
|
|
1639
|
+
delete process.env.IS_PLATFORM;
|
|
1640
|
+
}
|
|
1641
|
+
});
|
|
1642
|
+
|
|
1627
1643
|
it("is a structured VellumError (ConfigError) for logging/monitoring", () => {
|
|
1628
1644
|
const err = new ConnectionResolutionError("x", "not_found", "m");
|
|
1629
1645
|
expect(err).toBeInstanceOf(VellumError);
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { describe, expect, jest, mock, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
// Mock secure-keys so McpOAuthProvider doesn't try to access the credential store
|
|
4
|
+
mock.module("../security/secure-keys.js", () => ({
|
|
5
|
+
getSecureKeyAsync: jest.fn().mockResolvedValue(null),
|
|
6
|
+
setSecureKeyAsync: jest.fn().mockResolvedValue(true),
|
|
7
|
+
deleteSecureKeyAsync: jest.fn().mockResolvedValue("deleted"),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
mock.module("../config/env-registry.js", () => ({
|
|
11
|
+
getDebugStdoutLogs: () => false,
|
|
12
|
+
getIsContainerized: () => false,
|
|
13
|
+
getIsPlatform: () => false,
|
|
14
|
+
isPlatformRemote: () => false,
|
|
15
|
+
getWorkspaceDirOverride: () => undefined,
|
|
16
|
+
getBackupDirOverride: () => undefined,
|
|
17
|
+
getBackupKeyPathOverride: () => undefined,
|
|
18
|
+
getCpuLimit: () => undefined,
|
|
19
|
+
getMinikubeStorageSize: () => undefined,
|
|
20
|
+
getProfilerRunId: () => undefined,
|
|
21
|
+
getProfilerMode: () => undefined,
|
|
22
|
+
getProfilerMaxBytes: () => undefined,
|
|
23
|
+
getProfilerMaxRuns: () => undefined,
|
|
24
|
+
getProfilerMinFreeMb: () => undefined,
|
|
25
|
+
checkUnrecognizedEnvVars: () => [],
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
const { McpClient } = await import("../mcp/client.js");
|
|
29
|
+
const { createMcpTool } = await import("../tools/mcp/mcp-tool-factory.js");
|
|
30
|
+
const { RiskLevel } = await import("../permissions/types.js");
|
|
31
|
+
|
|
32
|
+
type ServerRisk = "low" | "medium" | "high";
|
|
33
|
+
|
|
34
|
+
function serverConfig(defaultRiskLevel: ServerRisk) {
|
|
35
|
+
return {
|
|
36
|
+
transport: { type: "stdio" as const, command: "echo", args: [] },
|
|
37
|
+
enabled: true,
|
|
38
|
+
defaultRiskLevel,
|
|
39
|
+
maxTools: 100,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function toolWithAnnotations(readOnlyHint?: boolean) {
|
|
44
|
+
return {
|
|
45
|
+
name: "get-summary",
|
|
46
|
+
description: "Read a summary",
|
|
47
|
+
inputSchema: { type: "object", properties: {} },
|
|
48
|
+
...(readOnlyHint === undefined ? {} : { annotations: { readOnlyHint } }),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
describe("MCP tool risk from readOnlyHint annotations", () => {
|
|
53
|
+
const fakeManager = { callTool: jest.fn() } as never;
|
|
54
|
+
|
|
55
|
+
test("readOnlyHint true on a medium-risk server lowers risk to Low", () => {
|
|
56
|
+
const tool = createMcpTool(
|
|
57
|
+
toolWithAnnotations(true),
|
|
58
|
+
"fathom",
|
|
59
|
+
serverConfig("medium"),
|
|
60
|
+
fakeManager,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
expect(tool.defaultRiskLevel).toBe(RiskLevel.Low);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("readOnlyHint true on a high-risk server leaves risk at High", () => {
|
|
67
|
+
const tool = createMcpTool(
|
|
68
|
+
toolWithAnnotations(true),
|
|
69
|
+
"untrusted",
|
|
70
|
+
serverConfig("high"),
|
|
71
|
+
fakeManager,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
expect(tool.defaultRiskLevel).toBe(RiskLevel.High);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("missing annotations keeps the server default risk", () => {
|
|
78
|
+
const tool = createMcpTool(
|
|
79
|
+
toolWithAnnotations(undefined),
|
|
80
|
+
"fathom",
|
|
81
|
+
serverConfig("medium"),
|
|
82
|
+
fakeManager,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
expect(tool.defaultRiskLevel).toBe(RiskLevel.Medium);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("readOnlyHint false on a low-risk server keeps risk at Low", () => {
|
|
89
|
+
const tool = createMcpTool(
|
|
90
|
+
toolWithAnnotations(false),
|
|
91
|
+
"trusted",
|
|
92
|
+
serverConfig("low"),
|
|
93
|
+
fakeManager,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
expect(tool.defaultRiskLevel).toBe(RiskLevel.Low);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("McpClient.listTools annotations passthrough", () => {
|
|
101
|
+
test("carries server-declared annotations into McpToolInfo", async () => {
|
|
102
|
+
const client = new McpClient("test-server");
|
|
103
|
+
|
|
104
|
+
const listToolsSpy = jest.fn().mockResolvedValue({
|
|
105
|
+
tools: [
|
|
106
|
+
{
|
|
107
|
+
name: "get-summary",
|
|
108
|
+
description: "Read a summary",
|
|
109
|
+
inputSchema: { type: "object", properties: {} },
|
|
110
|
+
annotations: { readOnlyHint: true, title: "Get summary" },
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: "delete-recording",
|
|
114
|
+
description: "Delete a recording",
|
|
115
|
+
inputSchema: { type: "object", properties: {} },
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
(client as unknown as { connected: boolean }).connected = true;
|
|
121
|
+
(client as unknown as { client: unknown }).client = {
|
|
122
|
+
listTools: listToolsSpy,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const tools = await client.listTools();
|
|
126
|
+
|
|
127
|
+
expect(tools[0]?.annotations).toEqual({
|
|
128
|
+
readOnlyHint: true,
|
|
129
|
+
title: "Get summary",
|
|
130
|
+
});
|
|
131
|
+
expect(tools[1]?.annotations).toBeUndefined();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
@@ -108,7 +108,10 @@ import {
|
|
|
108
108
|
initializeProviders,
|
|
109
109
|
listProviders,
|
|
110
110
|
} from "../providers/registry.js";
|
|
111
|
-
import {
|
|
111
|
+
import {
|
|
112
|
+
notifyCesOfAssistantApiKeyUpdate,
|
|
113
|
+
ROUTES,
|
|
114
|
+
} from "../runtime/routes/secret-routes.js";
|
|
112
115
|
|
|
113
116
|
const addRoute = ROUTES.find(
|
|
114
117
|
(r) => r.method === "POST" && r.endpoint === "secrets",
|
|
@@ -176,6 +179,31 @@ describe("secret routes managed proxy registry sync", () => {
|
|
|
176
179
|
expect(lastGeminiConstructorOpts).toBeDefined();
|
|
177
180
|
});
|
|
178
181
|
|
|
182
|
+
test("the CES key-update notification with no CES client logs a warning", async () => {
|
|
183
|
+
// When getCesClient() is undefined the push is skipped, but the skip must
|
|
184
|
+
// be logged, not dropped silently. Exercise the extracted helper directly
|
|
185
|
+
// with an injected logger.
|
|
186
|
+
const warns: string[] = [];
|
|
187
|
+
const fakeLogger = {
|
|
188
|
+
info: () => {},
|
|
189
|
+
warn: (a: unknown, b?: unknown) => {
|
|
190
|
+
warns.push(typeof a === "string" ? a : String(b));
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
await notifyCesOfAssistantApiKeyUpdate(
|
|
195
|
+
"ast-managed-key",
|
|
196
|
+
undefined,
|
|
197
|
+
fakeLogger as unknown as Parameters<
|
|
198
|
+
typeof notifyCesOfAssistantApiKeyUpdate
|
|
199
|
+
>[2],
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
expect(warns.some((m) => m.includes("no CES client is connected"))).toBe(
|
|
203
|
+
true,
|
|
204
|
+
);
|
|
205
|
+
});
|
|
206
|
+
|
|
179
207
|
test("provider API key writes notify live-conversation refresh listeners", async () => {
|
|
180
208
|
await addApiKey("fireworks", "fw-key");
|
|
181
209
|
|
|
@@ -19,6 +19,7 @@ import * as encryptedStore from "../security/encrypted-store.js";
|
|
|
19
19
|
import {
|
|
20
20
|
_resetBackend,
|
|
21
21
|
deleteSecureKeyAsync,
|
|
22
|
+
getActiveBackendName,
|
|
22
23
|
getSecureKeyAsync,
|
|
23
24
|
getSecureKeyResultAsync,
|
|
24
25
|
listSecureKeysAsync,
|
|
@@ -58,6 +59,9 @@ describe("secure-keys", () => {
|
|
|
58
59
|
_resetBackend();
|
|
59
60
|
delete process.env.VELLUM_DEV;
|
|
60
61
|
delete process.env.VELLUM_DESKTOP_APP;
|
|
62
|
+
delete process.env.IS_CONTAINERIZED;
|
|
63
|
+
delete process.env.CES_CREDENTIAL_URL;
|
|
64
|
+
delete process.env.CES_LOCAL_SOCKET;
|
|
61
65
|
});
|
|
62
66
|
|
|
63
67
|
afterAll(() => {
|
|
@@ -507,4 +511,91 @@ describe("secure-keys", () => {
|
|
|
507
511
|
).toBeUndefined();
|
|
508
512
|
});
|
|
509
513
|
});
|
|
514
|
+
|
|
515
|
+
// -----------------------------------------------------------------------
|
|
516
|
+
// Encrypted-store → CES upgrade without a reconnect callback
|
|
517
|
+
// -----------------------------------------------------------------------
|
|
518
|
+
//
|
|
519
|
+
// Worker/CLI processes inject a CES client whose handshake is still in
|
|
520
|
+
// flight, so the first credential read falls back to the encrypted store.
|
|
521
|
+
// These processes never register `_cesReconnect`. Once the handshake
|
|
522
|
+
// completes and the client reports ready, the next read must upgrade to
|
|
523
|
+
// CES RPC, since the live client already exists and no reconnect is needed.
|
|
524
|
+
describe("encrypted-store → CES upgrade without a reconnect callback", () => {
|
|
525
|
+
test("upgrades to CES RPC once the injected client becomes ready", async () => {
|
|
526
|
+
const client = makeMockCesClient(false);
|
|
527
|
+
setCesClient(client);
|
|
528
|
+
|
|
529
|
+
// Not ready yet → falls back to the encrypted store (local mode).
|
|
530
|
+
encryptedStore.setKey("openai", "local-value");
|
|
531
|
+
expect(await getSecureKeyAsync("openai")).toBe("local-value");
|
|
532
|
+
expect(getActiveBackendName()).toBe("encrypted-store");
|
|
533
|
+
|
|
534
|
+
// Handshake completes; no `_cesReconnect` was ever registered.
|
|
535
|
+
client.setReady(true);
|
|
536
|
+
|
|
537
|
+
await getSecureKeyResultAsync("openai");
|
|
538
|
+
expect(getActiveBackendName()).toBe("ces-rpc");
|
|
539
|
+
});
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
// -----------------------------------------------------------------------
|
|
543
|
+
// Containerized pod with no ready CES backend
|
|
544
|
+
// -----------------------------------------------------------------------
|
|
545
|
+
//
|
|
546
|
+
// On a pod the local encrypted store does not exist. When no CES path is
|
|
547
|
+
// ready, reads must report the store as unreachable (presence
|
|
548
|
+
// indeterminate) rather than absent. A provisioned credential is never
|
|
549
|
+
// reported as "no key". The unreachable result must not be pinned: once a
|
|
550
|
+
// CES client arrives, the next read routes through it.
|
|
551
|
+
describe("containerized pod with no ready CES backend", () => {
|
|
552
|
+
test("reads report unreachable (indeterminate), never absent", async () => {
|
|
553
|
+
process.env.IS_CONTAINERIZED = "1";
|
|
554
|
+
delete process.env.CES_CREDENTIAL_URL;
|
|
555
|
+
delete process.env.CES_LOCAL_SOCKET;
|
|
556
|
+
_resetBackend();
|
|
557
|
+
|
|
558
|
+
const result = await getSecureKeyResultAsync("openai");
|
|
559
|
+
expect(result.value).toBeUndefined();
|
|
560
|
+
// unreachable → presence indeterminate, NEVER absent.
|
|
561
|
+
expect(result.unreachable).toBe(true);
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
test("does not pin the unreachable result: a ready CES client wins the next read", async () => {
|
|
565
|
+
process.env.IS_CONTAINERIZED = "1";
|
|
566
|
+
delete process.env.CES_CREDENTIAL_URL;
|
|
567
|
+
delete process.env.CES_LOCAL_SOCKET;
|
|
568
|
+
_resetBackend();
|
|
569
|
+
|
|
570
|
+
expect((await getSecureKeyResultAsync("openai")).unreachable).toBe(true);
|
|
571
|
+
|
|
572
|
+
setCesClient(makeMockCesClient(true));
|
|
573
|
+
|
|
574
|
+
const afterAttach = await getSecureKeyResultAsync("openai");
|
|
575
|
+
expect(afterAttach.unreachable).toBe(false);
|
|
576
|
+
expect(getActiveBackendName()).toBe("ces-rpc");
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
// -----------------------------------------------------------------------
|
|
581
|
+
// Encrypted-store read error vs genuinely-absent (local mode)
|
|
582
|
+
// -----------------------------------------------------------------------
|
|
583
|
+
describe("encrypted-store read error vs absent", () => {
|
|
584
|
+
test("genuinely-missing store → absent (unreachable false)", async () => {
|
|
585
|
+
const result = await getSecureKeyResultAsync("nope");
|
|
586
|
+
expect(result.value).toBeUndefined();
|
|
587
|
+
expect(result.unreachable).toBe(false);
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
test("store exists but key material is missing → unreachable", async () => {
|
|
591
|
+
encryptedStore.setKey("openai", "sk-1");
|
|
592
|
+
// Remove the store key so the existing entry can no longer be decrypted.
|
|
593
|
+
rmSync(join(TEST_DIR, "store.key"));
|
|
594
|
+
_resetBackend();
|
|
595
|
+
|
|
596
|
+
const result = await getSecureKeyResultAsync("openai");
|
|
597
|
+
expect(result.value).toBeUndefined();
|
|
598
|
+
expect(result.unreachable).toBe(true);
|
|
599
|
+
});
|
|
600
|
+
});
|
|
510
601
|
});
|
|
@@ -176,6 +176,9 @@ export async function startCes(config: AssistantConfig): Promise<void> {
|
|
|
176
176
|
},
|
|
177
177
|
});
|
|
178
178
|
if (client) {
|
|
179
|
+
log.info(
|
|
180
|
+
"CES client injected into credential resolver at startup; credential reads route through CES RPC",
|
|
181
|
+
);
|
|
179
182
|
setCesClient(client);
|
|
180
183
|
} else {
|
|
181
184
|
// The handshake lost the startup race, so provider init proceeds on the
|
|
@@ -9,6 +9,15 @@
|
|
|
9
9
|
* delegated to the shared package.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import {
|
|
13
|
+
type CesRpcClient,
|
|
14
|
+
type CesRpcClientConfig,
|
|
15
|
+
type CesTransport,
|
|
16
|
+
createCesRpcClient,
|
|
17
|
+
} from "@vellumai/ces-client/rpc-client";
|
|
18
|
+
|
|
19
|
+
import { getLogger } from "../util/logger.js";
|
|
20
|
+
|
|
12
21
|
export {
|
|
13
22
|
type CesRpcClient as CesClient,
|
|
14
23
|
type CesRpcClientConfig as CesClientConfig,
|
|
@@ -17,5 +26,17 @@ export {
|
|
|
17
26
|
CesHandshakeError,
|
|
18
27
|
type CesTransport,
|
|
19
28
|
CesTransportError,
|
|
20
|
-
createCesRpcClient as createCesClient,
|
|
21
29
|
} from "@vellumai/ces-client/rpc-client";
|
|
30
|
+
|
|
31
|
+
const log = getLogger("ces-rpc-client");
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Construct a CES RPC client wired to the assistant logger so handshake-ready
|
|
35
|
+
* and close transitions are visible in the daemon logs.
|
|
36
|
+
*/
|
|
37
|
+
export function createCesClient(
|
|
38
|
+
transport: CesTransport,
|
|
39
|
+
config?: CesRpcClientConfig,
|
|
40
|
+
): CesRpcClient {
|
|
41
|
+
return createCesRpcClient(transport, { logger: log, ...config });
|
|
42
|
+
}
|
|
@@ -125,3 +125,102 @@ describe("CesProcessManager.onTransportClose", () => {
|
|
|
125
125
|
await pm.stop();
|
|
126
126
|
});
|
|
127
127
|
});
|
|
128
|
+
|
|
129
|
+
// ---------------------------------------------------------------------------
|
|
130
|
+
// Transport-death logging: WARN only for genuinely-unexpected death
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
|
|
133
|
+
type LogCall = { level: string; msg: string };
|
|
134
|
+
|
|
135
|
+
function makeRecordingLogger(): {
|
|
136
|
+
calls: LogCall[];
|
|
137
|
+
logger: NonNullable<Parameters<typeof createCesProcessManager>[0]["logger"]>;
|
|
138
|
+
} {
|
|
139
|
+
const calls: LogCall[] = [];
|
|
140
|
+
const rec =
|
|
141
|
+
(level: string) =>
|
|
142
|
+
(...args: unknown[]) => {
|
|
143
|
+
const msg = typeof args[0] === "string" ? args[0] : args[1];
|
|
144
|
+
calls.push({ level, msg: typeof msg === "string" ? msg : "" });
|
|
145
|
+
};
|
|
146
|
+
const logger = {
|
|
147
|
+
info: rec("info"),
|
|
148
|
+
warn: rec("warn"),
|
|
149
|
+
debug: rec("debug"),
|
|
150
|
+
error: rec("error"),
|
|
151
|
+
} as unknown as NonNullable<
|
|
152
|
+
Parameters<typeof createCesProcessManager>[0]["logger"]
|
|
153
|
+
>;
|
|
154
|
+
return { calls, logger };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
describe("CesProcessManager transport-death logging", () => {
|
|
158
|
+
let tempDir: string;
|
|
159
|
+
let server: Server;
|
|
160
|
+
let connections: Array<import("node:net").Socket>;
|
|
161
|
+
|
|
162
|
+
beforeEach(async () => {
|
|
163
|
+
tempDir = mkdtempSync(join(tmpdir(), "ces-pm-log-test-"));
|
|
164
|
+
mockSocketPath = join(tempDir, "ces.sock");
|
|
165
|
+
connections = [];
|
|
166
|
+
server = createServer((socket) => {
|
|
167
|
+
connections.push(socket);
|
|
168
|
+
socket.on("error", () => {});
|
|
169
|
+
});
|
|
170
|
+
await new Promise<void>((resolve) =>
|
|
171
|
+
server.listen(mockSocketPath, resolve),
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
afterEach(async () => {
|
|
176
|
+
for (const sock of connections) {
|
|
177
|
+
sock.destroy();
|
|
178
|
+
}
|
|
179
|
+
connections = [];
|
|
180
|
+
await new Promise<void>((resolve) => server.close(() => resolve()));
|
|
181
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test("logs WARN when the transport dies unexpectedly (remote close)", async () => {
|
|
185
|
+
const { calls, logger } = makeRecordingLogger();
|
|
186
|
+
const pm = createCesProcessManager({ logger });
|
|
187
|
+
const transport = await pm.start();
|
|
188
|
+
|
|
189
|
+
// The remote (server) closes the connection: genuinely-unexpected death.
|
|
190
|
+
for (const sock of connections) {
|
|
191
|
+
sock.destroy();
|
|
192
|
+
}
|
|
193
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
194
|
+
expect(transport.isAlive()).toBe(false);
|
|
195
|
+
|
|
196
|
+
expect(
|
|
197
|
+
calls.some(
|
|
198
|
+
(c) => c.level === "warn" && c.msg.includes("died unexpectedly"),
|
|
199
|
+
),
|
|
200
|
+
).toBe(true);
|
|
201
|
+
|
|
202
|
+
await pm.stop();
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test("does not log WARN on an intentional stop()", async () => {
|
|
206
|
+
const { calls, logger } = makeRecordingLogger();
|
|
207
|
+
const pm = createCesProcessManager({ logger });
|
|
208
|
+
await pm.start();
|
|
209
|
+
|
|
210
|
+
await pm.stop();
|
|
211
|
+
// Let the socket close event propagate after destroy().
|
|
212
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
213
|
+
|
|
214
|
+
expect(
|
|
215
|
+
calls.some(
|
|
216
|
+
(c) => c.level === "warn" && c.msg.includes("died unexpectedly"),
|
|
217
|
+
),
|
|
218
|
+
).toBe(false);
|
|
219
|
+
expect(
|
|
220
|
+
calls.some(
|
|
221
|
+
(c) =>
|
|
222
|
+
c.level === "debug" && c.msg.includes("CES socket transport closed"),
|
|
223
|
+
),
|
|
224
|
+
).toBe(true);
|
|
225
|
+
});
|
|
226
|
+
});
|