kimi-code / packages /node-sdk /test /config.test.ts
SaylorTwift's picture
SaylorTwift HF Staff
Add files using upload-large-folder tool
4e23b01 verified
Raw History Blame Contribute Delete
1.45 kB
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'],
},
],
},
});
});
});