File size: 1,445 Bytes
4e23b01 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | import { mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { afterEach, describe, expect, it } from 'vitest';
import { createKimiConfigRpc } from '#/index';
const toPosix = (p: string): string => p.replaceAll('\\', '/');
const tempDirs: string[] = [];
afterEach(async () => {
for (const dir of tempDirs.splice(0)) {
await rm(dir, { recursive: true, force: true });
}
});
async function makeTempDir(): Promise<string> {
const dir = await mkdtemp(join(tmpdir(), 'kimi-sdk-config-'));
tempDirs.push(dir);
return dir;
}
describe('SDK config TOML', () => {
it('resolves config paths through the config RPC wrapper', async () => {
const dir = await makeTempDir();
const rpc = createKimiConfigRpc();
await expect(rpc.resolveConfigPath({ homeDir: dir })).resolves.toBe(toPosix(join(dir, 'config.toml')));
});
it('returns structured validation issues through the config RPC wrapper', async () => {
const rpc = createKimiConfigRpc();
await expect(
rpc.validateConfigToml({
text: `
[providers.kimi]
type = "kimi"
[models.kimi]
provider = "kimi"
model = "kimi"
max_context_size = "large"
`,
filePath: 'broken.toml',
}),
).rejects.toMatchObject({
details: {
validationIssues: [
{
path: ['models', 'kimi', 'maxContextSize'],
},
],
},
});
});
});
|