Skip to content

Commit 1e3d3ce

Browse files
committed
fix(release): repair validation backports
1 parent 5789181 commit 1e3d3ce

8 files changed

Lines changed: 107 additions & 203 deletions

File tree

‎extensions/mattermost/src/mattermost/client.retry.test.ts‎

Lines changed: 27 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,12 @@ describe("createMattermostDirectChannelWithRetry", () => {
100100
return run;
101101
}
102102

103+
function jsonResponse(body: unknown, status = 200): Response {
104+
return Response.json(body, { status });
105+
}
106+
103107
it("succeeds on first attempt without retries", async () => {
104-
mockFetch.mockResolvedValueOnce({
105-
ok: true,
106-
status: 201,
107-
headers: new Headers({ "content-type": "application/json" }),
108-
json: async () => ({ id: "dm-channel-123" }),
109-
} as Response);
108+
mockFetch.mockResolvedValueOnce(jsonResponse({ id: "dm-channel-123" }, 201));
110109

111110
const client = createMockClient();
112111
const onRetry = vi.fn();
@@ -124,19 +123,8 @@ describe("createMattermostDirectChannelWithRetry", () => {
124123

125124
it("retries on 429 rate limit error and succeeds", async () => {
126125
mockFetch
127-
.mockResolvedValueOnce({
128-
ok: false,
129-
status: 429,
130-
headers: new Headers({ "content-type": "application/json" }),
131-
json: async () => ({ message: "Too many requests" }),
132-
text: async () => "Too many requests",
133-
} as Response)
134-
.mockResolvedValueOnce({
135-
ok: true,
136-
status: 201,
137-
headers: new Headers({ "content-type": "application/json" }),
138-
json: async () => ({ id: "dm-channel-456" }),
139-
} as Response);
126+
.mockResolvedValueOnce(jsonResponse({ message: "Too many requests" }, 429))
127+
.mockResolvedValueOnce(jsonResponse({ id: "dm-channel-456" }, 201));
140128

141129
const client = createMockClient();
142130
const onRetry = vi.fn();
@@ -157,21 +145,14 @@ describe("createMattermostDirectChannelWithRetry", () => {
157145
expect(retryCall?.[1]).toBeGreaterThanOrEqual(10);
158146
expect(retryCall?.[1]).toBeLessThanOrEqual(20);
159147
expect(retryCall?.[2]).toBeInstanceOf(Error);
160-
expect((retryCall?.[2] as Error | undefined)?.message).toBe(
161-
"Mattermost API 429 undefined: Too many requests",
162-
);
148+
expect((retryCall?.[2] as Error | undefined)?.message).toContain("Too many requests");
163149
});
164150

165151
it("retries on port 443 connection errors (not misclassified as 4xx)", async () => {
166152
// This tests that port numbers like :443 don't trigger false 4xx classification
167153
mockFetch
168154
.mockRejectedValueOnce(new Error("connect ECONNRESET 104.18.32.10:443"))
169-
.mockResolvedValueOnce({
170-
ok: true,
171-
status: 201,
172-
headers: new Headers({ "content-type": "application/json" }),
173-
json: async () => ({ id: "dm-channel-port" }),
174-
} as Response);
155+
.mockResolvedValueOnce(jsonResponse({ id: "dm-channel-port" }, 201));
175156

176157
const client = createMockClient();
177158

@@ -190,13 +171,7 @@ describe("createMattermostDirectChannelWithRetry", () => {
190171
it("does not retry on 400 even if error message contains '429' text", async () => {
191172
// This tests that "429" in error detail doesn't trigger false rate-limit retry
192173
// e.g., "Invalid user ID: 4294967295" should NOT be retried
193-
mockFetch.mockResolvedValueOnce({
194-
ok: false,
195-
status: 400,
196-
headers: new Headers({ "content-type": "application/json" }),
197-
json: async () => ({ message: "Invalid user ID: 4294967295" }),
198-
text: async () => "Invalid user ID: 4294967295",
199-
} as Response);
174+
mockFetch.mockResolvedValueOnce(jsonResponse({ message: "Invalid user ID: 4294967295" }, 400));
200175

201176
const client = createMockClient();
202177

@@ -214,26 +189,9 @@ describe("createMattermostDirectChannelWithRetry", () => {
214189

215190
it("retries on 5xx server errors", async () => {
216191
mockFetch
217-
.mockResolvedValueOnce({
218-
ok: false,
219-
status: 503,
220-
headers: new Headers({ "content-type": "application/json" }),
221-
json: async () => ({ message: "Service unavailable" }),
222-
text: async () => "Service unavailable",
223-
} as Response)
224-
.mockResolvedValueOnce({
225-
ok: false,
226-
status: 502,
227-
headers: new Headers({ "content-type": "application/json" }),
228-
json: async () => ({ message: "Bad gateway" }),
229-
text: async () => "Bad gateway",
230-
} as Response)
231-
.mockResolvedValueOnce({
232-
ok: true,
233-
status: 201,
234-
headers: new Headers({ "content-type": "application/json" }),
235-
json: async () => ({ id: "dm-channel-789" }),
236-
} as Response);
192+
.mockResolvedValueOnce(jsonResponse({ message: "Service unavailable" }, 503))
193+
.mockResolvedValueOnce(jsonResponse({ message: "Bad gateway" }, 502))
194+
.mockResolvedValueOnce(jsonResponse({ id: "dm-channel-789" }, 201));
237195

238196
const client = createMockClient();
239197

@@ -252,12 +210,7 @@ describe("createMattermostDirectChannelWithRetry", () => {
252210
mockFetch
253211
.mockRejectedValueOnce(new Error("Network error: connection refused"))
254212
.mockRejectedValueOnce(new Error("ECONNRESET"))
255-
.mockResolvedValueOnce({
256-
ok: true,
257-
status: 201,
258-
headers: new Headers({ "content-type": "application/json" }),
259-
json: async () => ({ id: "dm-channel-abc" }),
260-
} as Response);
213+
.mockResolvedValueOnce(jsonResponse({ id: "dm-channel-abc" }, 201));
261214

262215
const client = createMockClient();
263216

@@ -280,12 +233,7 @@ describe("createMattermostDirectChannelWithRetry", () => {
280233
code: "ECONNREFUSED",
281234
}),
282235
)
283-
.mockResolvedValueOnce({
284-
ok: true,
285-
status: 201,
286-
headers: new Headers({ "content-type": "application/json" }),
287-
json: async () => ({ id: "dm-channel-fetch-failed" }),
288-
} as Response);
236+
.mockResolvedValueOnce(jsonResponse({ id: "dm-channel-fetch-failed" }, 201));
289237

290238
const client = createMockClient();
291239

@@ -301,13 +249,7 @@ describe("createMattermostDirectChannelWithRetry", () => {
301249
});
302250

303251
it("does not retry on 4xx client errors (except 429)", async () => {
304-
mockFetch.mockResolvedValueOnce({
305-
ok: false,
306-
status: 400,
307-
headers: new Headers({ "content-type": "application/json" }),
308-
json: async () => ({ message: "Bad request" }),
309-
text: async () => "Bad request",
310-
} as Response);
252+
mockFetch.mockResolvedValueOnce(jsonResponse({ message: "Bad request" }, 400));
311253

312254
const client = createMockClient();
313255

@@ -323,13 +265,7 @@ describe("createMattermostDirectChannelWithRetry", () => {
323265
});
324266

325267
it("does not retry on 404 not found", async () => {
326-
mockFetch.mockResolvedValueOnce({
327-
ok: false,
328-
status: 404,
329-
headers: new Headers({ "content-type": "application/json" }),
330-
json: async () => ({ message: "User not found" }),
331-
text: async () => "User not found",
332-
} as Response);
268+
mockFetch.mockResolvedValueOnce(jsonResponse({ message: "User not found" }, 404));
333269

334270
const client = createMockClient();
335271

@@ -345,13 +281,7 @@ describe("createMattermostDirectChannelWithRetry", () => {
345281
});
346282

347283
it("throws after exhausting all retries", async () => {
348-
mockFetch.mockResolvedValue({
349-
ok: false,
350-
status: 503,
351-
headers: new Headers({ "content-type": "application/json" }),
352-
json: async () => ({ message: "Service unavailable" }),
353-
text: async () => "Service unavailable",
354-
} as Response);
284+
mockFetch.mockImplementation(async () => jsonResponse({ message: "Service unavailable" }, 503));
355285

356286
const client = createMockClient();
357287

@@ -414,12 +344,7 @@ describe("createMattermostDirectChannelWithRetry", () => {
414344
.spyOn(globalThis, "setTimeout")
415345
.mockReturnValue(1 as unknown as ReturnType<typeof setTimeout>);
416346
vi.spyOn(globalThis, "clearTimeout").mockImplementation(() => undefined);
417-
mockFetch.mockResolvedValueOnce({
418-
ok: true,
419-
status: 201,
420-
headers: new Headers({ "content-type": "application/json" }),
421-
json: async () => ({ id: "dm-channel-capped" }),
422-
} as Response);
347+
mockFetch.mockResolvedValueOnce(jsonResponse({ id: "dm-channel-capped" }, 201));
423348

424349
const client = createMockClient();
425350

@@ -436,12 +361,7 @@ describe("createMattermostDirectChannelWithRetry", () => {
436361
mockFetch
437362
.mockRejectedValueOnce(new Error("Mattermost API 503 Service Unavailable"))
438363
.mockRejectedValueOnce(new Error("Mattermost API 503 Service Unavailable"))
439-
.mockResolvedValueOnce({
440-
ok: true,
441-
status: 201,
442-
headers: new Headers({ "content-type": "application/json" }),
443-
json: async () => ({ id: "dm-channel-delay" }),
444-
} as Response);
364+
.mockResolvedValueOnce(jsonResponse({ id: "dm-channel-delay" }, 201));
445365

446366
const client = createMockClient();
447367

@@ -472,12 +392,7 @@ describe("createMattermostDirectChannelWithRetry", () => {
472392
.mockRejectedValueOnce(new Error("Mattermost API 503"))
473393
.mockRejectedValueOnce(new Error("Mattermost API 503"))
474394
.mockRejectedValueOnce(new Error("Mattermost API 503"))
475-
.mockResolvedValueOnce({
476-
ok: true,
477-
status: 201,
478-
headers: new Headers({ "content-type": "application/json" }),
479-
json: async () => ({ id: "dm-channel-max" }),
480-
} as Response);
395+
.mockResolvedValueOnce(jsonResponse({ id: "dm-channel-max" }, 201));
481396

482397
const client = createMockClient();
483398

@@ -502,13 +417,9 @@ describe("createMattermostDirectChannelWithRetry", () => {
502417
it("does not retry on 4xx errors even if message contains retryable keywords", async () => {
503418
// This tests the fix for false positives where a 400 error with "timeout" in the message
504419
// would incorrectly be retried
505-
mockFetch.mockResolvedValueOnce({
506-
ok: false,
507-
status: 400,
508-
headers: new Headers({ "content-type": "application/json" }),
509-
json: async () => ({ message: "Request timeout: connection timed out" }),
510-
text: async () => "Request timeout: connection timed out",
511-
} as Response);
420+
mockFetch.mockResolvedValueOnce(
421+
jsonResponse({ message: "Request timeout: connection timed out" }, 400),
422+
);
512423

513424
const client = createMockClient();
514425

@@ -525,13 +436,7 @@ describe("createMattermostDirectChannelWithRetry", () => {
525436
});
526437

527438
it("does not retry on 403 Forbidden even with 'abort' in message", async () => {
528-
mockFetch.mockResolvedValueOnce({
529-
ok: false,
530-
status: 403,
531-
headers: new Headers({ "content-type": "application/json" }),
532-
json: async () => ({ message: "Request aborted: forbidden" }),
533-
text: async () => "Request aborted: forbidden",
534-
} as Response);
439+
mockFetch.mockResolvedValueOnce(jsonResponse({ message: "Request aborted: forbidden" }, 403));
535440

536441
const client = createMockClient();
537442

@@ -550,12 +455,7 @@ describe("createMattermostDirectChannelWithRetry", () => {
550455
let capturedSignal: AbortSignal | undefined;
551456
mockFetch.mockImplementationOnce((url, init) => {
552457
capturedSignal = init?.signal ?? undefined;
553-
return Promise.resolve({
554-
ok: true,
555-
status: 201,
556-
headers: new Headers({ "content-type": "application/json" }),
557-
json: async () => ({ id: "dm-channel-signal" }),
558-
} as Response);
458+
return Promise.resolve(jsonResponse({ id: "dm-channel-signal" }, 201));
559459
});
560460

561461
const client = createMockClient();
@@ -573,12 +473,7 @@ describe("createMattermostDirectChannelWithRetry", () => {
573473
// This tests the fix for the ordering bug: 503 with "upstream 404" should be retried
574474
mockFetch
575475
.mockRejectedValueOnce(new Error("Mattermost API 503: upstream returned 404 Not Found"))
576-
.mockResolvedValueOnce({
577-
ok: true,
578-
status: 201,
579-
headers: new Headers({ "content-type": "application/json" }),
580-
json: async () => ({ id: "dm-channel-5xx-with-404" }),
581-
} as Response);
476+
.mockResolvedValueOnce(jsonResponse({ id: "dm-channel-5xx-with-404" }, 201));
582477

583478
const client = createMockClient();
584479

‎extensions/memory-core/src/memory/qmd-manager.test.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,18 @@ type EmbedLockCall = [
5454
() => Promise<unknown>,
5555
];
5656

57+
type MockStream = EventEmitter & { setEncoding: ReturnType<typeof vi.fn> };
58+
5759
interface MockChild extends EventEmitter {
58-
stdout: EventEmitter;
59-
stderr: EventEmitter;
60+
stdout: MockStream;
61+
stderr: MockStream;
6062
kill: (signal?: NodeJS.Signals) => void;
6163
closeWith: (code?: number | null) => void;
6264
}
6365

6466
function createMockChild(params?: { autoClose?: boolean; closeDelayMs?: number }): MockChild {
65-
const stdout = new EventEmitter();
66-
const stderr = new EventEmitter();
67+
const stdout = Object.assign(new EventEmitter(), { setEncoding: vi.fn() });
68+
const stderr = Object.assign(new EventEmitter(), { setEncoding: vi.fn() });
6769
const child: MockChild = Object.assign(new EventEmitter(), {
6870
stdout,
6971
stderr,

‎extensions/ollama/provider-discovery.test.ts‎

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,16 @@ describe("Ollama provider", () => {
103103

104104
const createTagModel = (name: string) => ({ name, modified_at: "", size: 1, digest: "" });
105105

106-
const tagsResponse = (names: string[]) => ({
107-
ok: true,
108-
json: async () => ({ models: names.map((name) => createTagModel(name)) }),
109-
});
106+
const jsonResponse = (body: unknown, status = 200) =>
107+
new Response(JSON.stringify(body), {
108+
status,
109+
headers: { "content-type": "application/json" },
110+
});
110111

111-
const notFoundJsonResponse = () => ({
112-
ok: false,
113-
status: 404,
114-
json: async () => ({}),
115-
});
112+
const tagsResponse = (names: string[]) =>
113+
jsonResponse({ models: names.map((name) => createTagModel(name)) });
114+
115+
const notFoundJsonResponse = () => jsonResponse({}, 404);
116116

117117
const stubTagsFetch = (names: string[] = []) => {
118118
const fetchMock = vi.fn(async (input: unknown) => {
@@ -213,16 +213,10 @@ describe("Ollama provider", () => {
213213
const bodyText = typeof rawBody === "string" ? rawBody : "{}";
214214
const parsed = JSON.parse(bodyText) as { name?: string };
215215
if (parsed.name === "qwen3:32b") {
216-
return {
217-
ok: true,
218-
json: async () => ({ model_info: { "qwen3.context_length": 131072 } }),
219-
};
216+
return jsonResponse({ model_info: { "qwen3.context_length": 131072 } });
220217
}
221218
if (parsed.name === "llama3.3:70b") {
222-
return {
223-
ok: true,
224-
json: async () => ({ model_info: { "llama.context_length": 65536 } }),
225-
};
219+
return jsonResponse({ model_info: { "llama.context_length": 65536 } });
226220
}
227221
}
228222
return notFoundJsonResponse();
@@ -249,10 +243,7 @@ describe("Ollama provider", () => {
249243
return tagsResponse(["deepseek-r1:latest", "llama3.3:latest"]);
250244
}
251245
if (url.endsWith("/api/show")) {
252-
return {
253-
ok: true,
254-
json: async () => ({ model_info: {} }),
255-
};
246+
return jsonResponse({ model_info: {} });
256247
}
257248
return notFoundJsonResponse();
258249
});
@@ -331,10 +322,7 @@ describe("Ollama provider", () => {
331322
return tagsResponse(["qwen3:32b"]);
332323
}
333324
if (url.endsWith("/api/show")) {
334-
return {
335-
ok: false,
336-
status: 500,
337-
};
325+
return jsonResponse({}, 500);
338326
}
339327
return notFoundJsonResponse();
340328
});
@@ -359,15 +347,9 @@ describe("Ollama provider", () => {
359347
const fetchMock = vi.fn(async (input: unknown) => {
360348
const url = String(input);
361349
if (url.endsWith("/api/tags")) {
362-
return {
363-
ok: true,
364-
json: async () => ({ models: manyModels }),
365-
};
350+
return jsonResponse({ models: manyModels });
366351
}
367-
return {
368-
ok: true,
369-
json: async () => ({ model_info: { "llama.context_length": 65536 } }),
370-
};
352+
return jsonResponse({ model_info: { "llama.context_length": 65536 } });
371353
});
372354
vi.stubGlobal("fetch", withFetchPreconnect(fetchMock));
373355

0 commit comments

Comments
 (0)