test: avoid extension count filter predicates

This commit is contained in:
Peter Steinberger
2026-05-08 22:11:01 +01:00
parent 27ddb6bea2
commit 2c7f2d3ac2
5 changed files with 39 additions and 9 deletions

View File

@@ -393,9 +393,7 @@ describe("Codex plugin thread config", () => {
});
expect(config.diagnostics).toEqual([]);
expect(request.mock.calls.map(([method]) => method)).toContain("plugin/install");
expect(request.mock.calls.filter(([method]) => method === "app/list").length).toBeGreaterThan(
0,
);
expect(request.mock.calls.some(([method]) => method === "app/list")).toBe(true);
expect(appListParams.map((params) => params.forceRefetch)).toContain(true);
});

View File

@@ -46,6 +46,16 @@ const mockReaddirSync = vi.fn();
const mockSettingsExistsSync = vi.fn();
const mockSettingsReadFileSync = vi.fn();
function countMatching<T>(items: readonly T[], predicate: (item: T) => boolean): number {
let count = 0;
for (const item of items) {
if (predicate(item)) {
count += 1;
}
}
return count;
}
describe("resolveGeminiCliSelectedAuthType", () => {
const ENV_KEYS = ["GOOGLE_GENAI_USE_GCA"] as const;
@@ -843,7 +853,7 @@ describe("loginGeminiCliOAuth", () => {
});
await runProjectDiscoveryExpectingProjectId("env-project");
expect(requests.filter(({ url }) => url.includes("v1internal:loadCodeAssist"))).toHaveLength(3);
expect(countMatching(requests, ({ url }) => url.includes("v1internal:loadCodeAssist"))).toBe(3);
expect(requests.map(({ url }) => url)).not.toEqual(
expect.arrayContaining([expect.stringContaining("v1internal:onboardUser")]),
);

View File

@@ -128,7 +128,9 @@ describe("syncMemoryWikiBridgeSources", () => {
expect(first.pagePaths).toHaveLength(3);
const sourcePages = await fs.readdir(path.join(vaultDir, "sources"));
expect(sourcePages.filter((name) => name.startsWith("bridge-"))).toHaveLength(3);
expect(
sourcePages.reduce((count, name) => count + (name.startsWith("bridge-") ? 1 : 0), 0),
).toBe(3);
const memoryPage = await fs.readFile(path.join(vaultDir, first.pagePaths[0] ?? ""), "utf8");
expect(memoryPage).toContain("sourceType: memory-bridge");

View File

@@ -45,6 +45,16 @@ function createContainerNetworkRunCommand(calls?: string[]) {
};
}
function countMatching<T>(items: readonly T[], predicate: (item: T) => boolean): number {
let count = 0;
for (const item of items) {
if (predicate(item)) {
count += 1;
}
}
return count;
}
describe("matrix harness runtime", () => {
it("writes a pinned Tuwunel compose file and redacted manifest", async () => {
const outputDir = await mkdtemp(path.join(os.tmpdir(), "matrix-qa-harness-"));
@@ -180,7 +190,7 @@ describe("matrix harness runtime", () => {
return {
ok:
input === "http://127.0.0.1:28008/_matrix/client/versions" &&
fetchCalls.filter((url) => url === input).length > 1,
countMatching(fetchCalls, (url) => url === input) > 1,
};
}),
sleepImpl: vi.fn(async () => {}),
@@ -208,7 +218,7 @@ describe("matrix harness runtime", () => {
return {
ok:
input === "http://172.18.0.10:8008/_matrix/client/versions" &&
fetchCalls.filter((url) => url === input).length > 1,
countMatching(fetchCalls, (url) => url === input) > 1,
};
}),
sleepImpl: vi.fn(async () => {}),

View File

@@ -16,6 +16,16 @@ type TestLog = {
error: (...args: unknown[]) => void;
};
function countMatching<T>(items: readonly T[], predicate: (item: T) => boolean): number {
let count = 0;
for (const item of items) {
if (predicate(item)) {
count += 1;
}
}
return count;
}
function makeAccount(
overrides: Partial<ResolvedSynologyChatAccount> = {},
): ResolvedSynologyChatAccount {
@@ -240,8 +250,8 @@ describe("createWebhookHandler", () => {
await new Promise((resolve) => setTimeout(resolve, 0));
// Default maxInFlightPerKey is 8; 12 total requests leaves 4 rejected with 429.
expect(responses.filter((res) => res._status === 0)).toHaveLength(8);
expect(responses.filter((res) => res._status === 429)).toHaveLength(4);
expect(countMatching(responses, (res) => res._status === 0)).toBe(8);
expect(countMatching(responses, (res) => res._status === 429)).toBe(4);
for (const req of requests) {
req.emit("end");