Download src/plugin-sdk/test-helpers/directory-ids.ts from SaylorTwift/openclaw: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/plugin-sdk/test-helpers/directory-ids.ts
- Command line
-
hf download hf://SaylorTwift/openclaw/src/plugin-sdk/test-helpers/directory-ids.ts
-
curl -L -o directory-ids.ts https://huggingface.co/SaylorTwift/openclaw/resolve/main/src/plugin-sdk/test-helpers/directory-ids.ts
1.15 kB
| /** | |
| * Shared assertions for channel directory id contract tests. | |
| */ | |
| import { expect } from "vitest"; | |
| import type { ChannelDirectoryEntry } from "../channel-contract.js"; | |
| import type { OpenClawConfig } from "../config-contracts.js"; | |
| export type DirectoryListFn = (params: { | |
| cfg: OpenClawConfig; | |
| accountId?: string; | |
| query?: string | null; | |
| limit?: number | null; | |
| }) => Promise<ChannelDirectoryEntry[]>; | |
| /** Calls a directory lister and compares returned ids, optionally ignoring order. */ | |
| export async function expectDirectoryIds( | |
| listFn: DirectoryListFn, | |
| cfg: OpenClawConfig, | |
| expected: string[], | |
| options?: { sorted?: boolean }, | |
| ) { | |
| const entries = await listFn({ | |
| cfg, | |
| accountId: "default", | |
| query: null, | |
| limit: null, | |
| }); | |
| const ids = entries.map((entry) => entry.id); | |
| expect(options?.sorted ? sortDirectoryIds(ids) : ids).toEqual( | |
| options?.sorted ? sortDirectoryIds(expected) : expected, | |
| ); | |
| } | |
| function compareDirectoryIds(left: string, right: string) { | |
| return left < right ? -1 : left > right ? 1 : 0; | |
| } | |
| function sortDirectoryIds(values: string[]) { | |
| return values.toSorted(compareDirectoryIds); | |
| } | |