@mycadet/assistant 0.12.7-dev.202610111049.d2b52a8 → 0.12.8

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.
Files changed (40) hide show
  1. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/ingress.ts +10 -4
  2. package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/ingress.ts +10 -4
  3. package/node_modules/@mycadet/service-contracts/src/ingress.ts +10 -4
  4. package/openapi.yaml +6679 -658
  5. package/package.json +1 -1
  6. package/src/__tests__/config-loader-cloud-defaults.test.ts +0 -233
  7. package/src/__tests__/credential-health-service.test.ts +0 -14
  8. package/src/__tests__/credential-routes.test.ts +0 -51
  9. package/src/__tests__/init-feature-flag-overrides.test.ts +40 -24
  10. package/src/__tests__/llm-request-log-source-clickhouse.test.ts +2 -2
  11. package/src/__tests__/llm-schema-fallback-profile.test.ts +9 -3
  12. package/src/__tests__/requests-mock.ts +231 -9
  13. package/src/__tests__/secret-routes-cloud-proxy.test.ts +8 -24
  14. package/src/__tests__/secret-routes-scrub.test.ts +2 -42
  15. package/src/__tests__/test-preload.ts +8 -5
  16. package/src/__tests__/web-search.test.ts +340 -859
  17. package/src/api/events/cloud-disconnected.ts +2 -2
  18. package/src/config/schemas/cloud.ts +2 -1
  19. package/src/config/schemas/host-browser.ts +1 -0
  20. package/src/config/schemas/ingress.ts +1 -12
  21. package/src/config/schemas/llm.ts +10 -1
  22. package/src/config/schemas/memory-lifecycle.ts +11 -1
  23. package/src/config/schemas/tts.ts +5 -0
  24. package/src/credential-execution/prompted-credential.ts +6 -18
  25. package/src/credential-health/credential-health-service.ts +6 -21
  26. package/src/daemon/credential-transcript-scrub.ts +21 -29
  27. package/src/ipc/gateway-client.test.ts +55 -59
  28. package/src/persistence/compaction-log-store-clickhouse.ts +1 -1
  29. package/src/persistence/llm-request-log-sink-clickhouse.ts +1 -1
  30. package/src/persistence/llm-request-log-source-clickhouse.ts +1 -1
  31. package/src/runtime/migrations/vbundle-streaming-importer.ts +3 -3
  32. package/src/runtime/routes/__tests__/conversation-query-routes.test.ts +10 -7
  33. package/src/runtime/routes/__tests__/migration-cadet-metadata-reconcile.test.ts +3 -9
  34. package/src/runtime/routes/__tests__/migration-import-credential-filter.test.ts +3 -3
  35. package/src/runtime/routes/cloud-routes.ts +14 -18
  36. package/src/runtime/routes/conversation-query-routes.ts +30 -230
  37. package/src/runtime/routes/migration-routes.ts +5 -6
  38. package/src/runtime/routes/secret-routes.ts +12 -31
  39. package/src/tools/credentials/store.ts +6 -15
  40. package/src/__tests__/mock-gateway-ipc.ts +0 -279
@@ -1,279 +0,0 @@
1
- /**
2
- * Global test utility for mocking gateway IPC calls via
3
- * `@mycadet/gateway-client/ipc-client`.
4
- *
5
- * Usage:
6
- * import { mockGatewayIpc, resetMockGatewayIpc } from "./mock-gateway-ipc.js";
7
- *
8
- * beforeEach(() => resetMockGatewayIpc());
9
- * afterEach(() => resetMockGatewayIpc());
10
- *
11
- * it("uses IPC flags", async () => {
12
- * mockGatewayIpc({ "my-flag": true });
13
- * await initFeatureFlagOverrides();
14
- * ...
15
- * });
16
- *
17
- * it("simulates socket error", async () => {
18
- * mockGatewayIpc(null, { error: true, code: "ENOENT" });
19
- * ...
20
- * });
21
- *
22
- * The mock is registered in the test preload (test-preload.ts) so every test
23
- * file gets a no-op IPC layer by default — no test accidentally connects to
24
- * a real gateway socket. Call `mockGatewayIpc()` to configure specific
25
- * responses when the test cares about the IPC result.
26
- *
27
- * For per-test request-matched registrations (params subsets, sequences,
28
- * thrown errors, call history) use the requests-mock helper:
29
- * `mockIpc("gateway").on(methodOrMatcher, response)` — consulted BEFORE the
30
- * results map; unmatched calls fall through to the map/sentinel behavior.
31
- *
32
- * Mocks `@mycadet/gateway-client/ipc-client` at the package level so the
33
- * assistant's thin wrapper in `ipc/gateway-client.ts` (which delegates to
34
- * the package) gets the fake implementation. Non-gateway IPC paths (e.g.
35
- * CLI IPC) are unaffected since they don't import from the package.
36
- */
37
-
38
- import { EventEmitter } from "node:events";
39
- import { mock } from "bun:test";
40
-
41
- import { dispatchGatewayIpcRequest } from "./requests-mock.js";
42
-
43
- // ---------------------------------------------------------------------------
44
- // Configurable state
45
- // ---------------------------------------------------------------------------
46
-
47
- /** IPC result the fake gateway will return (keyed by method name). */
48
-
49
- let ipcResults: Record<string, unknown> = {};
50
-
51
- /** Whether the fake ipcCall should simulate a connection error. */
52
- let simulateError = false;
53
-
54
- /** `IpcConnectError.code` used when `simulateError` is set. */
55
- let simulateErrorCode: string | undefined;
56
-
57
- /** Throw a transient (retryable) error for the first N persistent calls, then succeed. */
58
- let failFirstN = 0;
59
-
60
- /** When set, the simulated persistent-call failure is a non-retryable IpcCallError. */
61
- let failWithIpcCallError = false;
62
-
63
- /** Per-method persistent-client `.call` counter, so retry tests can assert attempts. */
64
- const persistentCallCounts: Record<string, number> = {};
65
-
66
- // ---------------------------------------------------------------------------
67
- // FakePersistentIpcClient — mirrors PersistentIpcClient API
68
- // ---------------------------------------------------------------------------
69
-
70
- class FakePersistentIpcClient extends EventEmitter {
71
- async call(
72
- method: string,
73
- _params?: Record<string, unknown>,
74
- _timeoutMs?: number,
75
- ): Promise<unknown> {
76
- persistentCallCounts[method] = (persistentCallCounts[method] ?? 0) + 1;
77
- const dispatched = dispatchGatewayIpcRequest(method, _params);
78
- if (dispatched.handled) {
79
- if (dispatched.value instanceof Error) {
80
- throw dispatched.value;
81
- }
82
- return dispatched.value;
83
- }
84
- if (failFirstN > 0) {
85
- failFirstN--;
86
- if (failWithIpcCallError) {
87
- throw new FakeIpcCallError("Mock deterministic gateway error");
88
- }
89
- throw mockConnectError();
90
- }
91
- if (simulateError) {
92
- throw mockConnectError();
93
- }
94
- if (method in ipcResults) {
95
- return ipcResults[method];
96
- }
97
- if (method === "get_feature_flags") {
98
- return GET_FEATURE_FLAGS_DEFAULT;
99
- }
100
- return undefined;
101
- }
102
-
103
- destroy(): void {
104
- /* no-op */
105
- }
106
- }
107
-
108
- // ---------------------------------------------------------------------------
109
- // Register the mock (called once from test-preload.ts)
110
- // ---------------------------------------------------------------------------
111
-
112
- /**
113
- * Sentinel returned by the mock for `get_feature_flags` when a test has not
114
- * explicitly configured a result. Keeps the response non-empty so
115
- * `initFeatureFlagOverrides()` does not enter its 7.75 s empty-result retry
116
- * loop during tests that build the CLI program or otherwise trigger flag
117
- * initialization. The sentinel key starts with a double underscore so it
118
- * cannot collide with any real registry-declared flag.
119
- */
120
- const GET_FEATURE_FLAGS_DEFAULT: Record<string, boolean> = {
121
- __test_default__: false,
122
- };
123
-
124
- class FakeIpcCallError extends Error {
125
- readonly statusCode?: number;
126
- readonly errorCode?: string;
127
- readonly errorDetails?: unknown;
128
-
129
- constructor(
130
- message: string,
131
- fields: {
132
- statusCode?: number;
133
- errorCode?: string;
134
- errorDetails?: unknown;
135
- } = {},
136
- ) {
137
- super(message);
138
- this.name = "IpcCallError";
139
- if (fields.statusCode !== undefined) {
140
- this.statusCode = fields.statusCode;
141
- }
142
- if (fields.errorCode !== undefined) {
143
- this.errorCode = fields.errorCode;
144
- }
145
- if (fields.errorDetails !== undefined) {
146
- this.errorDetails = fields.errorDetails;
147
- }
148
- }
149
- }
150
-
151
- class FakeIpcConnectError extends Error {
152
- readonly code?: string;
153
-
154
- constructor(message: string, code?: string) {
155
- super(message);
156
- this.name = "IpcConnectError";
157
- if (code !== undefined) {
158
- this.code = code;
159
- }
160
- }
161
- }
162
-
163
- const RETRYABLE_CONNECT_CODES = new Set(["ENOENT", "ECONNREFUSED"]);
164
-
165
- function isRetryableIpcConnectError(err: unknown): boolean {
166
- if (typeof err === "object" && err !== null && "code" in err) {
167
- const code = (err as { code?: unknown }).code;
168
- return typeof code === "string" && RETRYABLE_CONNECT_CODES.has(code);
169
- }
170
- return false;
171
- }
172
-
173
- function mockConnectError(): FakeIpcConnectError {
174
- return new FakeIpcConnectError(
175
- "Mock IPC socket error",
176
- simulateErrorCode ?? "ENOENT",
177
- );
178
- }
179
-
180
- export function installGatewayIpcMock(): void {
181
- // Named exports here must cover every ipc-client symbol the package barrel
182
- // re-exports. Bun's mock replaces that module for relative and package
183
- // imports, so a missing name fails assistant tests at load time.
184
- mock.module("@mycadet/gateway-client/ipc-client", () => ({
185
- ipcCall: async (
186
- _socketPath: string,
187
- method: string,
188
- params?: Record<string, unknown>,
189
- ): Promise<unknown> => {
190
- const dispatched = dispatchGatewayIpcRequest(method, params);
191
- if (dispatched.handled) {
192
- // Real ipcCall returns undefined on failure — mirror that behavior.
193
- return dispatched.value instanceof Error ? undefined : dispatched.value;
194
- }
195
- if (simulateError) {
196
- // Real ipcCall returns undefined on failure — mirror that behavior.
197
- return undefined;
198
- }
199
- if (method in ipcResults) {
200
- return ipcResults[method];
201
- }
202
- if (method === "get_feature_flags") {
203
- return GET_FEATURE_FLAGS_DEFAULT;
204
- }
205
- return undefined;
206
- },
207
- IpcCallError: FakeIpcCallError,
208
- IpcConnectError: FakeIpcConnectError,
209
- isRetryableIpcConnectError,
210
- PersistentIpcClient: FakePersistentIpcClient,
211
- }));
212
- }
213
-
214
- // ---------------------------------------------------------------------------
215
- // Public API for tests
216
- // ---------------------------------------------------------------------------
217
-
218
- /**
219
- * Configure the fake gateway IPC response.
220
- *
221
- * @param flags — feature flag map returned by `get_feature_flags`. Pass
222
- * `null` to skip setting a result (useful when only simulating errors).
223
- * @param opts.error — simulate a socket connection error
224
- * @param opts.code - `IpcConnectError.code` when simulating a connect failure
225
- * @param opts.results — raw method->result map for arbitrary IPC methods
226
- */
227
- export function mockGatewayIpc(
228
- flags?: Record<string, boolean> | null,
229
- opts?: {
230
- error?: boolean;
231
- code?: string;
232
- results?: Record<string, unknown>;
233
- /** Throw a transient (retryable) error for the first N persistent calls. */
234
- failFirstN?: number;
235
- /** Make the simulated persistent-call failure a non-retryable IpcCallError. */
236
- ipcCallError?: boolean;
237
- },
238
- ): void {
239
- if (flags != null) {
240
- ipcResults["get_feature_flags"] = flags;
241
- }
242
- if (opts?.results) {
243
- Object.assign(ipcResults, opts.results);
244
- }
245
- if (opts?.error) {
246
- simulateError = true;
247
- }
248
- if (opts?.code !== undefined) {
249
- simulateErrorCode = opts.code;
250
- }
251
- if (opts?.failFirstN !== undefined) {
252
- failFirstN = opts.failFirstN;
253
- }
254
- if (opts?.ipcCallError) {
255
- failWithIpcCallError = true;
256
- }
257
- }
258
-
259
- /**
260
- * Number of persistent-client `.call(method)` invocations since the last reset.
261
- * Lets retry tests assert the exact attempt count.
262
- */
263
- export function getMockPersistentCallCount(method: string): number {
264
- return persistentCallCounts[method] ?? 0;
265
- }
266
-
267
- /**
268
- * Reset all IPC mock state back to defaults (empty flags, no errors).
269
- */
270
- export function resetMockGatewayIpc(): void {
271
- ipcResults = {};
272
- simulateError = false;
273
- simulateErrorCode = undefined;
274
- failFirstN = 0;
275
- failWithIpcCallError = false;
276
- for (const key of Object.keys(persistentCallCounts)) {
277
- delete persistentCallCounts[key];
278
- }
279
- }